diff --git a/src/music_kraken/audio_source/fetch_source.py b/src/music_kraken/audio_source/fetch_source.py index 3c24d6b..678c078 100644 --- a/src/music_kraken/audio_source/fetch_source.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -21,59 +21,58 @@ class Download: def __init__(self) -> None: self.urls = [] - for row in temp_database.get_tracks_without_src(): - row['artists'] = [artist['name'] for artist in row['artists']] + for song in temp_database.get_tracks_without_src(): - id_ = row['id'] - if os.path.exists(os.path.join(MUSIC_DIR, row['file'])): - logger.info(f"skipping the fetching of the download links, cuz {row['file']} already exists.") + id_ = song['id'] + if os.path.exists(song.target.file): + logger.info(f"skipping the fetching of the download links, cuz {song['file']} already exists.") continue """ not implemented yet, will in one point crashe everything # check File System - file_path = file_system.get_path(row) + file_path = file_system.get_path(song) if file_path is not None: self.add_url(file_path, 'file', id_) continue """ """ # check YouTube - youtube_url = youtube.Youtube.fetch_source(row) + youtube_url = youtube.Youtube.fetch_source(song) if youtube_url is not None: self.add_url(youtube_url, 'youtube', id_) continue # check musify - musify_url = musify.Musify.fetch_source(row) + musify_url = musify.Musify.fetch_source(song) if musify_url is not None: self.add_url(musify_url, 'musify', id_) continue # 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: self.add_url(musify_url, 'musify', id_) continue """ for src in AUDIO_SOURCES: - res = Download.fetch_from_src(row, src) + res = Download.fetch_from_src(song, src) if res is not None: 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 - def fetch_from_src(row: dict, src: str): + def fetch_from_src(song, src): if src not in sources: raise ValueError(f"source {src} seems to not exist") source_subclass = sources[src] - return source_subclass.fetch_source(row) + return source_subclass.fetch_source(song) @staticmethod 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__": diff --git a/src/music_kraken/audio_source/sources/youtube.py b/src/music_kraken/audio_source/sources/youtube.py index 2450d1a..00acd15 100644 --- a/src/music_kraken/audio_source/sources/youtube.py +++ b/src/music_kraken/audio_source/sources/youtube.py @@ -47,7 +47,7 @@ class Youtube(AudioSource): final_result = None results = cls.get_youtube_from_isrc(song.isrc) for result in results: - video_title = result.title.lower() + video_title = result['title'].lower() match, distance = phonetic_compares.match_titles(video_title, real_title) if match: diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index dcf99ff..baab8f3 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -4,6 +4,8 @@ from ..utils.shared import ( ) import os +from mutagen.easyid3 import EasyID3 + class Target: def __init__(self) -> None: @@ -46,6 +48,22 @@ class Source: self.src = self.src_data['src'] 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: def __init__(self, json_response) -> None: @@ -68,6 +86,10 @@ class Song: self.target.file = self.json_data['file'] self.target.path = self.json_data['path'] + # initialize id3 metadata + self.metadata = Metadata() + # EasyID3.valid_keys.keys() + def __str__(self) -> str: return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}" diff --git a/src/music_kraken/metadata/metadata_fetch.py b/src/music_kraken/metadata/metadata_fetch.py index db8a803..45145cb 100644 --- a/src/music_kraken/metadata/metadata_fetch.py +++ b/src/music_kraken/metadata/metadata_fetch.py @@ -1,7 +1,7 @@ from ..utils.shared import * 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 import musicbrainzngs @@ -67,7 +67,7 @@ class MetadataDownloader: def save(self): logger.info(f"caching {self}") - database.add_artist( + temp_database.add_artist( musicbrainz_artistid=self.musicbrainz_artistid, artist=self.artist ) @@ -130,7 +130,7 @@ class MetadataDownloader: def save(self): logger.info(f"caching {self}") - database.add_release_group( + temp_database.add_release_group( musicbrainz_releasegroupid=self.musicbrainz_releasegroupid, artist_ids=[artist.musicbrainz_artistid for artist in self.artists], albumartist=self.albumartist, @@ -221,7 +221,7 @@ class MetadataDownloader: def save(self): logger.info(f"caching {self}") - database.add_release( + temp_database.add_release( musicbrainz_albumid=self.musicbrainz_albumid, release_group_id=self.release_group.musicbrainz_releasegroupid, title=self.title, @@ -287,7 +287,7 @@ class MetadataDownloader: def save(self): logger.info(f"caching {self}") - database.add_track( + temp_database.add_track( musicbrainz_releasetrackid=self.musicbrainz_releasetrackid, musicbrainz_albumid=self.release.musicbrainz_albumid, feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists], diff --git a/src/music_kraken/target/set_target.py b/src/music_kraken/target/set_target.py index 485f359..745e07d 100644 --- a/src/music_kraken/target/set_target.py +++ b/src/music_kraken/target/set_target.py @@ -26,7 +26,7 @@ class UrlPath: # print(row) file, path = self.get_path_from_row(row) 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): """