added fetching of ma lyrics
This commit is contained in:
parent
34baf75d2e
commit
8045476dba
@ -16,11 +16,16 @@ def fetch_artist():
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist, stop_at_level=2)
|
artist: objects.Artist = EncyclopaediaMetallum.fetch_details(artist, stop_at_level=3)
|
||||||
print(artist.options)
|
print(artist.options)
|
||||||
|
|
||||||
|
album: objects.Album
|
||||||
for album in artist.main_album_collection:
|
for album in artist.main_album_collection:
|
||||||
print(album.options)
|
print(album.options)
|
||||||
|
song: objects.Song
|
||||||
|
for song in album.song_collection:
|
||||||
|
for lyrics in song.lyrics_collection:
|
||||||
|
print(lyrics.text)
|
||||||
|
|
||||||
|
|
||||||
def fetch_album():
|
def fetch_album():
|
||||||
|
@ -67,6 +67,9 @@ class FormattedText:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
return self.doc == other.doc
|
return self.doc == other.doc
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.plaintext
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ from ..utils.shared import (
|
|||||||
|
|
||||||
from .abstract import Page
|
from .abstract import Page
|
||||||
from ..objects import (
|
from ..objects import (
|
||||||
DatabaseObject,
|
Lyrics,
|
||||||
Artist,
|
Artist,
|
||||||
Source,
|
Source,
|
||||||
SourcePages,
|
SourcePages,
|
||||||
@ -475,9 +475,14 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
row_list = track_row.find_all(recursive=False)
|
row_list = track_row.find_all(recursive=False)
|
||||||
|
|
||||||
|
source_list: List[Source] = []
|
||||||
|
|
||||||
track_sort_soup = row_list[0]
|
track_sort_soup = row_list[0]
|
||||||
track_sort = int(track_sort_soup.text[:-1])
|
track_sort = int(track_sort_soup.text[:-1])
|
||||||
track_id = track_sort_soup.find("a").get("name")
|
track_id = track_sort_soup.find("a").get("name").strip()
|
||||||
|
|
||||||
|
if track_row.find("a", {"href": f"#{track_id}"}) is not None:
|
||||||
|
source_list.append(Source(cls.SOURCE_TYPE, track_id))
|
||||||
|
|
||||||
title = row_list[1].text.strip()
|
title = row_list[1].text.strip()
|
||||||
|
|
||||||
@ -492,7 +497,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
title=title,
|
title=title,
|
||||||
length=length,
|
length=length,
|
||||||
tracksort=track_sort,
|
tracksort=track_sort,
|
||||||
source_list=[Source(cls.SOURCE_TYPE, track_id)]
|
source_list=source_list
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -579,11 +584,54 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
if stop_at_level > 1:
|
if stop_at_level > 1:
|
||||||
for song in album.song_collection:
|
for song in album.song_collection:
|
||||||
for source in album.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
|
for source in song.source_collection.get_sources_from_page(cls.SOURCE_TYPE):
|
||||||
song.merge(cls._fetch_song_from_source(source=source, stop_at_level=stop_at_level-1))
|
song.merge(cls._fetch_song_from_source(source=source, stop_at_level=stop_at_level-1))
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _fetch_lyrics(cls, song_id: str) -> Optional[Lyrics]:
|
||||||
|
"""
|
||||||
|
function toggleLyrics(songId) {
|
||||||
|
var lyricsRow = $('#song' + songId);
|
||||||
|
lyricsRow.toggle();
|
||||||
|
var lyrics = $('#lyrics_' + songId);
|
||||||
|
if (lyrics.html() == '(loading lyrics...)') {
|
||||||
|
var realId = songId;
|
||||||
|
if(!$.isNumeric(songId.substring(songId.length -1, songId.length))) {
|
||||||
|
realId = songId.substring(0, songId.length -1);
|
||||||
|
}
|
||||||
|
lyrics.load(URL_SITE + "release/ajax-view-lyrics/id/" + realId);
|
||||||
|
}
|
||||||
|
// toggle link
|
||||||
|
var linkLabel = "lyrics";
|
||||||
|
$("#lyricsButton" + songId).text(lyricsRow.css("display") == "none" ? "Show " + linkLabel : "Hide " + linkLabel);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
if song_id is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
endpoint = "https://www.metal-archives.com/release/ajax-view-lyrics/id/{id}".format(id=song_id)
|
||||||
|
|
||||||
|
r = cls.get_request(endpoint)
|
||||||
|
if r is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return Lyrics(
|
||||||
|
text=FormattedText(html=r.text),
|
||||||
|
language=pycountry.languages.get(alpha_2="en"),
|
||||||
|
source_list=[
|
||||||
|
Source(cls.SOURCE_TYPE, endpoint)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song:
|
def _fetch_song_from_source(cls, source: Source, stop_at_level: int = 1) -> Song:
|
||||||
return Song()
|
song_id = source.url
|
||||||
|
|
||||||
|
return Song(
|
||||||
|
lyrics_list=[
|
||||||
|
cls._fetch_lyrics(song_id=song_id)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user