mirror of
https://github.com/csd4ni3l/music-player.git
synced 2026-01-01 04:03:42 +01:00
Make fpcalc missing page show up on startup instead of when viewing metadata, add metadata to file automatically with the downloader, fix lyrics caching
This commit is contained in:
@@ -5,7 +5,9 @@ import arcade, arcade.gui, os, json, threading, subprocess, urllib.request, plat
|
||||
|
||||
from arcade.gui.experimental.focus import UIFocusGroup
|
||||
|
||||
from utils.music_handling import adjust_volume
|
||||
from utils.music_handling import adjust_volume, add_metadata_to_file
|
||||
from utils.musicbrainz_metadata import get_music_metadata
|
||||
from utils.acoustid_metadata import get_recording_id_from_acoustid
|
||||
from utils.constants import button_style
|
||||
from utils.preload import button_texture, button_hovered_texture
|
||||
|
||||
@@ -151,6 +153,19 @@ class Downloader(arcade.gui.UIView):
|
||||
except Exception as e:
|
||||
self.yt_dl_buffer = f"ERROR: Could not normalize volume due to an error: {e}"
|
||||
return
|
||||
|
||||
self.yt_dl_buffer = "Analyzing with Acoustid to get accurate metadata..."
|
||||
acoustid_id, musicbrainz_id = get_recording_id_from_acoustid("downloaded_music.mp3")
|
||||
|
||||
self.yt_dl_buffer = "Caching MusicBrainz and Lyrics metadata..."
|
||||
if musicbrainz_id:
|
||||
music_metadata, artist_metadata, album_metadata, lyrics_metadata = get_music_metadata(musicbrainz_id=musicbrainz_id)
|
||||
else:
|
||||
music_metadata, artist_metadata, album_metadata, lyrics_metadata = get_music_metadata(artist=artist, title=title)
|
||||
|
||||
self.yt_dl_buffer = "Adding missing metadata to file..."
|
||||
add_metadata_to_file("downloaded_music.mp3", [artist['musicbrainz_id'] for artist in artist_metadata.values()], artist, title, lyrics_metadata[1], music_metadata["isrc-list"], acoustid_id)
|
||||
|
||||
try:
|
||||
output_filename = os.path.join(path, f"{title}.mp3")
|
||||
os.replace("downloaded_music.mp3", output_filename)
|
||||
|
||||
61
menus/fpcalc_missing.py
Normal file
61
menus/fpcalc_missing.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import arcade, arcade.gui, sys, gzip, platform, tarfile, urllib.request, os, io, glob, shutil
|
||||
|
||||
from zipfile import ZipFile
|
||||
|
||||
from utils.acoustid_metadata import get_fpcalc_path, get_fpcalc_name
|
||||
|
||||
class FpcalcMissing(arcade.gui.UIView):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def on_show_view(self):
|
||||
super().on_show_view()
|
||||
|
||||
msgbox = self.add_widget(arcade.gui.UIMessageBox(width=self.window.width / 2, height=self.window.height / 2, title="Third-party fpcalc download", message_text="We need to download fpcalc from AcoustID to recognize the song for you for better results.\nIf you say no, we will use a searching algorithm instead which might give wrong results.\nEven if fpcalc is downloaded, it might not find the music since its a community-based project.\nIf so, we will fallback to the searching algorithm.\nDo you want to continue?", buttons=("Yes", "No")))
|
||||
msgbox.on_action = lambda event: self.download_fpcalc() if event.action == "Yes" else self.exit()
|
||||
|
||||
def download_fpcalc(self):
|
||||
system = platform.system()
|
||||
architecture = platform.machine()
|
||||
|
||||
os.makedirs("bin", exist_ok=True)
|
||||
|
||||
if system == "Linux":
|
||||
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-linux-x86_64.tar.gz"
|
||||
elif system == "Darwin":
|
||||
if architecture.lower() == "x86_64" or architecture.lower() == "amd64":
|
||||
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-macos-x86_64.tar.gz"
|
||||
else:
|
||||
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-macos-arm64.tar.gz"
|
||||
elif system == "Windows":
|
||||
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-windows-x86_64.zip"
|
||||
|
||||
if url.endswith(".zip"):
|
||||
zip_path = os.path.join(os.getcwd(), "bin", "chromaprint.zip")
|
||||
urllib.request.urlretrieve(url, zip_path)
|
||||
with ZipFile(zip_path) as file:
|
||||
file.extractall(os.path.join(os.getcwd(), "bin"))
|
||||
|
||||
os.remove(zip_path)
|
||||
else:
|
||||
tar_gz_path = os.path.join(os.getcwd(), "bin", "chromaprint.tar.gz")
|
||||
urllib.request.urlretrieve(url, tar_gz_path)
|
||||
|
||||
with gzip.open(tar_gz_path, "rb") as f: # For some reason, tarfile by itself didnt work for tar.gz so i have to uncompress with gzip first and then with tarfile
|
||||
with tarfile.open(fileobj=io.BytesIO(f.read())) as tar:
|
||||
tar.extractall(os.path.join(os.getcwd(), "bin"))
|
||||
|
||||
os.remove(tar_gz_path)
|
||||
|
||||
chromaprint_matches = glob.glob(os.path.join("bin", "chromaprint*"))
|
||||
if chromaprint_matches:
|
||||
shutil.move(os.path.join(chromaprint_matches[0], get_fpcalc_name()), os.path.join("bin", get_fpcalc_name()))
|
||||
shutil.rmtree(chromaprint_matches[0])
|
||||
|
||||
os.chmod(get_fpcalc_path(), 0o755)
|
||||
|
||||
self.exit()
|
||||
|
||||
def exit(self):
|
||||
from menus.main import Main
|
||||
self.window.show_view(Main())
|
||||
@@ -485,16 +485,6 @@ class Main(arcade.gui.UIView):
|
||||
|
||||
update_last_play_statistics(music_path)
|
||||
|
||||
if not music_path in self.loaded_sounds:
|
||||
self.loaded_sounds[music_path] = arcade.Sound(music_path, streaming=self.settings_dict.get("music_mode", "Stream") == "Stream")
|
||||
|
||||
self.volume = self.settings_dict.get("default_volume", 100)
|
||||
self.volume_slider.value = self.volume
|
||||
|
||||
self.current_music_player = self.loaded_sounds[music_path].play()
|
||||
self.current_music_player.volume = self.volume / 100
|
||||
self.current_length = self.loaded_sounds[music_path].get_length()
|
||||
|
||||
self.current_music_artist = artist
|
||||
self.current_music_title = title
|
||||
self.current_music_title_label.text = title
|
||||
@@ -503,8 +493,6 @@ class Main(arcade.gui.UIView):
|
||||
self.current_music_thumbnail_image.texture = self.file_metadata[music_path]["thumbnail"]
|
||||
self.time_label.text = "00:00"
|
||||
self.full_length_label.text = "00:00"
|
||||
self.progressbar.max_value = self.current_length
|
||||
self.progressbar.value = 0
|
||||
self.current_synchronized_lyrics = get_lyrics(self.current_music_artist, self.current_music_title)[1]
|
||||
self.lyrics_times, self.parsed_lyrics = parse_synchronized_lyrics(self.current_synchronized_lyrics) if self.current_synchronized_lyrics else (None, None)
|
||||
|
||||
@@ -512,6 +500,16 @@ class Main(arcade.gui.UIView):
|
||||
self.current_lyrics_label.text = "No known lyrics found"
|
||||
self.next_lyrics_label.text = "No known lyrics found"
|
||||
|
||||
if not music_path in self.loaded_sounds:
|
||||
self.loaded_sounds[music_path] = arcade.Sound(music_path, streaming=self.settings_dict.get("music_mode", "Stream") == "Stream")
|
||||
|
||||
self.volume = self.settings_dict.get("default_volume", 100)
|
||||
self.volume_slider.value = self.volume
|
||||
self.current_music_player = self.loaded_sounds[music_path].play()
|
||||
self.current_music_player.volume = self.volume / 100
|
||||
self.current_length = self.loaded_sounds[music_path].get_length()
|
||||
self.progressbar.max_value = self.current_length
|
||||
self.progressbar.value = 0
|
||||
else:
|
||||
if self.current_music_player is not None:
|
||||
self.skip_sound() # reset properties
|
||||
|
||||
@@ -9,7 +9,7 @@ from utils.constants import button_style
|
||||
from utils.preload import button_texture, button_hovered_texture
|
||||
from utils.utils import convert_seconds_to_date
|
||||
from utils.music_handling import convert_timestamp_to_time_ago, truncate_end, add_metadata_to_file
|
||||
from utils.acoustid_metadata import get_recording_id_from_acoustic, get_fpcalc_path, download_fpcalc
|
||||
from utils.acoustid_metadata import get_recording_id_from_acoustid, get_fpcalc_path
|
||||
|
||||
class MetadataViewer(arcade.gui.UIView):
|
||||
def __init__(self, pypresence_client, metadata_type="file", metadata=None, file_path=None, *args):
|
||||
@@ -28,20 +28,11 @@ class MetadataViewer(arcade.gui.UIView):
|
||||
|
||||
self.artist = self.file_metadata["artist"] if not self.file_metadata["artist"] == "Unknown" else None
|
||||
self.title = self.file_metadata["title"]
|
||||
if metadata.get("confirm_download") is None:
|
||||
if not os.path.exists(get_fpcalc_path()):
|
||||
self.msgbox = self.add_widget(arcade.gui.UIMessageBox(width=self.window.width / 2, height=self.window.height / 2, title="Third-party fpcalc download", message_text="We need to download fpcalc from AcoustID to recognize the song for you for better results.\nIf you say no, we will use a searching algorithm instead which might give wrong results.\nEven if fpcalc is downloaded, it might not find the music since its a community-based project.\nIf so, we will fallback to the searching algorithm.\nDo you want to continue?", buttons=("Yes", "No")))
|
||||
self.msgbox.on_action = lambda event: self.window.show_view(MetadataViewer(pypresence_client, metadata_type, metadata | {"confirm_download": event.action == "Yes"}, file_path, *args))
|
||||
return
|
||||
else:
|
||||
self.acoustid_id, musicbrainz_id = get_recording_id_from_acoustic(self.file_path)
|
||||
else:
|
||||
if metadata["confirm_download"]:
|
||||
download_fpcalc()
|
||||
self.acoustid_id, musicbrainz_id = get_recording_id_from_acoustic(self.file_path)
|
||||
|
||||
else:
|
||||
self.acoustid_id = None
|
||||
if os.path.exists(get_fpcalc_path()):
|
||||
self.acoustid_id, musicbrainz_id = get_recording_id_from_acoustid(self.file_path)
|
||||
else:
|
||||
self.acoustid_id, musicbrainz_id = None, None
|
||||
|
||||
if self.acoustid_id and musicbrainz_id:
|
||||
self.music_metadata, self.artist_metadata, self.album_metadata, self.lyrics_metadata = get_music_metadata(musicbrainz_id=musicbrainz_id)
|
||||
|
||||
Reference in New Issue
Block a user