...
This commit is contained in:
parent
a99f794174
commit
696de60249
21
src/goof.py
21
src/goof.py
@ -1,19 +1,12 @@
|
||||
import music_kraken as mk
|
||||
print(mk.__file__)
|
||||
|
||||
"""
|
||||
from music_kraken.audio_source import (
|
||||
fetch_sources,
|
||||
fetch_audios
|
||||
)
|
||||
print(fetch_sources)
|
||||
song_list = mk.cache.get_custom_track([])
|
||||
|
||||
from music_kraken.database import (
|
||||
cache
|
||||
)
|
||||
"""
|
||||
print(mk.cache, len(song_list))
|
||||
print(song_list)
|
||||
|
||||
print(mk.cache, len(mk.cache.get_tracks_without_src()))
|
||||
|
||||
mk.fetch_sources(mk.cache.get_tracks_without_src(), skip_existing_files=False)
|
||||
mk.fetch_audios(mk.cache.get_tracks_to_download(), override_existing=True)
|
||||
for song in song_list:
|
||||
print()
|
||||
print(song)
|
||||
print(song.json_data)
|
||||
|
@ -4,7 +4,8 @@ from . import (
|
||||
artist,
|
||||
metadata,
|
||||
source,
|
||||
target
|
||||
target,
|
||||
lyrics
|
||||
)
|
||||
|
||||
Song = song.Song
|
||||
@ -12,5 +13,6 @@ Artist = artist.Artist
|
||||
Source = source.Source
|
||||
Target = target.Target
|
||||
Metadata = metadata.Metadata
|
||||
Lyrics = lyrics.Lyrics
|
||||
|
||||
cache = temp_database.TempDatabase()
|
||||
|
@ -1,7 +1,4 @@
|
||||
class Lyrics:
|
||||
def __init__(self, text: str = None, language: str = None) -> None:
|
||||
def __init__(self, text: str, language: str) -> None:
|
||||
self.text = text
|
||||
self.language = language
|
||||
|
||||
def set_lyrics(self, text: str, language: str):
|
||||
pass
|
||||
|
@ -47,6 +47,9 @@ class Song:
|
||||
def __str__(self) -> str:
|
||||
return f"\"{self.title}\" by {', '.join([str(a) for a in self.artists])}"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.__str__()
|
||||
|
||||
def get_metadata(self):
|
||||
return self.metadata.get_all_metadata()
|
||||
|
||||
|
@ -3,6 +3,9 @@ from typing import List
|
||||
from bs4 import BeautifulSoup
|
||||
import pycountry
|
||||
|
||||
from ..database import (
|
||||
Lyrics
|
||||
)
|
||||
from ..utils.shared import *
|
||||
from ..utils import phonetic_compares
|
||||
from ..utils.object_handeling import get_elem_from_obj
|
||||
@ -133,39 +136,6 @@ def search(artist: str, track: str) -> list:
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
"""
|
||||
song = Song(
|
||||
{'highlights': [], 'index': 'song', 'type': 'song',
|
||||
'result': {'_type': 'song', 'annotation_count': 0, 'api_path': '/songs/6142483',
|
||||
'artist_names': 'Psychonaut 4',
|
||||
'full_title': 'Sana Sana Sana, Cura Cura Cura by\xa0Psychonaut\xa04',
|
||||
'header_image_thumbnail_url': 'https://images.genius.com/f9f67a3f9c801f697fbaf68c7efd3599.300x300x1.jpg',
|
||||
'header_image_url': 'https://images.genius.com/f9f67a3f9c801f697fbaf68c7efd3599.651x651x1.jpg',
|
||||
'id': 6142483, 'instrumental': False, 'language': 'en', 'lyrics_owner_id': 4443216,
|
||||
'lyrics_state': 'complete', 'lyrics_updated_at': 1604698709,
|
||||
'path': '/Psychonaut-4-sana-sana-sana-cura-cura-cura-lyrics', 'pyongs_count': None,
|
||||
'relationships_index_url': 'https://genius.com/Psychonaut-4-sana-sana-sana-cura-cura-cura-sample',
|
||||
'release_date_components': {'year': 2020, 'month': 7, 'day': 1},
|
||||
'release_date_for_display': 'July 1, 2020',
|
||||
'release_date_with_abbreviated_month_for_display': 'Jul. 1, 2020',
|
||||
'song_art_image_thumbnail_url': 'https://images.genius.com/f9f67a3f9c801f697fbaf68c7efd3599.300x300x1.jpg',
|
||||
'song_art_image_url': 'https://images.genius.com/f9f67a3f9c801f697fbaf68c7efd3599.651x651x1.jpg',
|
||||
'stats': {'unreviewed_annotations': 0, 'hot': False}, 'title': 'Sana Sana Sana, Cura Cura Cura',
|
||||
'title_with_featured': 'Sana Sana Sana, Cura Cura Cura', 'updated_by_human_at': 1647353214,
|
||||
'url': 'https://genius.com/Psychonaut-4-sana-sana-sana-cura-cura-cura-lyrics',
|
||||
'featured_artists': [], 'primary_artist': {'_type': 'artist', 'api_path': '/artists/1108956',
|
||||
'header_image_url': 'https://images.genius.com/ff13efc74a043237cfca3fc0a6cb12dd.1000x563x1.jpg',
|
||||
'id': 1108956,
|
||||
'image_url': 'https://images.genius.com/25ff7cfdcb6d92a9f19ebe394a895736.640x640x1.jpg',
|
||||
'index_character': 'p', 'is_meme_verified': False,
|
||||
'is_verified': False, 'name': 'Psychonaut 4',
|
||||
'slug': 'Psychonaut-4',
|
||||
'url': 'https://genius.com/artists/Psychonaut-4'}}},
|
||||
{'artist': 'Psychonaut 4', 'track': 'Sana Sana Sana, Cura Cura Cura'}
|
||||
)
|
||||
print(song.fetch_lyrics())
|
||||
"""
|
||||
|
||||
songs = search("Zombiez", "WALL OF Z")
|
||||
for song in songs:
|
||||
print(song)
|
||||
|
@ -3,8 +3,10 @@ from mutagen.id3 import ID3, USLT
|
||||
|
||||
from ..utils.shared import *
|
||||
from . import genius
|
||||
|
||||
from ..database.temp_database import temp_database
|
||||
from ..database import (
|
||||
Song,
|
||||
cache
|
||||
)
|
||||
|
||||
logger = LYRICS_LOGGER
|
||||
|
||||
@ -32,8 +34,7 @@ I have written that Rhythmbox plugin: https://github.com/HeIIow2/rythmbox-id3-ly
|
||||
# https://code.activestate.com/recipes/577138-embed-lyrics-into-mp3-files-using-mutagen-uslt-tag/
|
||||
|
||||
|
||||
def add_lyrics(file_name, lyrics):
|
||||
file_path = os.path.join(MUSIC_DIR, file_name)
|
||||
def add_lyrics(file_path: str, lyrics):
|
||||
if not os.path.exists(file_path):
|
||||
return
|
||||
|
||||
@ -49,46 +50,20 @@ def add_lyrics(file_name, lyrics):
|
||||
tags.save(file_path)
|
||||
|
||||
|
||||
def fetch_single_lyrics(row: dict):
|
||||
artists = [artist['name'] for artist in row['artists']]
|
||||
track = row['title']
|
||||
id_ = row['id']
|
||||
|
||||
logger.info(f"try fetching lyrics for \"{track}\" by \"{', '.join(artists)}")
|
||||
def fetch_single_lyrics(song: Song):
|
||||
logger.info(f"try fetching lyrics for {song}")
|
||||
|
||||
lyrics = []
|
||||
for artist in artists:
|
||||
lyrics.extend(genius.search(artist, track))
|
||||
for artist in song.get_artist_names():
|
||||
lyrics.extend(genius.search(artist, song.title))
|
||||
if len(lyrics) == 0:
|
||||
return
|
||||
|
||||
logger.info("found lyrics")
|
||||
temp_database.add_lyrics(id_, lyrics=lyrics[0])
|
||||
add_lyrics(row['file'], lyrics[0])
|
||||
cache.add_lyrics(song.id, lyrics=lyrics[0])
|
||||
add_lyrics(song.target.file, lyrics[0])
|
||||
|
||||
|
||||
def fetch_lyrics():
|
||||
for row in temp_database.get_tracks_for_lyrics():
|
||||
fetch_single_lyrics(row)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
temp_folder = "music-downloader"
|
||||
temp_dir = os.path.join(tempfile.gettempdir(), temp_folder)
|
||||
if not os.path.exists(temp_dir):
|
||||
os.mkdir(temp_dir)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
db_logger = logging.getLogger("database")
|
||||
db_logger.setLevel(logging.DEBUG)
|
||||
|
||||
database = db.Database(os.path.join(temp_dir, "metadata.db"),
|
||||
os.path.join(temp_dir, "database_structure.sql"),
|
||||
"https://raw.githubusercontent.com/HeIIow2/music-downloader/new_metadata/assets/database_structure.sql",
|
||||
db_logger,
|
||||
reset_anyways=False)
|
||||
|
||||
fetch_lyrics()
|
||||
for song in cache.get_tracks_for_lyrics():
|
||||
fetch_single_lyrics(song)
|
||||
|
Loading…
Reference in New Issue
Block a user