From 2401513c1961ec7c976c3eae28347081d028012c Mon Sep 17 00:00:00 2001 From: Timothyxxx <384084775@qq.com> Date: Thu, 4 Jan 2024 17:55:07 +0800 Subject: [PATCH] Initialize VLC getters and metrics, fix some bugs in infra logic, needs to be refactored later on --- desktop_env/evaluators/getters/vlc.py | 20 +++++++++++++++ desktop_env/evaluators/metrics/gimp.py | 22 ++++++++++++++++ desktop_env/evaluators/metrics/vlc.py | 35 ++++++++++++-------------- 3 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 desktop_env/evaluators/getters/vlc.py create mode 100644 desktop_env/evaluators/metrics/gimp.py diff --git a/desktop_env/evaluators/getters/vlc.py b/desktop_env/evaluators/getters/vlc.py new file mode 100644 index 0000000..e00ce61 --- /dev/null +++ b/desktop_env/evaluators/getters/vlc.py @@ -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 diff --git a/desktop_env/evaluators/metrics/gimp.py b/desktop_env/evaluators/metrics/gimp.py new file mode 100644 index 0000000..fbc328c --- /dev/null +++ b/desktop_env/evaluators/metrics/gimp.py @@ -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 diff --git a/desktop_env/evaluators/metrics/vlc.py b/desktop_env/evaluators/metrics/vlc.py index d3083c2..b5272eb 100644 --- a/desktop_env/evaluators/metrics/vlc.py +++ b/desktop_env/evaluators/metrics/vlc.py @@ -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 - -