import os import platform from xml.etree import ElementTree import pygetwindow as gw import pyautogui from typing import Dict import logging logger = logging.getLogger("desktopenv.metrics.vlc") def get_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): logger.warning("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: logger.error(f"Error reading config file: {e}") return None def is_vlc_playing(actual: str, rule: Dict[str, str]) -> float: """ Checks if VLC is currently playing a file. """ with open(actual, 'rb') as file: actual_status = file.read().decode('utf-8') 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(): """ 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 logger.error("VLC window not found.") return False except Exception as e: logger.error(f"An error occurred: {e}") return False