Update getters for Chrome and VLC media player software
This commit is contained in:
87
desktop_env/evaluators/metrics/vlc.py
Normal file
87
desktop_env/evaluators/metrics/vlc.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import os
|
||||
import platform
|
||||
import requests
|
||||
from xml.etree import ElementTree
|
||||
import pygetwindow as gw
|
||||
import pyautogui
|
||||
|
||||
def read_vlc_config(setting_name):
|
||||
"""
|
||||
Reads the VLC configuration file to check for a specific setting.
|
||||
|
||||
# Example usage
|
||||
setting_name = 'recordings_folder='
|
||||
setting = read_vlc_config(setting_name)
|
||||
"""
|
||||
# Common paths for VLC config file on different operating systems
|
||||
paths = {
|
||||
'Windows': os.path.expanduser('~\\AppData\\Roaming\\vlc\\vlcrc'),
|
||||
'Darwin': os.path.expanduser('~/Library/Preferences/org.videolan.vlc/vlcrc'),
|
||||
'Linux': os.path.expanduser('~/.config/vlc/vlcrc')
|
||||
}
|
||||
|
||||
os_type = platform.system()
|
||||
config_path = paths.get(os_type)
|
||||
|
||||
if not config_path or not os.path.exists(config_path):
|
||||
print("VLC config file not found for this operating system.")
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(config_path, 'r', encoding="utf-8") as file:
|
||||
for line in file:
|
||||
if line.startswith(setting_name):
|
||||
return line.strip()
|
||||
except IOError as e:
|
||||
print(f"Error reading config file: {e}")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_vlc_playing_info(host='localhost', port=8080, password='password'):
|
||||
"""
|
||||
Gets the current playing information from VLC's HTTP interface.
|
||||
"""
|
||||
url = f'http://{host}:{port}/requests/status.xml'
|
||||
try:
|
||||
response = requests.get(url, auth=('', password))
|
||||
if response.status_code == 200:
|
||||
tree = ElementTree.fromstring(response.content)
|
||||
status = tree.find('state').text
|
||||
if status == 'playing':
|
||||
file_info = tree.find('information/category[@name="meta"]/info[@name="filename"]').text
|
||||
return status, file_info
|
||||
return status, None
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
def is_vlc_fullscreen():
|
||||
"""
|
||||
Checks if the VLC window is in full-screen mode.
|
||||
|
||||
When VLC is in full-screen mode, its window size matches the screen size with no borders.
|
||||
"""
|
||||
try:
|
||||
# Get the VLC window; adjust the title as per your VLC window's title
|
||||
vlc_window = gw.getWindowsWithTitle('VLC media player')[0] # Adjust title if needed
|
||||
if not vlc_window:
|
||||
return False
|
||||
|
||||
# Get screen size
|
||||
screen_width, screen_height = pyautogui.size()
|
||||
|
||||
# Check if VLC window size matches the screen size
|
||||
return (vlc_window.width == screen_width and vlc_window.height == screen_height)
|
||||
|
||||
except IndexError:
|
||||
# VLC window not found
|
||||
print("VLC window not found.")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user