This commit is contained in:
Lars Noack 2023-01-12 16:25:50 +01:00
parent b6a8966503
commit 133e360562
10 changed files with 84 additions and 50 deletions

View File

@ -51,7 +51,7 @@ song_input = Song(
length=666,
isrc="US-S1Z-99-00001",
tracksort=2,
target=Target(file="~/Music/test/Linkin Park/Hybrid Theory/Cure for the Itch.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"),
target=Target(file="test/Linkin Park/Hybrid Theory/out.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"),
lyrics=[
Lyrics(text="these are some depressive lyrics", language="en"),
Lyrics(text="test", language="en")
@ -100,6 +100,7 @@ for source in song.sources:
# try writing metadata
write_metadata(song)
exit()
# getting song by album ref
div()
song_output_list = cache.pull_songs(album_ref=album_input.reference)

View File

@ -4,17 +4,18 @@ import logging
from typing import List, Tuple
from pkg_resources import resource_string
from .objects.database_object import Reference
from .objects.parents import Reference
from .objects.source import Source
from .objects import (
Song,
Lyrics,
Metadata,
Target,
Artist,
Source,
Album
)
logger = logging.getLogger("database")
# Due to this not being deployed on a Server **HOPEFULLY**

View File

@ -1,13 +1,14 @@
from . import (
song,
id3_mapping
id3_mapping,
source
)
ID3_MAPPING = id3_mapping.Mapping
Song = song.Song
Artist = song.Artist
Source = song.Source
Source = source.Source
Target = song.Target
Metadata = song.Metadata
Lyrics = song.Lyrics

View File

@ -1,7 +1,7 @@
from ...utils.shared import (
DATABASE_LOGGER as logger
)
from .database_object import (
from .parents import (
DatabaseObject,
Reference
)

View File

@ -45,3 +45,22 @@ class DatabaseObject:
id = property(fget=get_id)
reference = property(fget=get_reference)
class SongAttribute:
def __init__(self, song=None):
# the reference to the song the lyrics belong to
self.song = song
def add_song(self, song):
self.song = song
def get_ref_song_id(self):
if self.song is None:
return None
return self.song.reference.id
def set_ref_song_id(self, song_id):
self.song_ref = Reference(song_id)
song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id)

View File

@ -7,33 +7,19 @@ from ...utils.shared import (
MUSIC_DIR,
DATABASE_LOGGER as logger
)
from .database_object import (
from .parents import (
DatabaseObject,
Reference
Reference,
SongAttribute
)
from .source import Source
"""
All Objects dependent
"""
class SongAttribute:
def __init__(self, song=None):
# the reference to the song the lyrics belong to
self.song = song
def add_song(self, song):
self.song = song
def get_ref_song_id(self):
if self.song is None:
return None
return self.song.reference.id
def set_ref_song_id(self, song_id):
self.song_ref = Reference(song_id)
song_ref_id = property(fget=get_ref_song_id, fset=set_ref_song_id)
class Metadata:
@ -58,7 +44,9 @@ class Metadata:
return
if type(value) != list:
raise ValueError(f"can only set attribute to list, not {type(value)}")
self.id3_attributes[key] = value
# self.id3_attributes[key] = [value[0], "HHHHSSSS"]
self.id3_attributes[key] = value[0]
def __getitem__(self, key):
if key not in self.id3_attributes:
@ -96,24 +84,7 @@ class Metadata:
return "\n".join(rows)
class Source(DatabaseObject, SongAttribute):
"""
create somehow like that
```python
# url won't be a valid one due to it being just an example
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd")
```
"""
def __init__(self, id_: str = None, src: str = None, url: str = None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.src = src
self.url = url
def __str__(self):
return f"{self.src}: {self.url}"
class Target(DatabaseObject, SongAttribute):

View File

@ -0,0 +1,41 @@
from enum import Enum
from .parents import (
DatabaseObject,
SongAttribute
)
class sources(Enum):
YOUTUBE = "youtube"
MUSIFY = "musify"
@classmethod
def get_homepage(cls, attribute) -> str:
homepage_map = {
cls.YOUTUBE: "https://www.youtube.com/",
cls.MUSIFY: "https://musify.club/"
}
return homepage_map[attribute]
class Source(DatabaseObject, SongAttribute):
"""
create somehow like that
```python
# url won't be a valid one due to it being just an example
Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd")
```
"""
def __init__(self, id_: str = None, src: str = None, url: str = None) -> None:
DatabaseObject.__init__(self, id_=id_)
SongAttribute.__init__(self)
self.src = sources(src)
self.url = url
def __str__(self):
return f"{self.src}: {self.url}"
homepage = property(fget=lambda self: sources.get_homepage(self.src))

View File

@ -7,7 +7,7 @@ from ..utils.shared import (
MUSIC_DIR,
SONG_LOGGER as logger
)
from .objects.database_object import DatabaseObject
from .objects.parents import DatabaseObject
class Metadata:
def __init__(self) -> None:

View File

@ -1,4 +1,4 @@
import mutagen
import mutagen
from mutagen.id3 import ID3, Frame
from typing import List
@ -18,7 +18,7 @@ class AudioMetadata:
self.frames: ID3 = ID3()
if self.file_location is not None:
if file_location is not None:
self.file_location = file_location
@ -26,10 +26,10 @@ class AudioMetadata:
print("adding")
for key, value in song.metadata:
"""
TODO:
Implement the adding to the frame thingie of the metadata
https://www.programcreek.com/python/example/84797/mutagen.id3.ID3
"""
print(key, value)
self.frames.add(mutagen.id3.Frames[key](encoding=3, text=value))
def save(self, file_location: str = None):
if file_location is not None:
@ -37,12 +37,12 @@ class AudioMetadata:
if self.file_location is None:
raise Exception("no file target provided to save the data to")
self.frames.save(filething=self.file_location)
self.frames.save(self.file_location, v2_version=4)
def set_file_location(self, file_location):
# try loading the data from the given file. if it doesn't succeed the frame remains empty
try:
self.frames.load(file_location)
self.frames.load(file_location, v2_version=4)
self._file_location = file_location
except mutagen.MutagenError:
logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"")
@ -52,7 +52,7 @@ class AudioMetadata:
def write_metadata(song: Song):
if not song.target.exists_on_disc:
print("afhhkj")
print(song.target.file)
return
id3_object = AudioMetadata(file_location=song.target.file)

BIN
test.db

Binary file not shown.