Initialize VLC getters and metrics, fix some bugs in infra logic, needs to be refactored later on
This commit is contained in:
@@ -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