am
This commit is contained in:
parent
013e3dccfd
commit
b6a8966503
11
src/goof.py
11
src/goof.py
@ -8,6 +8,12 @@ from music_kraken import (
|
||||
Artist
|
||||
)
|
||||
|
||||
from music_kraken.tagging import (
|
||||
AudioMetadata,
|
||||
write_metadata,
|
||||
write_many_metadata
|
||||
)
|
||||
|
||||
import music_kraken.database.new_database as db
|
||||
|
||||
|
||||
@ -45,7 +51,7 @@ song_input = Song(
|
||||
length=666,
|
||||
isrc="US-S1Z-99-00001",
|
||||
tracksort=2,
|
||||
target=Target(file="~/Music/genre/artist/album/song.mp3", path="~/Music/genre/artist/album"),
|
||||
target=Target(file="~/Music/test/Linkin Park/Hybrid Theory/Cure for the Itch.mp3", path="~/Music/test/Linkin Park/Hybrid Theory/"),
|
||||
lyrics=[
|
||||
Lyrics(text="these are some depressive lyrics", language="en"),
|
||||
Lyrics(text="test", language="en")
|
||||
@ -91,6 +97,9 @@ print("--src--")
|
||||
for source in song.sources:
|
||||
print(source)
|
||||
|
||||
# try writing metadata
|
||||
write_metadata(song)
|
||||
|
||||
# getting song by album ref
|
||||
div()
|
||||
song_output_list = cache.pull_songs(album_ref=album_input.reference)
|
||||
|
@ -301,6 +301,7 @@ class Song(DatabaseObject):
|
||||
self._sources = source_list
|
||||
for source in self._sources:
|
||||
source.add_song(self)
|
||||
|
||||
self.metadata[ID3_MAPPING.FILE_WEBPAGE_URL.value] = [s.url for s in self._sources]
|
||||
|
||||
def get_metadata(self):
|
||||
|
@ -0,0 +1,9 @@
|
||||
from .id3 import (
|
||||
AudioMetadata,
|
||||
write_many_metadata,
|
||||
write_metadata
|
||||
)
|
||||
|
||||
AudioMetadata = AudioMetadata
|
||||
write_many_metadata = write_many_metadata
|
||||
write_metadata = write_metadata
|
@ -1,23 +1,35 @@
|
||||
import mutagen
|
||||
from mutagen.id3 import ID3
|
||||
from mutagen.id3 import ID3, Frame
|
||||
|
||||
from typing import List
|
||||
import logging
|
||||
|
||||
|
||||
logger = logging.Logger("hs")
|
||||
from ..utils.shared import (
|
||||
TAGGING_LOGGER as logger
|
||||
)
|
||||
from ..database import (
|
||||
Song
|
||||
)
|
||||
|
||||
|
||||
class AudioMetadata:
|
||||
def __init__(self, file_location: str = None) -> None:
|
||||
self.file_location = file_location
|
||||
self._file_location = None
|
||||
|
||||
self.frames: ID3 = ID3()
|
||||
|
||||
if self.file_location is not None:
|
||||
# try loading the data from the given file. if it doesn't succeed the frame remains empty
|
||||
try:
|
||||
self.frames.load(self.file_location)
|
||||
except mutagen.MutagenError:
|
||||
logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"")
|
||||
self.file_location = file_location
|
||||
|
||||
|
||||
def add_song_metadata(self, song: Song):
|
||||
print("adding")
|
||||
for key, value in song.metadata:
|
||||
"""
|
||||
TODO:
|
||||
Implement the adding to the frame thingie of the metadata
|
||||
"""
|
||||
print(key, value)
|
||||
|
||||
def save(self, file_location: str = None):
|
||||
if file_location is not None:
|
||||
@ -27,6 +39,31 @@ class AudioMetadata:
|
||||
raise Exception("no file target provided to save the data to")
|
||||
self.frames.save(filething=self.file_location)
|
||||
|
||||
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._file_location = file_location
|
||||
except mutagen.MutagenError:
|
||||
logger.warning(f"couldn't find any metadata at: \"{self.file_location}\"")
|
||||
|
||||
file_location = property(fget=lambda self: self._file_location, fset=set_file_location)
|
||||
|
||||
|
||||
def write_metadata(song: Song):
|
||||
if not song.target.exists_on_disc:
|
||||
print("afhhkj")
|
||||
return
|
||||
|
||||
id3_object = AudioMetadata(file_location=song.target.file)
|
||||
id3_object.add_song_metadata(song=song)
|
||||
id3_object.save()
|
||||
|
||||
|
||||
def write_many_metadata(song_list: List[Song]):
|
||||
for song in song_list:
|
||||
write_metadata(song=song)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("called directly")
|
||||
|
@ -39,6 +39,7 @@ PATH_LOGGER = logging.getLogger("create-paths")
|
||||
DOWNLOAD_LOGGER = logging.getLogger("download")
|
||||
LYRICS_LOGGER = logging.getLogger("lyrics")
|
||||
GENIUS_LOGGER = logging.getLogger("genius")
|
||||
TAGGING_LOGGER = logging.getLogger("tagging")
|
||||
|
||||
NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea"
|
||||
MUSIC_DIR = os.path.join(os.path.expanduser("~"), "Music")
|
||||
|
Loading…
Reference in New Issue
Block a user