From 37ec196b189edda47332f8431d4f56b40f2ae52f Mon Sep 17 00:00:00 2001 From: Timothyxxx <384084775@qq.com> Date: Thu, 25 Jan 2024 12:40:00 +0800 Subject: [PATCH] Finish VLC v2 loading --- desktop_env/evaluators/metrics/__init__.py | 7 +- desktop_env/evaluators/metrics/vlc.py | 194 +++++++++++++++++- .../0d95d28a-9587-433b-a805-1fbe5467d598.json | 2 +- .../215dfd39-f493-4bc3-a027-8a97d72c61bf.json | 40 +++- .../386dbd0e-0241-4a0a-b6a2-6704fba26b1c.json | 95 ++++++++- .../9195653c-f4aa-453d-aa95-787f6ccfaae9.json | 40 +++- .../a5bbbcd5-b398-4c91-83d4-55e1e31bbb81.json | 40 +++- .../d06f0d4d-2cd5-4ede-8de9-598629438c6e.json | 40 +++- .../d1ba14d0-fef8-4026-8418-5b581dc68ca0.json | 2 +- .../f3977615-2b45-4ac5-8bba-80c17dbe2a37.json | 40 +++- 10 files changed, 464 insertions(+), 36 deletions(-) diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index 3ab04c2..aea27d1 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -1,4 +1,5 @@ -from .chrome import is_expected_tabs, is_expected_bookmarks, compare_pdfs, is_cookie_deleted, is_shortcut_on_desktop +from .chrome import is_expected_tabs, is_expected_bookmarks, compare_pdfs, is_cookie_deleted, is_shortcut_on_desktop, check_font_size, \ + check_enabled_experiments, check_history_deleted from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers, compare_docx_lines from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, \ compare_insert_equation, compare_highlighted_text @@ -17,6 +18,6 @@ from .pdf import check_pdf_pages from .table import compare_table from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, compare_images, compare_audios, \ - compare_videos -from .thunderbird import check_thunderbird_prefs, check_thunderbird_filter + compare_videos, check_qt_bgcone, check_one_instance_when_started_from_file,check_qt_minimal_view, check_qt_max_volume, \ + check_qt_slider_colours, check_global_key_play_pause from .vscode import compare_text_file, compare_config, compare_answer, is_extension_installed, check_json_settings, check_json_keybindings diff --git a/desktop_env/evaluators/metrics/vlc.py b/desktop_env/evaluators/metrics/vlc.py index 17c9b40..48c064e 100644 --- a/desktop_env/evaluators/metrics/vlc.py +++ b/desktop_env/evaluators/metrics/vlc.py @@ -53,7 +53,7 @@ def is_vlc_recordings_folder(actual_config_path: str, rule: Dict[str, str]) -> f expected_recording_file_path = rule['recording_file_path'] try: - for line in config_file: + for line in config_file.split("\n"): # Skip comments and empty lines if line.startswith('#') or not line.strip(): continue @@ -216,3 +216,195 @@ def are_audio_files_similar(mp3_file_path, mp4_file_path): return True return False + + +def check_qt_bgcone(actual_config_path, rule): + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + expected_qt_bgcone = rule['expected_qt_bgcone'] + if isinstance(expected_qt_bgcone, int): + expected_qt_bgcone = str(expected_qt_bgcone) + + try: + # The default value of qt_bgcone is 1, which means it is enabled + qt_bgcone = "1" + for line in config_file.split("\n"): + # Check if the line contains the recording path setting + if 'qt-bgcone=' in line: + # Extract the value of the recording path and remove surrounding whitespace + qt_bgcone = line.split('=')[-1].strip() + # The configuration key was not found in the file + + if qt_bgcone == expected_qt_bgcone: + return 1 + else: + return 0 + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 + + +def check_qt_max_volume(actual_config_path, rule): + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + expected_qt_max_volume = rule['expected_qt_max_volume'] + if isinstance(expected_qt_max_volume, int): + expected_qt_max_volume = str(expected_qt_max_volume) + + try: + qt_max_volume = "125" + for line in config_file.split("\n"): + if 'qt-max-volume=' in line: + qt_max_volume = line.split('=')[-1].strip() + # The configuration key was not found in the file + + if qt_max_volume == expected_qt_max_volume: + return 1 + else: + return 0 + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 + + +def check_qt_minimal_view(actual_config_path, rule): + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + expected_qt_minimal_view = rule['expected_qt_minimal_view'] + if isinstance(expected_qt_minimal_view, int): + expected_qt_minimal_view = str(expected_qt_minimal_view) + + try: + qt_minimal_view = "0" + for line in config_file.split("\n"): + if 'qt-minimal-view=' in line: + qt_minimal_view = line.split('=')[-1].strip() + + if qt_minimal_view == expected_qt_minimal_view: + return 1 + else: + return 0 + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 + + +def check_qt_slider_colours(actual_config_path, rule): + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + try: + qt_slider_colours = "153;210;153;20;210;20;255;199;15;245;39;29" + for line in config_file.split("\n"): + if 'qt-slider-colours' in line: + qt_slider_colours = line.split('=')[-1].strip() + # The configuration key was not found in the file + + if rule['type'] == 'match': + expected_qt_slider_colours = rule['expected_qt_slider_colours'] + if qt_slider_colours == expected_qt_slider_colours: + return 1 + else: + return 0 + elif rule['type'] == 'blackish': + def is_color_blackish(rgb_values, threshold=100): + # decide if the color is blackish + return all(value < threshold for value in rgb_values) + + def parse_qt_slider_colours(colours_string): + # parse the string of colours into a list of RGB tuples + values = [int(x) for x in colours_string.split(';')] + colors = list(zip(values[0::3], values[1::3], values[2::3])) + return colors + + colors = parse_qt_slider_colours(qt_slider_colours) + + # check if all colors are blackish + for color in colors: + if is_color_blackish(color): + pass + else: + return 0 + return 1 + + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 + + +def check_global_key_play_pause(actual_config_path, rule): + """ + # Play/Pause (str) + #global-key-play-pause= + + # Play/Pause (str) + #key-play-pause=Space + """ + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + expected_global_key_play_pause = rule['expected_global_key_play_pause'] + + if isinstance(expected_global_key_play_pause, int): + expected_global_key_play_pause = str(expected_global_key_play_pause) + + try: + global_key_play_pause = "0" + for line in config_file.split("\n"): + # Check if the line contains the recording path setting + if 'global-key-play-pause=' in line: + global_key_play_pause = "0" if line.split('=')[-1].strip() == "" else "1" + + if global_key_play_pause == expected_global_key_play_pause: + return 1 + else: + return 0 + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 + + +def check_one_instance_when_started_from_file(actual_config_path, rule): + with open(actual_config_path, 'rb') as file: + config_file = file.read().decode('utf-8') + + expected_one_instance_when_started_from_file = rule['expected_one_instance_when_started_from_file'] + + if isinstance(expected_one_instance_when_started_from_file, int): + expected_one_instance_when_started_from_file = str(expected_one_instance_when_started_from_file) + + try: + one_instance_when_started_from_file = "1" + for line in config_file.split("\n"): + # Check if the line contains the recording path setting + if 'one-instance-when-started-from-file=' in line: + one_instance_when_started_from_file = line.split('=')[-1].strip() + + if one_instance_when_started_from_file == expected_one_instance_when_started_from_file: + return 1 + else: + return 0 + except FileNotFoundError: + logger.error("VLC configuration file not found.") + return 0 + except Exception as e: + logger.error(f"An error occurred: {e}") + return 0 diff --git a/evaluation_examples/examples/vlc/0d95d28a-9587-433b-a805-1fbe5467d598.json b/evaluation_examples/examples/vlc/0d95d28a-9587-433b-a805-1fbe5467d598.json index 9d64cf8..0e52b79 100644 --- a/evaluation_examples/examples/vlc/0d95d28a-9587-433b-a805-1fbe5467d598.json +++ b/evaluation_examples/examples/vlc/0d95d28a-9587-433b-a805-1fbe5467d598.json @@ -6,7 +6,7 @@ "config": [], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { "func": "", diff --git a/evaluation_examples/examples/vlc/215dfd39-f493-4bc3-a027-8a97d72c61bf.json b/evaluation_examples/examples/vlc/215dfd39-f493-4bc3-a027-8a97d72c61bf.json index 83b1bd1..21f4222 100644 --- a/evaluation_examples/examples/vlc/215dfd39-f493-4bc3-a027-8a97d72c61bf.json +++ b/evaluation_examples/examples/vlc/215dfd39-f493-4bc3-a027-8a97d72c61bf.json @@ -3,16 +3,46 @@ "snapshot": "chrome", "instruction": "Can you disable the cone icon in the splash screen? I am tired of its skeuomorphic design.", "source": "https://superuser.com/questions/1224784/how-to-change-vlcs-splash-screen", - "config": [], + "config": [ + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_qt_bgcone", "expected": { + "type": "rule", + "rules": { + "expected_qt_bgcone": 0 + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } } diff --git a/evaluation_examples/examples/vlc/386dbd0e-0241-4a0a-b6a2-6704fba26b1c.json b/evaluation_examples/examples/vlc/386dbd0e-0241-4a0a-b6a2-6704fba26b1c.json index 0a00751..75dff19 100644 --- a/evaluation_examples/examples/vlc/386dbd0e-0241-4a0a-b6a2-6704fba26b1c.json +++ b/evaluation_examples/examples/vlc/386dbd0e-0241-4a0a-b6a2-6704fba26b1c.json @@ -3,16 +3,101 @@ "snapshot": "chrome", "instruction": "I am reading lecture note in PDF while a music video is running in VLC media player. But I find I need to switch to the player every time I need to pause/start.Could you help me change the setting to allow pausing the video using keyboard shortcut without minimizing the PDF reader? I want to focus on the lecture note and don't be disturbed by the app switching.", "source": "https://superuser.com/questions/1708415/pause-and-play-vlc-in-background?rq=1", - "config": [], + "config": [ + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.usercontent.google.com/download?id=1JqKzFk-4ru1BQdaInui37ORPC1btl7PK&export=download&authuser=0&confirm=t&uuid=449004d6-6f52-4ae3-9008-c2a0a6e0d17f&at=APZUnTXYRTL_FkB5l1TgseCgdSPK:1706155700724", + "path": "Desktop/lecture.pdf" + } + ] + } + }, + { + "type": "download", + "parameters": { + "files": [ + { + "url": "https://drive.usercontent.google.com/download?id=1jS74kYGOcEMOWyHZxlqmQVPmIC6A-UBm&export=download&authuser=0&confirm=t&uuid=0521f46a-9aa5-4dfc-9761-ae6256a31488&at=APZUnTWwRv10ztlVQq2oVsiMX2_r:1706155684550", + "path": "Desktop/Colorful-Flowers.mp3" + } + ] + } + }, + { + "type": "launch", + "parameters": { + "command": [ + "vlc", + "--start-time=10", + "Desktop/Colorful-Flowers.mp3" + ] + } + }, + { + "type": "open", + "parameters": { + "path": "Desktop/lecture.pdf" + } + }, + { + "type": "activate_window", + "parameters": { + "window_name": "lecture.pdf — 6.006 Introduction to Algorithms, Lecture 2: Data Structures", + "strict": true + } + }, + { + "type": "sleep", + "parameters": { + "seconds": 0.5 + } + }, + { + "type": "execute", + "parameters": { + "command": [ + "python", + "-c", + "import pyautogui; pyautogui.press('f11');" + ] + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_global_key_play_pause", "expected": { + "type": "rule", + "rules": { + "expected_global_key_play_pause": 1 + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } } diff --git a/evaluation_examples/examples/vlc/9195653c-f4aa-453d-aa95-787f6ccfaae9.json b/evaluation_examples/examples/vlc/9195653c-f4aa-453d-aa95-787f6ccfaae9.json index f6bb5b7..73d0fd2 100644 --- a/evaluation_examples/examples/vlc/9195653c-f4aa-453d-aa95-787f6ccfaae9.json +++ b/evaluation_examples/examples/vlc/9195653c-f4aa-453d-aa95-787f6ccfaae9.json @@ -3,16 +3,46 @@ "snapshot": "chrome", "instruction": "I like watching movies (using VLC) on my laptop and sometimes the volume is too low for my taste even when the volume in VLC is set to the maximum of 125% on the volume control. Can you increase the max volume of the video to the 200% of the original volume?", "source": "https://superuser.com/questions/1513285/how-can-i-increase-the-maximum-volume-output-by-vlc?rq=1", - "config": [], + "config": [ + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_qt_max_volume", "expected": { + "type": "rule", + "rules": { + "expected_qt_max_volume": 200 + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } } diff --git a/evaluation_examples/examples/vlc/a5bbbcd5-b398-4c91-83d4-55e1e31bbb81.json b/evaluation_examples/examples/vlc/a5bbbcd5-b398-4c91-83d4-55e1e31bbb81.json index 0ffd95f..ff39f72 100644 --- a/evaluation_examples/examples/vlc/a5bbbcd5-b398-4c91-83d4-55e1e31bbb81.json +++ b/evaluation_examples/examples/vlc/a5bbbcd5-b398-4c91-83d4-55e1e31bbb81.json @@ -3,16 +3,46 @@ "snapshot": "chrome", "instruction": "Could you help me hide the bottom toolbar in VLC Media Player when watching in window mode? I often multitask on my computer, and the persistent toolbar in VLC is very distracting. ", "source": "https://superuser.com/questions/776056/how-to-hide-bottom-toolbar-in-vlc", - "config": [], + "config": [ + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_qt_minimal_view", "expected": { + "type": "rule", + "rules": { + "expected_qt_minimal_view": 1 + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } } diff --git a/evaluation_examples/examples/vlc/d06f0d4d-2cd5-4ede-8de9-598629438c6e.json b/evaluation_examples/examples/vlc/d06f0d4d-2cd5-4ede-8de9-598629438c6e.json index bb4668d..c29a8bc 100644 --- a/evaluation_examples/examples/vlc/d06f0d4d-2cd5-4ede-8de9-598629438c6e.json +++ b/evaluation_examples/examples/vlc/d06f0d4d-2cd5-4ede-8de9-598629438c6e.json @@ -3,16 +3,46 @@ "snapshot": "chrome", "instruction": "Can you change the color of the volume slider to black-ish color? I often use the player in a low-light environment, and a darker color scheme would be less straining on my eyes, especially during nighttime usage.", "source": "https://superuser.com/questions/1039392/changing-colour-of-vlc-volume-slider", - "config": [], + "config": [ + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_qt_slider_colours", "expected": { + "type": "rule", + "rules": { + "type": "blackish" + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } } diff --git a/evaluation_examples/examples/vlc/d1ba14d0-fef8-4026-8418-5b581dc68ca0.json b/evaluation_examples/examples/vlc/d1ba14d0-fef8-4026-8418-5b581dc68ca0.json index 0ba512e..a85b069 100644 --- a/evaluation_examples/examples/vlc/d1ba14d0-fef8-4026-8418-5b581dc68ca0.json +++ b/evaluation_examples/examples/vlc/d1ba14d0-fef8-4026-8418-5b581dc68ca0.json @@ -6,7 +6,7 @@ "config": [], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { "func": "", diff --git a/evaluation_examples/examples/vlc/f3977615-2b45-4ac5-8bba-80c17dbe2a37.json b/evaluation_examples/examples/vlc/f3977615-2b45-4ac5-8bba-80c17dbe2a37.json index 410aaf7..e1ee77e 100644 --- a/evaluation_examples/examples/vlc/f3977615-2b45-4ac5-8bba-80c17dbe2a37.json +++ b/evaluation_examples/examples/vlc/f3977615-2b45-4ac5-8bba-80c17dbe2a37.json @@ -3,16 +3,46 @@ "snapshot": "chrome", "instruction": "I want to watch two or more videos in same time on VLC. I tried to run multiple instances of VLC. It worked but can't play videos on those new instances. When I play video it plays on first instance instead of new instance.\nIs there any way to solve this problem? Take the three videos on my desktop for example, do that for me.", "source": "https://www.reddit.com/r/Fedora/comments/rhljzd/how_to_run_multiple_instances_of_vlc_media_player/", - "config": [], + "config": [ + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], "trajectory": "trajectories/", "related_apps": [ - "chrome" + "vlc" ], "evaluator": { - "func": "", - "result": { - }, + "postconfig": [ + { + "type": "launch", + "parameters": { + "command": [ + "pkill", + "vlc" + ] + } + }, + { + "type": "launch", + "parameters": { + "command": "vlc" + } + } + ], + "func": "check_one_instance_when_started_from_file", "expected": { + "type": "rule", + "rules": { + "expected_one_instance_when_started_from_file": 0 + } + }, + "result": { + "type": "vlc_config", + "dest": "vlcrc" } } }