This commit is contained in:
Lars Noack 2022-12-12 15:40:41 +01:00
parent 9d43dfd129
commit dee7f9f152
3 changed files with 66 additions and 3 deletions

View File

@ -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()

View File

@ -0,0 +1,4 @@
from enum import Enum
class Providers(Enum):
musicbrainz = "musicbrainz"

View File

@ -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