From aa50d2cf20dc741ba379caef3de7bdbee5cf595b Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 29 Apr 2024 13:51:43 +0200 Subject: [PATCH] feat: renamed referrer page fixing typo --- music_kraken/objects/source.py | 38 ++++++++++---------- music_kraken/pages/bandcamp.py | 2 +- music_kraken/pages/encyclopaedia_metallum.py | 4 +-- music_kraken/pages/musify.py | 4 +-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/music_kraken/objects/source.py b/music_kraken/objects/source.py index bb2e9e3..64cd433 100644 --- a/music_kraken/objects/source.py +++ b/music_kraken/objects/source.py @@ -4,6 +4,7 @@ from collections import defaultdict from enum import Enum from typing import List, Dict, Set, Tuple, Optional, Iterable from urllib.parse import urlparse +from dataclasses import dataclass from ..utils.enums.source import SourcePages, SourceTypes from ..utils.config import youtube_settings @@ -14,11 +15,12 @@ from .parents import OuterProxy from .collection import Collection + +@dataclass class Source(OuterProxy): url: str - page_enum: SourcePages - referer_page: SourcePages + referrer_page: SourcePages audio_url: str @@ -27,16 +29,16 @@ class Source(OuterProxy): } # This is automatically generated - def __init__(self, page_enum: SourcePages, url: str, referer_page: SourcePages = None, audio_url: str = None, + def __init__(self, page_enum: SourcePages, url: str, referrer_page: SourcePages = None, audio_url: str = None, **kwargs) -> None: - if referer_page is None: - referer_page = page_enum + if referrer_page is None: + referrer_page = page_enum - super().__init__(url=url, page_enum=page_enum, referer_page=referer_page, audio_url=audio_url, **kwargs) + super().__init__(url=url, page_enum=page_enum, referrer_page=referrer_page, audio_url=audio_url, **kwargs) @classmethod - def match_url(cls, url: str, referer_page: SourcePages) -> Optional["Source"]: + def match_url(cls, url: str, referrer_page: SourcePages) -> Optional["Source"]: """ this shouldn't be used, unlesse you are not certain what the source is for the reason is that it is more inefficient @@ -45,38 +47,38 @@ class Source(OuterProxy): url = parsed.geturl() if "musify" in parsed.netloc: - return cls(SourcePages.MUSIFY, url, referer_page=referer_page) + return cls(SourcePages.MUSIFY, url, referrer_page=referrer_page) if parsed.netloc in [_url.netloc for _url in youtube_settings['youtube_url']]: - return cls(SourcePages.YOUTUBE, url, referer_page=referer_page) + return cls(SourcePages.YOUTUBE, url, referrer_page=referrer_page) if url.startswith("https://www.deezer"): - return cls(SourcePages.DEEZER, url, referer_page=referer_page) + return cls(SourcePages.DEEZER, url, referrer_page=referrer_page) if url.startswith("https://open.spotify.com"): - return cls(SourcePages.SPOTIFY, url, referer_page=referer_page) + return cls(SourcePages.SPOTIFY, url, referrer_page=referrer_page) if "bandcamp" in url: - return cls(SourcePages.BANDCAMP, url, referer_page=referer_page) + return cls(SourcePages.BANDCAMP, url, referrer_page=referrer_page) if "wikipedia" in parsed.netloc: - return cls(SourcePages.WIKIPEDIA, url, referer_page=referer_page) + return cls(SourcePages.WIKIPEDIA, url, referrer_page=referrer_page) if url.startswith("https://www.metal-archives.com/"): - return cls(SourcePages.ENCYCLOPAEDIA_METALLUM, url, referer_page=referer_page) + return cls(SourcePages.ENCYCLOPAEDIA_METALLUM, url, referrer_page=referrer_page) # the less important once if url.startswith("https://www.facebook"): - return cls(SourcePages.FACEBOOK, url, referer_page=referer_page) + return cls(SourcePages.FACEBOOK, url, referrer_page=referrer_page) if url.startswith("https://www.instagram"): - return cls(SourcePages.INSTAGRAM, url, referer_page=referer_page) + return cls(SourcePages.INSTAGRAM, url, referrer_page=referrer_page) if url.startswith("https://twitter"): - return cls(SourcePages.TWITTER, url, referer_page=referer_page) + return cls(SourcePages.TWITTER, url, referrer_page=referrer_page) if url.startswith("https://myspace.com"): - return cls(SourcePages.MYSPACE, url, referer_page=referer_page) + return cls(SourcePages.MYSPACE, url, referrer_page=referrer_page) def get_song_metadata(self) -> Metadata: return Metadata({ diff --git a/music_kraken/pages/bandcamp.py b/music_kraken/pages/bandcamp.py index 90064db..dcfebbf 100644 --- a/music_kraken/pages/bandcamp.py +++ b/music_kraken/pages/bandcamp.py @@ -185,7 +185,7 @@ class Bandcamp(Page): if li is None and li['href'] is not None: continue - source_list.append(Source.match_url(_parse_artist_url(li['href']), referer_page=self.SOURCE_TYPE)) + source_list.append(Source.match_url(_parse_artist_url(li['href']), referrer_page=self.SOURCE_TYPE)) return Artist( name=name, diff --git a/music_kraken/pages/encyclopaedia_metallum.py b/music_kraken/pages/encyclopaedia_metallum.py index d9ce0ca..dba4527 100644 --- a/music_kraken/pages/encyclopaedia_metallum.py +++ b/music_kraken/pages/encyclopaedia_metallum.py @@ -486,7 +486,7 @@ class EncyclopaediaMetallum(Page): href = anchor["href"] if href is not None: - source_list.append(Source.match_url(href, referer_page=self.SOURCE_TYPE)) + source_list.append(Source.match_url(href, referrer_page=self.SOURCE_TYPE)) # The following code is only legacy code, which I just kep because it doesn't harm. # The way ma returns sources changed. @@ -504,7 +504,7 @@ class EncyclopaediaMetallum(Page): if url is None: continue - source_list.append(Source.match_url(url, referer_page=self.SOURCE_TYPE)) + source_list.append(Source.match_url(url, referrer_page=self.SOURCE_TYPE)) return source_list diff --git a/music_kraken/pages/musify.py b/music_kraken/pages/musify.py index 28ac0a9..0e99f75 100644 --- a/music_kraken/pages/musify.py +++ b/music_kraken/pages/musify.py @@ -503,7 +503,7 @@ class Musify(Page): source_list.append(Source( SourcePages.YOUTUBE, iframe["src"], - referer_page=self.SOURCE_TYPE + referrer_page=self.SOURCE_TYPE )) return Song( @@ -812,7 +812,7 @@ class Musify(Page): href = additional_source.get("href") if href is None: continue - new_src = Source.match_url(href, referer_page=self.SOURCE_TYPE) + new_src = Source.match_url(href, referrer_page=self.SOURCE_TYPE) if new_src is None: continue source_list.append(new_src)