91 lines
2.8 KiB
Python
91 lines
2.8 KiB
Python
import os
|
|
import platform
|
|
import requests
|
|
from xml.etree import ElementTree
|
|
import pygetwindow as gw
|
|
import pyautogui
|
|
|
|
import logging
|
|
logger = logging.getLogger("desktopenv.metrics.vlc")
|
|
|
|
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):
|
|
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 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:
|
|
logger.error(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
|
|
logger.error("VLC window not found.")
|
|
return False
|
|
except Exception as e:
|
|
logger.error(f"An error occurred: {e}")
|
|
return False
|
|
|
|
|