Initialize VLC getters and metrics, fix some bugs in infra logic, needs to be refactored later on
This commit is contained in:
20
desktop_env/evaluators/getters/vlc.py
Normal file
20
desktop_env/evaluators/getters/vlc.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def get_vlc_playing_info(env, config: Dict[str, str]):
|
||||
"""
|
||||
Gets the current playing information from VLC's HTTP interface.
|
||||
"""
|
||||
_path = os.path.join(env.cache_dir, config["dest"])
|
||||
|
||||
host = env.vm_ip
|
||||
port = 8080
|
||||
password = 'password'
|
||||
|
||||
content = env.controller.get_vlc_status(host, port, password)
|
||||
print("content: ", content)
|
||||
with open(_path, "wb") as f:
|
||||
f.write(content)
|
||||
|
||||
return _path
|
||||
22
desktop_env/evaluators/metrics/gimp.py
Normal file
22
desktop_env/evaluators/metrics/gimp.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
|
||||
|
||||
def get_gimp_export_path():
|
||||
# Path to GIMP's configuration file. This example assumes GIMP version 2.10.
|
||||
# You need to adjust the path according to the GIMP version and user's file system.
|
||||
gimp_config_file = os.path.expanduser("~/.config/GIMP/2.10/gimprc")
|
||||
|
||||
try:
|
||||
# Open and read the configuration file
|
||||
with open(gimp_config_file, 'r') as file:
|
||||
for line in file:
|
||||
# Search for the default export path setting
|
||||
if "default-export-path" in line:
|
||||
# Extract the current path from the line (assuming it's enclosed in quotes)
|
||||
current_path = line.split('"')[1]
|
||||
# Compare the current path with the expected path
|
||||
return current_path
|
||||
except FileNotFoundError:
|
||||
# Handle the case where the configuration file is not found
|
||||
print("GIMP configuration file not found")
|
||||
return False
|
||||
@@ -1,11 +1,12 @@
|
||||
import os
|
||||
import platform
|
||||
import requests
|
||||
from xml.etree import ElementTree
|
||||
import pygetwindow as gw
|
||||
import pyautogui
|
||||
from typing import Dict
|
||||
|
||||
def read_vlc_config(setting_name):
|
||||
|
||||
def get_vlc_config(setting_name):
|
||||
"""
|
||||
Reads the VLC configuration file to check for a specific setting.
|
||||
|
||||
@@ -38,24 +39,22 @@ def read_vlc_config(setting_name):
|
||||
return None
|
||||
|
||||
|
||||
def get_vlc_playing_info(host='localhost', port=8080, password='password'):
|
||||
def is_vlc_playing(actual: str, rule: Dict[str, str]) -> float:
|
||||
"""
|
||||
Gets the current playing information from VLC's HTTP interface.
|
||||
Checks if VLC is currently playing a file.
|
||||
"""
|
||||
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}")
|
||||
with open(actual, 'rb') as file:
|
||||
actual_status = file.read().decode('utf-8')
|
||||
|
||||
return None, None
|
||||
tree = ElementTree.fromstring(actual_status)
|
||||
status = tree.find('state').text
|
||||
if status == 'playing':
|
||||
file_info = tree.find('information/category[@name="meta"]/info[@name="filename"]').text
|
||||
print("file_info: ", file_info)
|
||||
if file_info:
|
||||
return 1 if file_info.endswith(rule['expected']) else 0
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def is_vlc_fullscreen():
|
||||
@@ -83,5 +82,3 @@ def is_vlc_fullscreen():
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user