mirror of
https://github.com/csd4ni3l/music-player.git
synced 2026-01-01 04:03:42 +01:00
fix download text having whitespace, fix display mode None crashing, and removed files and folders crashing
This commit is contained in:
@@ -80,7 +80,7 @@ class Downloader(arcade.gui.UIView):
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
|
||||
for line in process.stdout:
|
||||
self.yt_dl_buffer = line
|
||||
self.yt_dl_buffer = line.strip()
|
||||
|
||||
process.wait()
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ class FileManager(arcade.gui.UIView):
|
||||
|
||||
def get_content(self, directory):
|
||||
if not directory in self.content_cache or time.perf_counter() - self.content_cache[directory][-1] >= 30:
|
||||
try:
|
||||
entries = os.listdir(directory)
|
||||
except PermissionError:
|
||||
return None
|
||||
|
||||
filtered = [
|
||||
entry for entry in entries
|
||||
@@ -116,6 +119,9 @@ class FileManager(arcade.gui.UIView):
|
||||
self.file_buttons[-1].on_click = lambda event, file=f"{self.current_directory}/{file}": self.submit(file)
|
||||
|
||||
def change_directory(self, directory):
|
||||
if directory.startswith("//"): # Fix / paths
|
||||
directory = directory[1:]
|
||||
|
||||
self.current_directory = directory
|
||||
|
||||
self.show_directory()
|
||||
|
||||
@@ -163,6 +163,9 @@ class Main(arcade.gui.UIView):
|
||||
self.no_music_label = self.anchor.add(arcade.gui.UILabel(text="No music files were found in this directory or playlist.", font_name="Roboto", font_size=24), anchor_x="center", anchor_y="center")
|
||||
self.no_music_label.visible = False
|
||||
|
||||
self.no_playlists_label = self.anchor.add(arcade.gui.UILabel(text="You have no playlists.", font_name="Roboto", font_size=24))
|
||||
self.no_playlists_label.visible = False
|
||||
|
||||
if self.current_mode == "files":
|
||||
self.show_content(os.path.expanduser(self.current_tab))
|
||||
elif self.current_mode == "playlist":
|
||||
@@ -291,6 +294,8 @@ class Main(arcade.gui.UIView):
|
||||
|
||||
n = 0
|
||||
|
||||
self.no_playlists_label.visible = not self.playlist_content[tab]
|
||||
|
||||
if self.current_playlist:
|
||||
if not self.search_term == "":
|
||||
matches = process.extract(self.search_term, self.playlist_content[tab], limit=5, processor=lambda text: text.lower(), scorer=fuzz.partial_token_sort_ratio)
|
||||
@@ -347,6 +352,11 @@ class Main(arcade.gui.UIView):
|
||||
|
||||
for tab in self.tab_options:
|
||||
expanded_tab = os.path.expanduser(tab)
|
||||
|
||||
if not os.path.exists(expanded_tab) or not os.path.isdir(expanded_tab):
|
||||
self.tab_options.remove(tab)
|
||||
return
|
||||
|
||||
self.tab_content[expanded_tab] = []
|
||||
|
||||
for filename in os.listdir(expanded_tab):
|
||||
@@ -359,6 +369,10 @@ class Main(arcade.gui.UIView):
|
||||
|
||||
for playlist, content in self.settings_dict.get("playlists", {}).items():
|
||||
for file in content:
|
||||
if not os.path.exists(file) or not os.path.isfile(file):
|
||||
content.remove(file) # also removes reference from self.settings_dict["playlists"]
|
||||
continue
|
||||
|
||||
if file not in self.thumbnails:
|
||||
self.thumbnails[file] = get_audio_thumbnail_texture(file, self.window.size)
|
||||
|
||||
@@ -373,6 +387,9 @@ class Main(arcade.gui.UIView):
|
||||
self.tab_buttons[os.path.expanduser(tab)] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=os.path.basename(os.path.normpath(os.path.expanduser(tab))), style=button_style, width=self.window.width / 10, height=self.window.height / 15))
|
||||
self.tab_buttons[os.path.expanduser(tab)].on_click = lambda event, tab=os.path.expanduser(tab): self.show_content(os.path.expanduser(tab))
|
||||
elif self.current_mode == "playlist":
|
||||
if not self.playlist_content:
|
||||
self.no_playlists_label.visible = True
|
||||
|
||||
for playlist in self.playlist_content:
|
||||
self.tab_buttons[playlist] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=playlist, style=button_style, width=self.window.width / 10, height=self.window.height / 15))
|
||||
self.tab_buttons[playlist].on_click = lambda event, playlist=playlist: self.show_content(playlist)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from arcade.gui.widgets.buttons import UITextureButton
|
||||
import copy, pypresence, json
|
||||
|
||||
import arcade, arcade.gui
|
||||
@@ -163,7 +162,10 @@ class Settings(arcade.gui.UIView):
|
||||
if self.settings_dict['vsync']:
|
||||
self.window.set_vsync(True)
|
||||
display_mode = self.window.display.get_default_screen().get_mode()
|
||||
if display_mode:
|
||||
refresh_rate = display_mode.rate
|
||||
else:
|
||||
refresh_rate = 60
|
||||
self.window.set_update_rate(1 / refresh_rate)
|
||||
self.window.set_draw_rate(1 / refresh_rate)
|
||||
|
||||
@@ -218,7 +220,6 @@ class Settings(arcade.gui.UIView):
|
||||
file.write(json.dumps(self.settings_dict, indent=4))
|
||||
|
||||
def update(self, setting=None, button_state=None, setting_type="bool"):
|
||||
setting_dict = settings[self.current_category][setting]
|
||||
config_key = settings[self.current_category][setting]["config_key"]
|
||||
|
||||
if setting_type == "option":
|
||||
|
||||
5
run.py
5
run.py
@@ -11,7 +11,7 @@ import logging, datetime, json, sys, arcade
|
||||
|
||||
arcade.ArcadeContext.atlas_size = (16384, 16384)
|
||||
|
||||
from utils.utils import get_closest_resolution, print_debug_info, on_exception, ErrorView
|
||||
from utils.utils import get_closest_resolution, print_debug_info, on_exception
|
||||
from utils.constants import log_dir, menu_background_color
|
||||
from menus.main import Main
|
||||
from arcade.experimental.controller_window import ControllerWindow
|
||||
@@ -77,7 +77,10 @@ window = ControllerWindow(width=resolution[0], height=resolution[1], title='Musi
|
||||
if vsync:
|
||||
window.set_vsync(True)
|
||||
display_mode = window.display.get_default_screen().get_mode()
|
||||
if display_mode:
|
||||
refresh_rate = display_mode.rate
|
||||
else:
|
||||
refresh_rate = 60
|
||||
window.set_update_rate(1 / refresh_rate)
|
||||
window.set_draw_rate(1 / refresh_rate)
|
||||
elif not fps_limit == 0:
|
||||
|
||||
Reference in New Issue
Block a user