get_album.py 761 B

12345678910111213141516171819202122232425262728293031
  1. from .get_html import get_html
  2. from .type import Album
  3. from .utils import parse_json, remove_brackets
  4. def parse_meta(html):
  5. meta = html.select_one('meta[itemprop="page_data"]')
  6. obj = parse_json(meta["content"])
  7. album = obj.album
  8. tracks = {}
  9. for track in obj.album_appearances:
  10. number = track.track_number
  11. url = track.song.url
  12. tracks[url] = number
  13. return Album(
  14. artist=remove_brackets(album.artist.name),
  15. cover=album.cover_art_url,
  16. id=album.api_path,
  17. release=album.release_date,
  18. title=remove_brackets(album.name),
  19. url=album.url,
  20. track_urls=tracks
  21. )
  22. async def get_album(url: str) -> Album:
  23. html = await get_html(url)
  24. return parse_meta(html)