VLC v1 finished, improve on instructions, improve on infra
This commit is contained in:
@@ -241,6 +241,18 @@ class PythonController:
|
||||
logger.error("Failed to get window size. Status code: %d", response.status_code)
|
||||
return None
|
||||
|
||||
def get_vm_wallpaper(self):
|
||||
"""
|
||||
Gets the wallpaper of the vm.
|
||||
"""
|
||||
response = requests.post(self.http_server + "/wallpaper")
|
||||
if response.status_code == 200:
|
||||
logger.info("Wallpaper downloaded successfully")
|
||||
return response.content
|
||||
else:
|
||||
logger.error("Failed to get wallpaper. Status code: %d", response.status_code)
|
||||
return None
|
||||
|
||||
def get_vlc_status(self, host='localhost', port=8080, password='password'):
|
||||
url = f'http://{host}:{port}/requests/status.xml'
|
||||
|
||||
|
||||
@@ -225,7 +225,12 @@ class DesktopEnv(gym.Env):
|
||||
|
||||
self.setup_controller.setup(self.evaluator["postconfig"]) if "postconfig" in self.evaluator else None
|
||||
|
||||
result_state = self.result_getter(self, self.evaluator["result"])
|
||||
try:
|
||||
result_state = self.result_getter(self, self.evaluator["result"])
|
||||
except FileNotFoundError:
|
||||
logger.error("File not found!")
|
||||
return 0
|
||||
|
||||
expected_state = self.expected_getter(self, self.evaluator["expected"]) if "expected" in self.evaluator \
|
||||
else None
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .file import get_cloud_file, get_vm_file, get_cache_file
|
||||
from .misc import get_rule
|
||||
from .info import get_vm_screen_size, get_vm_window_size, get_vm_wallpaper
|
||||
from .vlc import get_vlc_playing_info, get_vlc_config
|
||||
|
||||
@@ -95,6 +95,12 @@ with sync_playwright() as playwright:
|
||||
|
||||
|
||||
## VLC Media Player
|
||||
|
||||
### Bugs fix
|
||||
One thing on Ubuntu need to do, enter into the `meida`>`convert/save`>select files>`convert/save`
|
||||
Then enter the profile of `Audio - MP3`, change the profile for mp3, section audiocodec from "MP3" to "MPEG Audio"
|
||||
Otherwise the mp3 file will be created but with 0 bytes. It's a bug of VLC.
|
||||
|
||||
### Setting Up VLC's HTTP Interface
|
||||
|
||||
To enable and use the HTTP interface in VLC Media Player for remote control and status checks, follow these steps:
|
||||
|
||||
@@ -5,5 +5,5 @@ from .docs import compare_font_names, compare_subscript_contains, has_page_numbe
|
||||
from .docs import is_first_line_centered, check_file_exists, compare_contains_image
|
||||
from .pdf import check_pdf_pages
|
||||
from .libreoffice import check_libre_locale
|
||||
from .vlc import is_vlc_playing, is_vlc_recordings_folder
|
||||
from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, compare_images, compare_audios, compare_videos
|
||||
from .general import check_csv
|
||||
|
||||
@@ -7,7 +7,10 @@ from xml.etree import ElementTree
|
||||
import acoustid
|
||||
import cv2
|
||||
import imagehash
|
||||
from skimage.metrics import structural_similarity as ssim
|
||||
import librosa
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
|
||||
logger = logging.getLogger("desktopenv.metrics.vlc")
|
||||
|
||||
@@ -57,24 +60,79 @@ def is_vlc_recordings_folder(actual_config_path: str, rule: Dict[str, str]) -> f
|
||||
current_path = line.split('=')[-1].strip()
|
||||
# Compare with the Desktop path
|
||||
if current_path == expected_recording_file_path:
|
||||
return True
|
||||
return 1
|
||||
else:
|
||||
return False
|
||||
return 0
|
||||
# The configuration key was not found in the file
|
||||
return False
|
||||
return 0
|
||||
except FileNotFoundError:
|
||||
logger.error("VLC configuration file not found.")
|
||||
return False
|
||||
return 0
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {e}")
|
||||
return False
|
||||
return 0
|
||||
|
||||
|
||||
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 1
|
||||
else:
|
||||
return False
|
||||
return 0
|
||||
|
||||
|
||||
def compare_images(image1_path, image2_path):
|
||||
# You would call this function with the paths to the two images you want to compare:
|
||||
# score = compare_images('path_to_image1', 'path_to_image2')
|
||||
# print("Similarity score:", score)
|
||||
|
||||
# Open the images and convert to grayscale
|
||||
image1 = Image.open(image1_path).convert('L')
|
||||
image2 = Image.open(image2_path).convert('L')
|
||||
|
||||
# Resize images to the smaller one's size for comparison
|
||||
image1_size = image1.size
|
||||
image2_size = image2.size
|
||||
new_size = min(image1_size, image2_size)
|
||||
|
||||
image1 = image1.resize(new_size, Image.Resampling.LANCZOS)
|
||||
image2 = image2.resize(new_size, Image.Resampling.LANCZOS)
|
||||
|
||||
# Convert images to numpy arrays
|
||||
image1_array = np.array(image1)
|
||||
image2_array = np.array(image2)
|
||||
|
||||
# Calculate SSIM between two images
|
||||
similarity_index = ssim(image1_array, image2_array)
|
||||
|
||||
return similarity_index
|
||||
|
||||
|
||||
def compare_audios(audio_path_1, audio_path_2, max_distance=1000):
|
||||
"""
|
||||
Compare two audio files and return a similarity score in the range [0, 1].
|
||||
audio_path_1, audio_path_2: paths to the audio files to compare
|
||||
max_distance: an empirically determined maximum expected DTW distance
|
||||
"""
|
||||
# Example Usage:
|
||||
# similarity = compare_audios_simple('path_to_audio1.mp3', 'path_to_audio2.mp3')
|
||||
# print(f'Similarity Score: {similarity}')
|
||||
|
||||
# Convert to common format if necessary and load audio
|
||||
y1, sr1 = librosa.load(audio_path_1)
|
||||
y2, sr2 = librosa.load(audio_path_2)
|
||||
|
||||
# Extract MFCC features
|
||||
mfcc1 = librosa.feature.mfcc(y=y1, sr=sr1)
|
||||
mfcc2 = librosa.feature.mfcc(y=y2, sr=sr2)
|
||||
|
||||
# Compute Dynamic Time Warping distance
|
||||
distance, path = librosa.sequence.dtw(mfcc1.T, mfcc2.T)
|
||||
|
||||
# Normalize distance to get a similarity score
|
||||
normalized_distance = np.mean(distance) / max_distance
|
||||
similarity_score = 1 - min(normalized_distance, 1) # Ensure the score is within [0, 1]
|
||||
|
||||
return similarity_score
|
||||
|
||||
|
||||
def compare_videos(video_path1, video_path2, max_frames_to_check=100, threshold=5):
|
||||
|
||||
@@ -213,8 +213,7 @@ def get_wallpaper():
|
||||
if wallpaper_path:
|
||||
try:
|
||||
# Ensure the filename is secure
|
||||
filename = secure_filename(os.path.basename(wallpaper_path))
|
||||
return send_file(wallpaper_path, attachment_filename=filename)
|
||||
return send_file(wallpaper_path, mimetype='image/png')
|
||||
except Exception as e:
|
||||
app.logger.error(f"An error occurred while serving the wallpaper file: {e}")
|
||||
abort(500, description="Unable to serve the wallpaper file")
|
||||
|
||||
Reference in New Issue
Block a user