From 98afe5047d05d0c6546ad093d56623f62941896b Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Wed, 15 May 2024 14:21:15 +0200 Subject: [PATCH] fix: wrong creation of source types --- .vscode/settings.json | 1 + music_kraken/download/page_attributes.py | 6 +++--- music_kraken/pages/musify.py | 13 +++++++++++-- music_kraken/pages/youtube_music/youtube_music.py | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a8c503e..bea0c42 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "encyclopaedia", "ENDC", "Gitea", + "iframe", "isrc", "levenshtein", "metallum", diff --git a/music_kraken/download/page_attributes.py b/music_kraken/download/page_attributes.py index c6cf68d..cd047f0 100644 --- a/music_kraken/download/page_attributes.py +++ b/music_kraken/download/page_attributes.py @@ -22,7 +22,7 @@ from ..utils import output, BColors from ..utils.string_processing import fit_to_file_system from ..utils.config import youtube_settings, main_settings from ..utils.path_manager import LOCATIONS -from ..utils.enums import SourceType +from ..utils.enums import SourceType, ALL_SOURCE_TYPES from ..utils.support_classes.download_result import DownloadResult from ..utils.support_classes.query import Query from ..utils.support_classes.download_result import DownloadResult @@ -148,7 +148,7 @@ class Pages: return data_object def fetch_from_url(self, url: str) -> Optional[DataObject]: - source = Source.match_url(url, SourceType.MANUAL) + source = Source.match_url(url, ALL_SOURCE_TYPES.MANUAL) if source is None: return None @@ -317,7 +317,7 @@ class Pages: return r def fetch_url(self, url: str, stop_at_level: int = 2) -> Tuple[Type[Page], DataObject]: - source = Source.match_url(url, SourceType.MANUAL) + source = Source.match_url(url, ALL_SOURCE_TYPES.MANUAL) if source is None: raise UrlNotFoundException(url=url) diff --git a/music_kraken/pages/musify.py b/music_kraken/pages/musify.py index cf612af..54d849a 100644 --- a/music_kraken/pages/musify.py +++ b/music_kraken/pages/musify.py @@ -502,9 +502,18 @@ class Musify(Page): for video_container in video_container_list: iframe_list: List[BeautifulSoup] = video_container.findAll("iframe") for iframe in iframe_list: + """ + the url could look like this + https://www.youtube.com/embed/sNObCkhzOYA?si=dNVgnZMBNVlNb0P_ + """ + parsed_url = urlparse(iframe["src"]) + path_parts = parsed_url.path.strip("/").split("/") + if path_parts[0] != "embed" or len(path_parts) < 2: + continue + source_list.append(Source( - SourceType.YOUTUBE, - iframe["src"], + ALL_SOURCE_TYPES.YOUTUBE, + f"https://music.youtube.com/watch?v={path_parts[1]}", referrer_page=self.SOURCE_TYPE )) diff --git a/music_kraken/pages/youtube_music/youtube_music.py b/music_kraken/pages/youtube_music/youtube_music.py index 2e01805..5d9e55c 100644 --- a/music_kraken/pages/youtube_music/youtube_music.py +++ b/music_kraken/pages/youtube_music/youtube_music.py @@ -620,7 +620,7 @@ class YoutubeMusic(SuperYouTube): Artist( name=name, source_list=[Source( - SourceType.YOUTUBE_MUSIC, + self.SOURCE_TYPE, f"https://music.youtube.com/channel/{ydl_res.get('channel_id', ydl_res.get('uploader_id', ''))}" )] ) for name in artist_names] @@ -641,7 +641,7 @@ class YoutubeMusic(SuperYouTube): artwork=Artwork(*ydl_res.get("thumbnails", [])), main_artist_list=artist_list, source_list=[Source( - SourceType.YOUTUBE_MUSIC, + self.SOURCE_TYPE, f"https://music.youtube.com/watch?v={ydl_res.get('id')}" ), source], )