From cb2f9f180efcadbf6dcc14bfb1cc30f4b8aa2fdb Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Fri, 25 Nov 2022 07:53:50 +0100 Subject: [PATCH] pulled central data classes like Artist or Source out of song.py and put in eceternal file --- src/music_kraken/database/__init__.py | 14 +++-- src/music_kraken/database/artist.py | 15 ++++++ src/music_kraken/database/metadata.py | 17 ++++++ src/music_kraken/database/song.py | 75 ++------------------------- src/music_kraken/database/source.py | 6 +++ src/music_kraken/database/target.py | 30 +++++++++++ 6 files changed, 81 insertions(+), 76 deletions(-) create mode 100644 src/music_kraken/database/artist.py create mode 100644 src/music_kraken/database/metadata.py create mode 100644 src/music_kraken/database/source.py create mode 100644 src/music_kraken/database/target.py diff --git a/src/music_kraken/database/__init__.py b/src/music_kraken/database/__init__.py index 6c77dea..3a2685a 100644 --- a/src/music_kraken/database/__init__.py +++ b/src/music_kraken/database/__init__.py @@ -1,12 +1,16 @@ from . import ( temp_database, - song + song, + artist, + metadata, + source, + target ) Song = song.Song -Artist = song.Artist -Source = song.Source -Target = song.Target -Metadata = song.Metadata +Artist = artist.Artist +Source = source.Source +Target = target.Target +Metadata = metadata.Metadata cache = temp_database.TempDatabase() diff --git a/src/music_kraken/database/artist.py b/src/music_kraken/database/artist.py new file mode 100644 index 0000000..743db33 --- /dev/null +++ b/src/music_kraken/database/artist.py @@ -0,0 +1,15 @@ +class Artist: + def __init__(self, artist_data) -> None: + self.artist_data = artist_data + + self.id = self.artist_data['id'] + self.name = self.artist_data['name'] + + def __eq__(self, __o: object) -> bool: + if type(__o) != type(self): + return False + return self.id == __o.id + + def __str__(self) -> str: + return self.name + diff --git a/src/music_kraken/database/metadata.py b/src/music_kraken/database/metadata.py new file mode 100644 index 0000000..b14d4c4 --- /dev/null +++ b/src/music_kraken/database/metadata.py @@ -0,0 +1,17 @@ +from mutagen.easyid3 import EasyID3 + +class Metadata: + def __init__(self) -> None: + self.data = {} + + def get_all_metadata(self): + return list(self.data.items()) + + 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] diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index 87be512..0922e29 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -1,76 +1,9 @@ from typing import List -from ..utils.shared import ( - MUSIC_DIR -) -import os -from mutagen.easyid3 import EasyID3 - - -class Target: - def __init__(self) -> None: - self._file = None - self._path = None - - def set_file(self, _file: str): - self._file = _file - - def get_file(self) -> str | None: - if self._file is None: - return None - return os.path.join(MUSIC_DIR, self._file) - - def set_path(self, _path: str): - self._path = _path - - def get_path(self) -> str | None: - if self._path is None: - return None - return os.path.join(MUSIC_DIR, self._path) - - file = property(fget=get_file, fset=set_file) - path = property(fget=get_path, fset=set_path) - - -class Artist: - def __init__(self, artist_data) -> None: - self.artist_data = artist_data - - self.id = self.artist_data['id'] - self.name = self.artist_data['name'] - - def __eq__(self, __o: object) -> bool: - if type(__o) != type(self): - return False - return self.id == __o.id - - def __str__(self) -> str: - return self.name - - -class Source: - def __init__(self, src_data) -> None: - self.src_data = src_data - - 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): - return list(self.data.items()) - - 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] +from .artist import Artist +from .metadata import Metadata +from .source import Source +from .target import Target class Song: diff --git a/src/music_kraken/database/source.py b/src/music_kraken/database/source.py new file mode 100644 index 0000000..11888f4 --- /dev/null +++ b/src/music_kraken/database/source.py @@ -0,0 +1,6 @@ +class Source: + def __init__(self, src_data) -> None: + self.src_data = src_data + + self.src = self.src_data['src'] + self.url = self.src_data['url'] diff --git a/src/music_kraken/database/target.py b/src/music_kraken/database/target.py new file mode 100644 index 0000000..a8c490b --- /dev/null +++ b/src/music_kraken/database/target.py @@ -0,0 +1,30 @@ +import os + +from ..utils.shared import ( + MUSIC_DIR +) + + +class Target: + def __init__(self) -> None: + self._file = None + self._path = None + + def set_file(self, _file: str): + self._file = _file + + def get_file(self) -> str | None: + if self._file is None: + return None + return os.path.join(MUSIC_DIR, self._file) + + def set_path(self, _path: str): + self._path = _path + + def get_path(self) -> str | None: + if self._path is None: + return None + return os.path.join(MUSIC_DIR, self._path) + + file = property(fget=get_file, fset=set_file) + path = property(fget=get_path, fset=set_path)