works again
This commit is contained in:
parent
09fbb57380
commit
01c27efda5
66
src/database_structure.sql
Normal file
66
src/database_structure.sql
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
DROP TABLE IF EXISTS artist;
|
||||||
|
CREATE TABLE artist (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
name TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS artist_release_group;
|
||||||
|
CREATE TABLE artist_release_group (
|
||||||
|
artist_id TEXT NOT NULL,
|
||||||
|
release_group_id TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS artist_track;
|
||||||
|
CREATE TABLE artist_track (
|
||||||
|
artist_id TEXT NOT NULL,
|
||||||
|
track_id TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS release_group;
|
||||||
|
CREATE TABLE release_group (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
albumartist TEXT,
|
||||||
|
albumsort INT,
|
||||||
|
musicbrainz_albumtype TEXT,
|
||||||
|
compilation TEXT,
|
||||||
|
album_artist_id TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS release_;
|
||||||
|
CREATE TABLE release_ (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
release_group_id TEXT NOT NULL,
|
||||||
|
title TEXT,
|
||||||
|
copyright TEXT,
|
||||||
|
album_status TEXT,
|
||||||
|
language TEXT,
|
||||||
|
year TEXT,
|
||||||
|
date TEXT,
|
||||||
|
country TEXT,
|
||||||
|
barcode TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS track;
|
||||||
|
CREATE TABLE track (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
downloaded BOOLEAN NOT NULL DEFAULT 0,
|
||||||
|
release_id TEXT NOT NULL,
|
||||||
|
track TEXT,
|
||||||
|
length INT,
|
||||||
|
tracknumber TEXT,
|
||||||
|
isrc TEXT,
|
||||||
|
genre TEXT,
|
||||||
|
lyrics TEXT,
|
||||||
|
path TEXT,
|
||||||
|
file TEXT,
|
||||||
|
url TEXT,
|
||||||
|
src TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS source;
|
||||||
|
CREATE TABLE source (
|
||||||
|
track_id TEXT NOT NULL,
|
||||||
|
src TEXT NOT NULL,
|
||||||
|
url TEXT NOT NULL,
|
||||||
|
valid BOOLEAN NOT NULL DEFAULT 1
|
||||||
|
);
|
@ -37,7 +37,7 @@ class Download:
|
|||||||
for song in temp_database.get_tracks_to_download():
|
for song in temp_database.get_tracks_to_download():
|
||||||
|
|
||||||
if self.path_stuff(song.target):
|
if self.path_stuff(song.target):
|
||||||
self.write_metadata(song, song.target.file)
|
self.write_metadata(song)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# download_success = Download.download_from_src(song['src'], song)
|
# download_success = Download.download_from_src(song['src'], song)
|
||||||
@ -57,7 +57,7 @@ class Download:
|
|||||||
download_success = youtube.download(song)
|
download_success = youtube.download(song)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.write_metadata(song, song['file'])
|
self.write_metadata(song)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download_from_src(song, src):
|
def download_from_src(song, src):
|
||||||
@ -68,31 +68,28 @@ class Download:
|
|||||||
return source_subclass.fetch_audio(song, src)
|
return source_subclass.fetch_audio(song, src)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def write_metadata(song, file_path):
|
def write_metadata(song: song_objects.Song):
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(song.target.file):
|
||||||
logger.warning(f"file {file_path} doesn't exist")
|
logger.warning(f"file {song.target.file} doesn't exist")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# only convert the file to the proper format if mutagen doesn't work with it due to time
|
# only convert the file to the proper format if mutagen doesn't work with it due to time
|
||||||
try:
|
try:
|
||||||
audiofile = EasyID3(file_path)
|
audiofile = EasyID3(song.target.file)
|
||||||
except mutagen.id3.ID3NoHeaderError:
|
except mutagen.id3.ID3NoHeaderError:
|
||||||
AudioSegment.from_file(file_path).export(file_path, format="mp3")
|
AudioSegment.from_file(song.target.file).export(song.target.file, format="mp3")
|
||||||
audiofile = EasyID3(file_path)
|
audiofile = EasyID3(song.target.file)
|
||||||
|
|
||||||
valid_keys = list(EasyID3.valid_keys.keys())
|
for key, value in song.get_metadata():
|
||||||
|
if type(value) != list:
|
||||||
for key in list(song.keys()):
|
value = str(value)
|
||||||
if key in valid_keys and song[key] is not None:
|
audiofile[key] = value
|
||||||
if type(song[key]) != list:
|
|
||||||
song[key] = str(song[key])
|
|
||||||
audiofile[key] = song[key]
|
|
||||||
|
|
||||||
logger.info("saving")
|
logger.info("saving")
|
||||||
audiofile.save(file_path, v1=2)
|
audiofile.save(song.target.file, v1=2)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def path_stuff(target: song_objects.Target):
|
def path_stuff(target: song_objects.Target) -> bool:
|
||||||
# returns true if it shouldn't be downloaded
|
# returns true if it shouldn't be downloaded
|
||||||
if os.path.exists(target.file):
|
if os.path.exists(target.file):
|
||||||
logger.info(f"'{target.file}' does already exist, thus not downloading.")
|
logger.info(f"'{target.file}' does already exist, thus not downloading.")
|
||||||
|
@ -40,7 +40,7 @@ class Youtube(AudioSource):
|
|||||||
super().fetch_source(song)
|
super().fetch_source(song)
|
||||||
|
|
||||||
if not song.has_isrc():
|
if not song.has_isrc():
|
||||||
return
|
return None
|
||||||
|
|
||||||
real_title = song.title.lower()
|
real_title = song.title.lower()
|
||||||
|
|
||||||
@ -58,7 +58,8 @@ class Youtube(AudioSource):
|
|||||||
final_result = result
|
final_result = result
|
||||||
|
|
||||||
if final_result is None:
|
if final_result is None:
|
||||||
return False
|
return None
|
||||||
|
logger.info(f"found video {final_result}")
|
||||||
return final_result['url']
|
return final_result['url']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -84,6 +85,7 @@ class Youtube(AudioSource):
|
|||||||
logger.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})")
|
logger.warning(f"youtube blocked downloading. ({trie}-{MAX_TRIES})")
|
||||||
if trie >= MAX_TRIES:
|
if trie >= MAX_TRIES:
|
||||||
logger.warning("too many tries, returning")
|
logger.warning("too many tries, returning")
|
||||||
|
return False
|
||||||
logger.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again")
|
logger.warning(f"retrying in {WAIT_BETWEEN_BLOCK} seconds again")
|
||||||
time.sleep(WAIT_BETWEEN_BLOCK)
|
time.sleep(WAIT_BETWEEN_BLOCK)
|
||||||
return cls.fetch_audio(song, src, trie=trie + 1)
|
return cls.fetch_audio(song, src, trie=trie + 1)
|
||||||
|
@ -31,6 +31,7 @@ class Target:
|
|||||||
file = property(fget=get_file, fset=set_file)
|
file = property(fget=get_file, fset=set_file)
|
||||||
path = property(fget=get_path, fset=set_path)
|
path = property(fget=get_path, fset=set_path)
|
||||||
|
|
||||||
|
|
||||||
class Artist:
|
class Artist:
|
||||||
def __init__(self, artist_data) -> None:
|
def __init__(self, artist_data) -> None:
|
||||||
self.artist_data = artist_data
|
self.artist_data = artist_data
|
||||||
@ -41,6 +42,7 @@ class Artist:
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Source:
|
class Source:
|
||||||
def __init__(self, src_data) -> None:
|
def __init__(self, src_data) -> None:
|
||||||
self.src_data = src_data
|
self.src_data = src_data
|
||||||
@ -48,12 +50,13 @@ class Source:
|
|||||||
self.src = self.src_data['src']
|
self.src = self.src_data['src']
|
||||||
self.url = self.src_data['url']
|
self.url = self.src_data['url']
|
||||||
|
|
||||||
|
|
||||||
class Metadata:
|
class Metadata:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
def get_all_metadata(self):
|
def get_all_metadata(self):
|
||||||
pass
|
return list(self.data.items())
|
||||||
|
|
||||||
def __setitem__(self, item, value):
|
def __setitem__(self, item, value):
|
||||||
if item in EasyID3.valid_keys.keys():
|
if item in EasyID3.valid_keys.keys():
|
||||||
@ -88,11 +91,17 @@ class Song:
|
|||||||
|
|
||||||
# initialize id3 metadata
|
# initialize id3 metadata
|
||||||
self.metadata = Metadata()
|
self.metadata = Metadata()
|
||||||
|
for key, value in self.json_data.items():
|
||||||
|
self.metadata[key] = value
|
||||||
|
self.metadata['artist'] = self.get_artist_names()
|
||||||
# EasyID3.valid_keys.keys()
|
# EasyID3.valid_keys.keys()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}"
|
return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}"
|
||||||
|
|
||||||
|
def get_metadata(self):
|
||||||
|
return self.metadata.get_all_metadata()
|
||||||
|
|
||||||
def has_isrc(self) -> bool:
|
def has_isrc(self) -> bool:
|
||||||
return self.isrc is not None
|
return self.isrc is not None
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ from mutagen.id3 import ID3, USLT
|
|||||||
from ..utils.shared import *
|
from ..utils.shared import *
|
||||||
from . import genius
|
from . import genius
|
||||||
|
|
||||||
|
from ..database.temp_database import temp_database
|
||||||
|
|
||||||
logger = LYRICS_LOGGER
|
logger = LYRICS_LOGGER
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -61,12 +63,12 @@ def fetch_single_lyrics(row: dict):
|
|||||||
return
|
return
|
||||||
|
|
||||||
logger.info("found lyrics")
|
logger.info("found lyrics")
|
||||||
database.add_lyrics(id_, lyrics=lyrics[0])
|
temp_database.add_lyrics(id_, lyrics=lyrics[0])
|
||||||
add_lyrics(row['file'], lyrics[0])
|
add_lyrics(row['file'], lyrics[0])
|
||||||
|
|
||||||
|
|
||||||
def fetch_lyrics():
|
def fetch_lyrics():
|
||||||
for row in database.get_tracks_for_lyrics():
|
for row in temp_database.get_tracks_for_lyrics():
|
||||||
fetch_single_lyrics(row)
|
fetch_single_lyrics(row)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,17 +3,6 @@ print(mk.__path__)
|
|||||||
|
|
||||||
# mk.cli()
|
# mk.cli()
|
||||||
|
|
||||||
mk.fetch_source.Download()
|
mk.lyrics.fetch_lyrics()
|
||||||
# db = mk.utils.shared.database
|
# db = mk.utils.shared.database
|
||||||
# if len(db.get_custom_track([])) == 0:
|
# if len(db.get_custom_track([])) == 0:
|
||||||
|
|
||||||
|
|
||||||
mk.target.set_target.UrlPath(genre="test")
|
|
||||||
|
|
||||||
mk.fetch_audio.Download()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
db = mk.utils.shared.database
|
|
||||||
for elem in db.get_custom_track([]):
|
|
||||||
print(elem)
|
|
||||||
print()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user