sucessfully migrated metal archives
This commit is contained in:
parent
e3b1a866a1
commit
9445e95ef9
@ -6,6 +6,7 @@ from typing import Optional, Union, Type, Dict, Set
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from ..connection import Connection
|
||||||
from .support_classes.default_target import DefaultTarget
|
from .support_classes.default_target import DefaultTarget
|
||||||
from .support_classes.download_result import DownloadResult
|
from .support_classes.download_result import DownloadResult
|
||||||
from ..objects import (
|
from ..objects import (
|
||||||
@ -30,6 +31,8 @@ class Page:
|
|||||||
This is an abstract class, laying out the
|
This is an abstract class, laying out the
|
||||||
functionality for every other class fetching something
|
functionality for every other class fetching something
|
||||||
"""
|
"""
|
||||||
|
CONNECTION: Connection
|
||||||
|
|
||||||
API_SESSION: requests.Session = requests.Session()
|
API_SESSION: requests.Session = requests.Session()
|
||||||
API_SESSION.proxies = shared.proxies
|
API_SESSION.proxies = shared.proxies
|
||||||
TIMEOUT = 5
|
TIMEOUT = 5
|
||||||
|
@ -5,6 +5,7 @@ from bs4 import BeautifulSoup
|
|||||||
import pycountry
|
import pycountry
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from ..connection import Connection
|
||||||
from ..utils.shared import ENCYCLOPAEDIA_METALLUM_LOGGER, proxies
|
from ..utils.shared import ENCYCLOPAEDIA_METALLUM_LOGGER, proxies
|
||||||
from ..utils import string_processing
|
from ..utils import string_processing
|
||||||
from .abstract import Page
|
from .abstract import Page
|
||||||
@ -24,12 +25,10 @@ from ..objects import (
|
|||||||
|
|
||||||
|
|
||||||
class EncyclopaediaMetallum(Page):
|
class EncyclopaediaMetallum(Page):
|
||||||
API_SESSION: requests.Session = requests.Session()
|
CONNECTION: Connection = Connection(
|
||||||
API_SESSION.proxies = proxies
|
host="https://www.metal-archives.com/",
|
||||||
API_SESSION.headers = {
|
logger=ENCYCLOPAEDIA_METALLUM_LOGGER
|
||||||
"Host": "www.metal-archives.com",
|
)
|
||||||
"Connection": "keep-alive"
|
|
||||||
}
|
|
||||||
|
|
||||||
SOURCE_TYPE = SourcePages.ENCYCLOPAEDIA_METALLUM
|
SOURCE_TYPE = SourcePages.ENCYCLOPAEDIA_METALLUM
|
||||||
|
|
||||||
@ -70,10 +69,10 @@ class EncyclopaediaMetallum(Page):
|
|||||||
"&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&_" \
|
"&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&_" \
|
||||||
"=1674550595663"
|
"=1674550595663"
|
||||||
|
|
||||||
r = cls.get_request(endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str))
|
r = cls.CONNECTION.get(
|
||||||
if r.status_code != 200:
|
endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str)
|
||||||
cls.LOGGER.warning(
|
)
|
||||||
f"code {r.status_code} at {endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str)}")
|
if r is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return [cls.get_song_from_json(
|
return [cls.get_song_from_json(
|
||||||
@ -92,10 +91,8 @@ class EncyclopaediaMetallum(Page):
|
|||||||
"=&releaseRecordingInfo=&releaseDescription=&releaseNotes=&genre=&sEcho=1&iColumns=3&sColumns" \
|
"=&releaseRecordingInfo=&releaseDescription=&releaseNotes=&genre=&sEcho=1&iColumns=3&sColumns" \
|
||||||
"=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&_=1674563943747"
|
"=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&_=1674563943747"
|
||||||
|
|
||||||
r = cls.get_request(endpoint.format(artist=query.artist_str, album=query.album_str))
|
r = cls.CONNECTION.get(endpoint.format(artist=query.artist_str, album=query.album_str))
|
||||||
if r.status_code != 200:
|
if r is None:
|
||||||
cls.LOGGER.warning(
|
|
||||||
f"code {r.status_code} at {endpoint.format(song=query.song_str, artist=query.artist_str, album=query.album_str)}")
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return [cls.get_album_from_json(
|
return [cls.get_album_from_json(
|
||||||
@ -111,7 +108,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
"=&bandLabelName=&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0" \
|
"=&bandLabelName=&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0" \
|
||||||
"&mDataProp_1=1&mDataProp_2=2&_=1674565459976"
|
"&mDataProp_1=1&mDataProp_2=2&_=1674565459976"
|
||||||
|
|
||||||
r = cls.get_request(endpoint.format(artist=query.artist))
|
r = cls.CONNECTION.get(endpoint.format(artist=query.artist))
|
||||||
|
|
||||||
if r is None:
|
if r is None:
|
||||||
return []
|
return []
|
||||||
@ -134,7 +131,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
"""
|
"""
|
||||||
endpoint = "https://www.metal-archives.com/search/ajax-band-search/?field=name&query={query}&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2"
|
endpoint = "https://www.metal-archives.com/search/ajax-band-search/?field=name&query={query}&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=200&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2"
|
||||||
|
|
||||||
r = cls.get_request(endpoint.format(query=query))
|
r = cls.CONNECTION.get(endpoint.format(query=query))
|
||||||
if r is None:
|
if r is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -220,7 +217,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
discography_url = "https://www.metal-archives.com/band/discography/id/{}/tab/all"
|
discography_url = "https://www.metal-archives.com/band/discography/id/{}/tab/all"
|
||||||
|
|
||||||
# make the request
|
# make the request
|
||||||
r = cls.get_request(discography_url.format(ma_artist_id))
|
r = cls.CONNECTION.get(discography_url.format(ma_artist_id))
|
||||||
if r is None:
|
if r is None:
|
||||||
return []
|
return []
|
||||||
soup = cls.get_soup_from_response(r)
|
soup = cls.get_soup_from_response(r)
|
||||||
@ -257,7 +254,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _fetch_artist_sources(cls, ma_artist_id: str) -> List[Source]:
|
def _fetch_artist_sources(cls, ma_artist_id: str) -> List[Source]:
|
||||||
sources_url = "https://www.metal-archives.com/link/ajax-list/type/band/id/{}"
|
sources_url = "https://www.metal-archives.com/link/ajax-list/type/band/id/{}"
|
||||||
r = cls.get_request(sources_url.format(ma_artist_id))
|
r = cls.CONNECTION.get(sources_url.format(ma_artist_id))
|
||||||
if r is None:
|
if r is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@ -405,7 +402,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _fetch_artist_attributes(cls, url: str) -> Artist:
|
def _fetch_artist_attributes(cls, url: str) -> Artist:
|
||||||
r = cls.get_request(url)
|
r = cls.CONNECTION.get(url)
|
||||||
if r is None:
|
if r is None:
|
||||||
return Artist()
|
return Artist()
|
||||||
soup: BeautifulSoup = cls.get_soup_from_response(r)
|
soup: BeautifulSoup = cls.get_soup_from_response(r)
|
||||||
@ -417,7 +414,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
endpoint = "https://www.metal-archives.com/band/read-more/id/{}"
|
endpoint = "https://www.metal-archives.com/band/read-more/id/{}"
|
||||||
|
|
||||||
# make the request
|
# make the request
|
||||||
r = cls.get_request(endpoint.format(ma_artist_id))
|
r = cls.CONNECTION.get(endpoint.format(ma_artist_id))
|
||||||
if r is None:
|
if r is None:
|
||||||
return FormattedText()
|
return FormattedText()
|
||||||
|
|
||||||
@ -570,7 +567,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
# <table class="display table_lyrics
|
# <table class="display table_lyrics
|
||||||
|
|
||||||
r = cls.get_request(source.url)
|
r = cls.CONNECTION.get(source.url)
|
||||||
if r is None:
|
if r is None:
|
||||||
return Album()
|
return Album()
|
||||||
|
|
||||||
@ -610,7 +607,7 @@ class EncyclopaediaMetallum(Page):
|
|||||||
|
|
||||||
endpoint = "https://www.metal-archives.com/release/ajax-view-lyrics/id/{id}".format(id=song_id)
|
endpoint = "https://www.metal-archives.com/release/ajax-view-lyrics/id/{id}".format(id=song_id)
|
||||||
|
|
||||||
r = cls.get_request(endpoint)
|
r = cls.CONNECTION.get(endpoint)
|
||||||
if r is None:
|
if r is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user