VLC updates, and some infra bugs fix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
from typing import Dict
|
||||
|
||||
import os
|
||||
import requests
|
||||
|
||||
|
||||
@@ -37,11 +37,16 @@ def get_vm_file(env, config: Dict[str, str]) -> str:
|
||||
_path = os.path.join(env.cache_dir, config["dest"])
|
||||
|
||||
file = env.controller.get_file(config["path"])
|
||||
|
||||
if file is None:
|
||||
raise FileNotFoundError("File not found on VM: {:}".format(config["path"]))
|
||||
|
||||
with open(_path, "wb") as f:
|
||||
f.write(file)
|
||||
|
||||
return _path
|
||||
|
||||
|
||||
def get_cache_file(env, config: Dict[str, str]) -> str:
|
||||
"""
|
||||
Config:
|
||||
|
||||
@@ -1,66 +1,13 @@
|
||||
import logging
|
||||
from typing import TypeVar
|
||||
|
||||
import platform
|
||||
import subprocess
|
||||
import ctypes
|
||||
import os
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("desktopenv.getters.misc")
|
||||
|
||||
R = TypeVar("Rule")
|
||||
|
||||
|
||||
def get_rule(env, config: R) -> R:
|
||||
"""
|
||||
Returns the rule as-is.
|
||||
"""
|
||||
return config["rules"]
|
||||
|
||||
|
||||
def get_desktop_path():
|
||||
username = os.getlogin() # Get the current username
|
||||
if platform.system() == "Windows":
|
||||
return os.path.join("C:", "Users", username, "Desktop")
|
||||
elif platform.system() == "Darwin": # macOS is identified as 'Darwin'
|
||||
return os.path.join("/Users", username, "Desktop")
|
||||
elif platform.system() == "Linux":
|
||||
return os.path.join("/home", username, "Desktop")
|
||||
else:
|
||||
raise Exception("Unsupported operating system")
|
||||
|
||||
|
||||
def get_wallpaper():
|
||||
def get_wallpaper_windows():
|
||||
SPI_GETDESKWALLPAPER = 0x73
|
||||
MAX_PATH = 260
|
||||
buffer = ctypes.create_unicode_buffer(MAX_PATH)
|
||||
ctypes.windll.user32.SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, buffer, 0)
|
||||
return buffer.value
|
||||
|
||||
def get_wallpaper_macos():
|
||||
script = """
|
||||
tell application "System Events" to tell every desktop to get picture
|
||||
"""
|
||||
process = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE)
|
||||
output, error = process.communicate()
|
||||
if error:
|
||||
logger.error("Error: %s", error)
|
||||
else:
|
||||
return output.strip().decode('utf-8')
|
||||
|
||||
def get_wallpaper_linux():
|
||||
try:
|
||||
output = subprocess.check_output(["gsettings", "get", "org.gnome.desktop.background", "picture-uri"])
|
||||
return output.decode('utf-8').strip().replace('file://', '').replace("'", "")
|
||||
except Exception as e:
|
||||
logger.error("Error: %s", e)
|
||||
return None
|
||||
|
||||
os_name = platform.system()
|
||||
if os_name == 'Windows':
|
||||
return get_wallpaper_windows()
|
||||
elif os_name == 'Darwin':
|
||||
return get_wallpaper_macos()
|
||||
elif os_name == 'Linux':
|
||||
return get_wallpaper_linux()
|
||||
else:
|
||||
return "Unsupported OS"
|
||||
|
||||
@@ -33,7 +33,7 @@ def get_vlc_config(env, config: Dict[str, str]):
|
||||
# fixme: depends on how we config and install the vlc in virtual machine, need to be aligned and double-checked
|
||||
if os_type == "Linux":
|
||||
config_path = \
|
||||
env.controller.execute_python_command("import os; print(os.path.expanduser('~/snap/vlc/common/vlcrc'))")[
|
||||
env.controller.execute_python_command("import os; print(os.path.expanduser('~/.config/vlc/vlcrc'))")[
|
||||
'output'].strip()
|
||||
elif os_type == "Darwin":
|
||||
config_path = env.controller.execute_python_command(
|
||||
|
||||
@@ -7,8 +7,6 @@ from xml.etree import ElementTree
|
||||
import acoustid
|
||||
import cv2
|
||||
import imagehash
|
||||
import pyautogui
|
||||
import pygetwindow as gw # todo: change to the library that supports Linux
|
||||
from PIL import Image
|
||||
|
||||
logger = logging.getLogger("desktopenv.metrics.vlc")
|
||||
@@ -72,30 +70,11 @@ def is_vlc_recordings_folder(actual_config_path: str, rule: Dict[str, str]) -> f
|
||||
return False
|
||||
|
||||
|
||||
def are_audio_files_similar(mp3_file_path, mp4_file_path):
|
||||
# Extract audio fingerprint from MP3 file
|
||||
mp3_fingerprint, mp3_duration = acoustid.fingerprint_file(mp3_file_path)
|
||||
|
||||
# Extract the audio stream from the MP4 file
|
||||
mp4_audio_path = os.path.splitext(mp4_file_path)[0] + '_extracted.mp3'
|
||||
try:
|
||||
subprocess.run(["ffmpeg", "-i", mp4_file_path, "-vn", "-ar", "44100", "-ac", "2", "-ab", "192k", "-f", "mp3",
|
||||
mp4_audio_path], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"An error occurred during audio extraction from MP4: {e}")
|
||||
return False
|
||||
|
||||
# Extract audio fingerprint from the extracted audio
|
||||
mp4_fingerprint, mp4_duration = acoustid.fingerprint_file(mp4_audio_path)
|
||||
|
||||
# Clean up temporary extracted audio file
|
||||
os.remove(mp4_audio_path)
|
||||
|
||||
# Compare fingerprints (rudimentary comparison)
|
||||
if mp3_duration >= mp4_duration and mp3_fingerprint == mp4_fingerprint:
|
||||
def is_vlc_fullscreen(actual_window_size, screen_size):
|
||||
if actual_window_size['width'] == screen_size['width'] and actual_window_size['height'] == screen_size['height']:
|
||||
return True
|
||||
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def compare_videos(video_path1, video_path2, max_frames_to_check=100, threshold=5):
|
||||
@@ -137,28 +116,27 @@ def compare_videos(video_path1, video_path2, max_frames_to_check=100, threshold=
|
||||
return True
|
||||
|
||||
|
||||
def is_vlc_fullscreen():
|
||||
"""
|
||||
Checks if the VLC window is in full-screen mode.
|
||||
def are_audio_files_similar(mp3_file_path, mp4_file_path):
|
||||
# Extract audio fingerprint from MP3 file
|
||||
mp3_fingerprint, mp3_duration = acoustid.fingerprint_file(mp3_file_path)
|
||||
|
||||
When VLC is in full-screen mode, its window size matches the screen size with no borders.
|
||||
"""
|
||||
# Extract the audio stream from the MP4 file
|
||||
mp4_audio_path = os.path.splitext(mp4_file_path)[0] + '_extracted.mp3'
|
||||
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}")
|
||||
subprocess.run(["ffmpeg", "-i", mp4_file_path, "-vn", "-ar", "44100", "-ac", "2", "-ab", "192k", "-f", "mp3",
|
||||
mp4_audio_path], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"An error occurred during audio extraction from MP4: {e}")
|
||||
return False
|
||||
|
||||
# Extract audio fingerprint from the extracted audio
|
||||
mp4_fingerprint, mp4_duration = acoustid.fingerprint_file(mp4_audio_path)
|
||||
|
||||
# Clean up temporary extracted audio file
|
||||
os.remove(mp4_audio_path)
|
||||
|
||||
# Compare fingerprints (rudimentary comparison)
|
||||
if mp3_duration >= mp4_duration and mp3_fingerprint == mp4_fingerprint:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user