From 58c58b2141babc4f2afbe73ed58d7d608dfc0963 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 13:35:00 +0200 Subject: [PATCH] made the referer in sources more concistent --- src/music_kraken/objects/source.py | 26 +++++++++---------- .../pages/encyclopaedia_metallum.py | 2 +- src/music_kraken/pages/musify.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/music_kraken/objects/source.py b/src/music_kraken/objects/source.py index 25b17ad..85a8755 100644 --- a/src/music_kraken/objects/source.py +++ b/src/music_kraken/objects/source.py @@ -30,7 +30,7 @@ class Source(DatabaseObject): page_enum: SourcePages, url: str, id_: str = None, - referer_page: SourceTypes = None, + referer_page: SourcePages = None, adio_url: str = None ) -> None: DatabaseObject.__init__(self, id_=id_) @@ -42,7 +42,7 @@ class Source(DatabaseObject): self.audio_url = adio_url @classmethod - def match_url(cls, url: str) -> Optional["Source"]: + def match_url(cls, url: str, referer_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 @@ -51,38 +51,38 @@ class Source(DatabaseObject): url = parsed.geturl() if "musify" in parsed.netloc: - return cls(SourcePages.MUSIFY, url) + return cls(SourcePages.MUSIFY, url, referer_page=referer_page) if url.startswith("https://www.youtube"): - return cls(SourcePages.YOUTUBE, url) + return cls(SourcePages.YOUTUBE, url, referer_page=referer_page) if url.startswith("https://www.deezer"): - return cls(SourcePages.DEEZER, url) + return cls(SourcePages.DEEZER, url, referer_page=referer_page) if url.startswith("https://open.spotify.com"): - return cls(SourcePages.SPOTIFY, url) + return cls(SourcePages.SPOTIFY, url, referer_page=referer_page) if "bandcamp" in url: - return cls(SourcePages.BANDCAMP, url) + return cls(SourcePages.BANDCAMP, url, referer_page=referer_page) if "wikipedia" in parsed.netloc: - return cls(SourcePages.WIKIPEDIA, url) + return cls(SourcePages.WIKIPEDIA, url, referer_page=referer_page) if url.startswith("https://www.metal-archives.com/"): - return cls(SourcePages.ENCYCLOPAEDIA_METALLUM, url) + return cls(SourcePages.ENCYCLOPAEDIA_METALLUM, url, referer_page=referer_page) # the less important once if url.startswith("https://www.facebook"): - return cls(SourcePages.FACEBOOK, url) + return cls(SourcePages.FACEBOOK, url, referer_page=referer_page) if url.startswith("https://www.instagram"): - return cls(SourcePages.INSTAGRAM, url) + return cls(SourcePages.INSTAGRAM, url, referer_page=referer_page) if url.startswith("https://twitter"): - return cls(SourcePages.TWITTER, url) + return cls(SourcePages.TWITTER, url, referer_page=referer_page) if url.startswith("https://myspace.com"): - return cls(SourcePages.MYSPACE, url) + return cls(SourcePages.MYSPACE, url, referer_page=referer_page) def get_song_metadata(self) -> Metadata: return Metadata({ diff --git a/src/music_kraken/pages/encyclopaedia_metallum.py b/src/music_kraken/pages/encyclopaedia_metallum.py index 1bd90b8..70d2ffb 100644 --- a/src/music_kraken/pages/encyclopaedia_metallum.py +++ b/src/music_kraken/pages/encyclopaedia_metallum.py @@ -285,7 +285,7 @@ class EncyclopaediaMetallum(Page): if url is None: continue - source_list.append(Source.match_url(url)) + source_list.append(Source.match_url(url, referer_page=cls.SOURCE_TYPE)) return source_list diff --git a/src/music_kraken/pages/musify.py b/src/music_kraken/pages/musify.py index 3dab3a9..6ce3b71 100644 --- a/src/music_kraken/pages/musify.py +++ b/src/music_kraken/pages/musify.py @@ -681,7 +681,7 @@ class Musify(Page): href = additional_source.get("href") if href is None: continue - new_src = Source.match_url(href) + new_src = Source.match_url(href, referer_page=cls.SOURCE_TYPE) if new_src is None: continue source_list.append(new_src)