From dee7f9f1520e39290fe7253f4ed5b978e2828779 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 12 Dec 2022 15:40:41 +0100 Subject: [PATCH] afdfa --- src/music_kraken/database/temp_database.py | 9 ++- src/music_kraken/metadata/sources/__init__.py | 4 ++ .../metadata/sources/musicbrainz.py | 56 +++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/music_kraken/metadata/sources/__init__.py create mode 100644 src/music_kraken/metadata/sources/musicbrainz.py diff --git a/src/music_kraken/database/temp_database.py b/src/music_kraken/database/temp_database.py index 7ffc6f3..005b566 100644 --- a/src/music_kraken/database/temp_database.py +++ b/src/music_kraken/database/temp_database.py @@ -1,4 +1,4 @@ -from .database import Database +from .new_database import Database from ..utils.shared import ( TEMP_DATABASE_PATH, @@ -9,8 +9,11 @@ logger = DATABASE_LOGGER class TempDatabase(Database): - def __init__(self) -> None: - super().__init__(TEMP_DATABASE_PATH, False) + def __init__(self, reset_on_start: bool = True) -> None: + super().__init__(TEMP_DATABASE_PATH) + + if reset_on_start: + self.reset() temp_database = TempDatabase() diff --git a/src/music_kraken/metadata/sources/__init__.py b/src/music_kraken/metadata/sources/__init__.py new file mode 100644 index 0000000..e9dba5f --- /dev/null +++ b/src/music_kraken/metadata/sources/__init__.py @@ -0,0 +1,4 @@ +from enum import Enum + +class Providers(Enum): + musicbrainz = "musicbrainz" diff --git a/src/music_kraken/metadata/sources/musicbrainz.py b/src/music_kraken/metadata/sources/musicbrainz.py new file mode 100644 index 0000000..8e9b689 --- /dev/null +++ b/src/music_kraken/metadata/sources/musicbrainz.py @@ -0,0 +1,56 @@ +from typing import List +import musicbrainzngs + +from ...database import ( + Artist, + Album, + Song +) +from ...utils.object_handeling import ( + get_elem_from_obj +) + +def get_artist(flat: bool = False) -> Artist: + # getting the flat artist + artist_object = Artist() + if flat: + return artist_object + # get additional stuff like discography + return artist_object + +def get_album(flat: bool = False) -> Album: + # getting the flat album object + album_object = Album() + if flat: + return album_object + # get additional stuff like tracklist + return album_object + +def get_song(mb_id: str, flat: bool = False) -> Song: + # getting the flat song object + try: + result = musicbrainzngs.get_recording_by_id(mb_id, + includes=["artists", "releases", "recording-rels", "isrcs", + "work-level-rels"]) + except musicbrainzngs.musicbrainz.NetworkError: + return + + recording_data = result['recording'] + + song_object = Song( + mb_id=mb_id, + title=recording_data['title'], + length=get_elem_from_obj(recording_data, ['length']), + isrc=get_elem_from_obj(recording_data, ['isrc-list', 0]) + ) + if flat: + return song_object + + # fetch additional stuff + artist_data_list = get_elem_from_obj(recording_data, ['artist-credit'], return_if_none=[]) + for artist_data in artist_data_list: + mb_artist_id = get_elem_from_obj(artist_data, ['artist', 'id']) + + release_data = get_elem_from_obj(recording_data, ['release-list', -1]) + mb_release_id = get_elem_from_obj(release_data, ['id']) + return song_object