Compare commits
2 Commits
5d26fdbf94
...
feature/mu
Author | SHA1 | Date | |
---|---|---|---|
265c9f462f | |||
780daac0ef |
@@ -30,7 +30,7 @@ from ..utils.exception import MKMissingNameException
|
||||
from ..utils.exception.download import UrlNotFoundException
|
||||
from ..utils.shared import DEBUG_PAGES
|
||||
|
||||
from ..pages import Page, EncyclopaediaMetallum, Musify, YouTube, YoutubeMusic, Bandcamp, Genius, INDEPENDENT_DB_OBJECTS
|
||||
from ..pages import Page, EncyclopaediaMetallum, Musify, YouTube, YoutubeMusic, Bandcamp, Musicbrainz, Genius, INDEPENDENT_DB_OBJECTS
|
||||
|
||||
|
||||
ALL_PAGES: Set[Type[Page]] = {
|
||||
@@ -38,7 +38,8 @@ ALL_PAGES: Set[Type[Page]] = {
|
||||
Genius,
|
||||
Musify,
|
||||
YoutubeMusic,
|
||||
Bandcamp
|
||||
Bandcamp,
|
||||
Musicbrainz
|
||||
}
|
||||
|
||||
if youtube_settings["use_youtube_alongside_youtube_music"]:
|
||||
|
@@ -477,8 +477,6 @@ class Artist(Base):
|
||||
general_genre: str
|
||||
unformatted_location: str
|
||||
|
||||
artwork: List[Artwork]
|
||||
|
||||
source_collection: SourceCollection
|
||||
contact_collection: Collection[Contact]
|
||||
|
||||
@@ -495,8 +493,6 @@ class Artist(Base):
|
||||
"lyrical_themes": list,
|
||||
"general_genre": lambda: "",
|
||||
|
||||
"artwork": list,
|
||||
|
||||
"source_collection": SourceCollection,
|
||||
"album_collection": Collection,
|
||||
"contact_collection": Collection,
|
||||
@@ -515,7 +511,6 @@ class Artist(Base):
|
||||
notes: FormattedText = None,
|
||||
lyrical_themes: List[str] = None,
|
||||
general_genre: str = None,
|
||||
artwork: List[Artwork] = None,
|
||||
unformatted_location: str = None,
|
||||
source_list: List[Source] = None,
|
||||
contact_list: List[Contact] = None,
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from .encyclopaedia_metallum import EncyclopaediaMetallum
|
||||
from .musify import Musify
|
||||
from .musicbrainz import Musicbrainz
|
||||
from .youtube import YouTube
|
||||
from .youtube_music import YoutubeMusic
|
||||
from .bandcamp import Bandcamp
|
||||
|
145
music_kraken/pages/musicbrainz.py
Normal file
145
music_kraken/pages/musicbrainz.py
Normal file
@@ -0,0 +1,145 @@
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import List, Optional, Type, Union, Generator, Dict, Any
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import pycountry
|
||||
import musicbrainzngs
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from ..connection import Connection
|
||||
from .abstract import Page
|
||||
from ..utils.enums import SourceType, ALL_SOURCE_TYPES
|
||||
from ..utils.enums.album import AlbumType, AlbumStatus
|
||||
from ..objects import (
|
||||
Artist,
|
||||
Source,
|
||||
Song,
|
||||
Album,
|
||||
ID3Timestamp,
|
||||
FormattedText,
|
||||
Label,
|
||||
Target,
|
||||
DatabaseObject,
|
||||
Lyrics,
|
||||
Artwork
|
||||
)
|
||||
from ..utils.config import logging_settings, main_settings
|
||||
from ..utils import string_processing, shared
|
||||
from ..utils.string_processing import clean_song_title
|
||||
from ..utils.support_classes.query import Query
|
||||
from ..utils.support_classes.download_result import DownloadResult
|
||||
|
||||
|
||||
|
||||
class Musicbrainz(Page):
|
||||
SOURCE_TYPE = ALL_SOURCE_TYPES.MUSICBRAINZ
|
||||
|
||||
HOST = "https://musicbrainz.org"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
musicbrainzngs.set_useragent("mk", "1")
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def general_search(self, search_query: str) -> List[DatabaseObject]:
|
||||
search_results = []
|
||||
|
||||
#Artist
|
||||
search_results += self.artist_search(search_query).copy()
|
||||
|
||||
#Album
|
||||
search_results += self.album_search(search_query).copy()
|
||||
|
||||
#Song
|
||||
search_results += self.song_search(search_query).copy()
|
||||
|
||||
return search_results
|
||||
|
||||
def artist_search(self, search_query: str) -> List[Artist]:
|
||||
artist_list = []
|
||||
|
||||
#Artist
|
||||
artist_dict_list: list = musicbrainzngs.search_artists(search_query)['artist-list']
|
||||
artist_source_list: List[Source] = []
|
||||
for artist_dict in artist_dict_list:
|
||||
artist_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/artist/" + artist_dict['id']))
|
||||
artist_list.append(Artist(
|
||||
name=artist_dict['name'],
|
||||
source_list=artist_source_list
|
||||
))
|
||||
|
||||
return artist_list
|
||||
|
||||
def song_search(self, search_query: str) -> List[Song]:
|
||||
song_list = []
|
||||
|
||||
#Song
|
||||
song_dict_list: list = musicbrainzngs.search_recordings(search_query)['recording-list']
|
||||
song_source_list: List[Source] = []
|
||||
for song_dict in song_dict_list:
|
||||
song_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/recording/" + song_dict['id']))
|
||||
song_list.append(Song(
|
||||
title=song_dict['title'],
|
||||
source_list=song_source_list
|
||||
))
|
||||
|
||||
return song_list
|
||||
|
||||
def album_search(self, search_query: str) -> List[Album]:
|
||||
album_list = []
|
||||
|
||||
#Album
|
||||
album_dict_list: list = musicbrainzngs.search_release_groups(search_query)['release-group-list']
|
||||
album_source_list: List[Source] = []
|
||||
for album_dict in album_dict_list:
|
||||
album_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/release-group/" + album_dict['id']))
|
||||
album_list.append(Album(
|
||||
title=album_dict['title'],
|
||||
source_list=album_source_list
|
||||
))
|
||||
|
||||
return album_list
|
||||
|
||||
|
||||
def fetch_album(self, source: Source, stop_at_level: int = 1) -> Album:
|
||||
album_list = []
|
||||
|
||||
#Album
|
||||
album_dict_list: list = musicbrainzngs.search_release_groups(search_query)['release-group-list']
|
||||
album_source_list: List[Source] = []
|
||||
for album_dict in album_dict_list:
|
||||
album_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/release-group/" + album_dict['id']))
|
||||
album_list.append(Album(
|
||||
title=album_dict['title'],
|
||||
source_list=album_source_list
|
||||
))
|
||||
|
||||
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
|
||||
artist_list = []
|
||||
|
||||
#Artist
|
||||
artist_dict_list: list = musicbrainzngs.search_artists(search_query)['artist-list']
|
||||
artist_source_list: List[Source] = []
|
||||
for artist_dict in artist_dict_list:
|
||||
artist_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/artist/" + artist_dict['id']))
|
||||
artist_list.append(Artist(
|
||||
name=artist_dict['name'],
|
||||
source_list=artist_source_list,
|
||||
))
|
||||
|
||||
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
|
||||
song_list = []
|
||||
|
||||
#Song
|
||||
song_dict_list: list = musicbrainzngs.search_recordings(search_query)['recording-list']
|
||||
song_source_list: List[Source] = []
|
||||
for song_dict in song_dict_list:
|
||||
song_source_list.append(Source(self.SOURCE_TYPE, self.HOST + "/recording/" + song_dict['id']))
|
||||
song_list.append(Song(
|
||||
title=song_dict['title'],
|
||||
source_list=song_source_list
|
||||
))
|
||||
|
||||
|
@@ -457,17 +457,17 @@ class Musify(Page):
|
||||
for album_info in soup.find_all("ul", {"class": "album-info"}):
|
||||
list_element: BeautifulSoup = album_info.find("li")
|
||||
|
||||
if list_element is not None:
|
||||
artist_soup: BeautifulSoup
|
||||
for artist_soup in list_element.find_all("a"):
|
||||
artist_source_list = []
|
||||
href = artist_soup["href"]
|
||||
if href is not None:
|
||||
artist_source_list = [Source(self.SOURCE_TYPE, self.HOST + href)]
|
||||
artist_list.append(Artist(
|
||||
name=artist_soup.text.strip(),
|
||||
source_list=artist_source_list
|
||||
))
|
||||
if list_element is not None:
|
||||
artist_soup: BeautifulSoup
|
||||
for artist_soup in list_element.find_all("a"):
|
||||
artist_source_list = []
|
||||
href = artist_soup["href"]
|
||||
if href is not None:
|
||||
artist_source_list = [Source(self.SOURCE_TYPE, self.HOST + href)]
|
||||
artist_list.append(Artist(
|
||||
name=artist_soup.text.strip(),
|
||||
source_list=artist_source_list
|
||||
))
|
||||
|
||||
# breadcrums
|
||||
breadcrumb_list_element_list: List[BeautifulSoup] = soup.find_all("ol", {"class": "breadcrumb"})
|
||||
@@ -485,7 +485,7 @@ class Musify(Page):
|
||||
|
||||
track_name = list_points[4].text.strip()
|
||||
|
||||
# album artwork
|
||||
# artwork
|
||||
artwork: Artwork = Artwork()
|
||||
album_image_element_list: List[BeautifulSoup] = soup.find_all("img", {"class": "album-img"})
|
||||
for album_image_element in album_image_element_list:
|
||||
@@ -918,8 +918,7 @@ class Musify(Page):
|
||||
name=name,
|
||||
country=country,
|
||||
source_list=source_list,
|
||||
notes=notes,
|
||||
artwork=self._fetch_artist_artwork(soup, **kwargs)
|
||||
notes=notes
|
||||
)
|
||||
|
||||
def _parse_album_card(self, album_card: BeautifulSoup, artist_name: str = None, **kwargs) -> Album:
|
||||
@@ -1057,20 +1056,6 @@ class Musify(Page):
|
||||
|
||||
artist.album_collection.append(album)
|
||||
|
||||
def _fetch_artist_artwork(self, soup: BeautifulSoup, **kwargs):
|
||||
# artist artwork
|
||||
artist_artwork: List[Artwork] = Artwork()
|
||||
artist_a_element_list: List[BeautifulSoup] = soup.find_all("a")
|
||||
for artist_a_element in artist_a_element_list:
|
||||
if artist_a_element.find_all("img", {"class": "artist-img"}).count() > 0:
|
||||
artwork_gallery = self.connection.get(artist_a_element("data-src", artist_a_element.get("href")))
|
||||
if artwork_gallery is not None:
|
||||
gallery_image_element_list: List[BeautifulSoup] = artwork_gallery.find_all("img", {"class": "artist-img"})
|
||||
for gallery_image_element in gallery_image_element_list:
|
||||
artist_artwork.push(Artwork(url=gallery_image_element.get("data-src", gallery_image_element.get("src"))))
|
||||
|
||||
return artist_artwork
|
||||
|
||||
def fetch_artist(self, source: Source, **kwargs) -> Artist:
|
||||
"""
|
||||
TODO
|
||||
@@ -1083,7 +1068,7 @@ class Musify(Page):
|
||||
|
||||
artist = self._fetch_initial_artist(url, source=source, **kwargs)
|
||||
self._fetch_artist_discography(artist, url, artist.name, **kwargs)
|
||||
self._fetch_artist_artwork(artist, **kwargs)
|
||||
|
||||
return artist
|
||||
|
||||
def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label:
|
||||
|
@@ -59,6 +59,11 @@ Reference for the logging formats: https://docs.python.org/3/library/logging.htm
|
||||
description="The logger for the musify scraper.",
|
||||
default_value="musify"
|
||||
),
|
||||
LoggerAttribute(
|
||||
name="musicbrainz_logger",
|
||||
description="The logger for the musicbrainz scraper.",
|
||||
default_value="musicbrainz"
|
||||
),
|
||||
LoggerAttribute(
|
||||
name="youtube_logger",
|
||||
description="The logger for the youtube scraper.",
|
||||
|
Reference in New Issue
Block a user