need to fix another fcking thing fck refactoring

This commit is contained in:
Lars Noack 2022-11-22 15:55:34 +01:00
parent 993545eb9d
commit 09fbb57380
5 changed files with 42 additions and 21 deletions

View File

@ -21,59 +21,58 @@ class Download:
def __init__(self) -> None: def __init__(self) -> None:
self.urls = [] self.urls = []
for row in temp_database.get_tracks_without_src(): for song in temp_database.get_tracks_without_src():
row['artists'] = [artist['name'] for artist in row['artists']]
id_ = row['id'] id_ = song['id']
if os.path.exists(os.path.join(MUSIC_DIR, row['file'])): if os.path.exists(song.target.file):
logger.info(f"skipping the fetching of the download links, cuz {row['file']} already exists.") logger.info(f"skipping the fetching of the download links, cuz {song['file']} already exists.")
continue continue
""" """
not implemented yet, will in one point crashe everything not implemented yet, will in one point crashe everything
# check File System # check File System
file_path = file_system.get_path(row) file_path = file_system.get_path(song)
if file_path is not None: if file_path is not None:
self.add_url(file_path, 'file', id_) self.add_url(file_path, 'file', id_)
continue continue
""" """
""" """
# check YouTube # check YouTube
youtube_url = youtube.Youtube.fetch_source(row) youtube_url = youtube.Youtube.fetch_source(song)
if youtube_url is not None: if youtube_url is not None:
self.add_url(youtube_url, 'youtube', id_) self.add_url(youtube_url, 'youtube', id_)
continue continue
# check musify # check musify
musify_url = musify.Musify.fetch_source(row) musify_url = musify.Musify.fetch_source(song)
if musify_url is not None: if musify_url is not None:
self.add_url(musify_url, 'musify', id_) self.add_url(musify_url, 'musify', id_)
continue continue
# check musify again, but with a different methode that takes longer # check musify again, but with a different methode that takes longer
musify_url = musify.get_musify_url_slow(row) musify_url = musify.get_musify_url_slow(song)
if musify_url is not None: if musify_url is not None:
self.add_url(musify_url, 'musify', id_) self.add_url(musify_url, 'musify', id_)
continue continue
""" """
for src in AUDIO_SOURCES: for src in AUDIO_SOURCES:
res = Download.fetch_from_src(row, src) res = Download.fetch_from_src(song, src)
if res is not None: if res is not None:
Download.add_url(res, src, id_) Download.add_url(res, src, id_)
logger.warning(f"Didn't find any sources for {row['title']}") logger.warning(f"Didn't find any sources for {song}")
@staticmethod @staticmethod
def fetch_from_src(row: dict, src: str): def fetch_from_src(song, src):
if src not in sources: if src not in sources:
raise ValueError(f"source {src} seems to not exist") raise ValueError(f"source {src} seems to not exist")
source_subclass = sources[src] source_subclass = sources[src]
return source_subclass.fetch_source(row) return source_subclass.fetch_source(song)
@staticmethod @staticmethod
def add_url(url: str, src: str, id_: str): def add_url(url: str, src: str, id_: str):
database.set_download_data(id_, url, src) temp_database.set_download_data(id_, url, src)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -47,7 +47,7 @@ class Youtube(AudioSource):
final_result = None final_result = None
results = cls.get_youtube_from_isrc(song.isrc) results = cls.get_youtube_from_isrc(song.isrc)
for result in results: for result in results:
video_title = result.title.lower() video_title = result['title'].lower()
match, distance = phonetic_compares.match_titles(video_title, real_title) match, distance = phonetic_compares.match_titles(video_title, real_title)
if match: if match:

View File

@ -4,6 +4,8 @@ from ..utils.shared import (
) )
import os import os
from mutagen.easyid3 import EasyID3
class Target: class Target:
def __init__(self) -> None: def __init__(self) -> None:
@ -46,6 +48,22 @@ class Source:
self.src = self.src_data['src'] self.src = self.src_data['src']
self.url = self.src_data['url'] self.url = self.src_data['url']
class Metadata:
def __init__(self) -> None:
self.data = {}
def get_all_metadata(self):
pass
def __setitem__(self, item, value):
if item in EasyID3.valid_keys.keys():
self.data[item] = value
def __getitem__(self, item):
if item not in self.data:
return None
return self.data[item]
class Song: class Song:
def __init__(self, json_response) -> None: def __init__(self, json_response) -> None:
@ -68,6 +86,10 @@ class Song:
self.target.file = self.json_data['file'] self.target.file = self.json_data['file']
self.target.path = self.json_data['path'] self.target.path = self.json_data['path']
# initialize id3 metadata
self.metadata = Metadata()
# EasyID3.valid_keys.keys()
def __str__(self) -> str: def __str__(self) -> str:
return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}" return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}"

View File

@ -1,7 +1,7 @@
from ..utils.shared import * from ..utils.shared import *
from ..utils.object_handeling import get_elem_from_obj, parse_music_brainz_date from ..utils.object_handeling import get_elem_from_obj, parse_music_brainz_date
from .. import database from ..database.temp_database import temp_database
from typing import List from typing import List
import musicbrainzngs import musicbrainzngs
@ -67,7 +67,7 @@ class MetadataDownloader:
def save(self): def save(self):
logger.info(f"caching {self}") logger.info(f"caching {self}")
database.add_artist( temp_database.add_artist(
musicbrainz_artistid=self.musicbrainz_artistid, musicbrainz_artistid=self.musicbrainz_artistid,
artist=self.artist artist=self.artist
) )
@ -130,7 +130,7 @@ class MetadataDownloader:
def save(self): def save(self):
logger.info(f"caching {self}") logger.info(f"caching {self}")
database.add_release_group( temp_database.add_release_group(
musicbrainz_releasegroupid=self.musicbrainz_releasegroupid, musicbrainz_releasegroupid=self.musicbrainz_releasegroupid,
artist_ids=[artist.musicbrainz_artistid for artist in self.artists], artist_ids=[artist.musicbrainz_artistid for artist in self.artists],
albumartist=self.albumartist, albumartist=self.albumartist,
@ -221,7 +221,7 @@ class MetadataDownloader:
def save(self): def save(self):
logger.info(f"caching {self}") logger.info(f"caching {self}")
database.add_release( temp_database.add_release(
musicbrainz_albumid=self.musicbrainz_albumid, musicbrainz_albumid=self.musicbrainz_albumid,
release_group_id=self.release_group.musicbrainz_releasegroupid, release_group_id=self.release_group.musicbrainz_releasegroupid,
title=self.title, title=self.title,
@ -287,7 +287,7 @@ class MetadataDownloader:
def save(self): def save(self):
logger.info(f"caching {self}") logger.info(f"caching {self}")
database.add_track( temp_database.add_track(
musicbrainz_releasetrackid=self.musicbrainz_releasetrackid, musicbrainz_releasetrackid=self.musicbrainz_releasetrackid,
musicbrainz_albumid=self.release.musicbrainz_albumid, musicbrainz_albumid=self.release.musicbrainz_albumid,
feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists], feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists],

View File

@ -26,7 +26,7 @@ class UrlPath:
# print(row) # print(row)
file, path = self.get_path_from_row(row) file, path = self.get_path_from_row(row)
logger.info(f"setting target to {file}") logger.info(f"setting target to {file}")
database.set_filepath(row['id'], file, path, genre) temp_database.set_filepath(row['id'], file, path, genre)
def get_path_from_row(self, row): def get_path_from_row(self, row):
""" """