From 08339bab68d07ebbd86126ac1863844e31c1d590 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 23 May 2023 10:25:12 +0200 Subject: [PATCH] query function --- src/music_kraken/pages/abstract.py | 4 +-- .../support_classes/__init__.py | 0 .../support_classes/default_target.py | 0 .../support_classes/download_result.py | 0 .../utils/support_classes/query.py | 28 +++++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) rename src/music_kraken/{pages => utils}/support_classes/__init__.py (100%) rename src/music_kraken/{pages => utils}/support_classes/default_target.py (100%) rename src/music_kraken/{pages => utils}/support_classes/download_result.py (100%) create mode 100644 src/music_kraken/utils/support_classes/query.py diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index afe6e24..0d69604 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -7,8 +7,8 @@ import requests from bs4 import BeautifulSoup from ..connection import Connection -from .support_classes.default_target import DefaultTarget -from .support_classes.download_result import DownloadResult +from ..utils.support_classes.default_target import DefaultTarget +from ..utils.support_classes.download_result import DownloadResult from ..objects import ( Song, Source, diff --git a/src/music_kraken/pages/support_classes/__init__.py b/src/music_kraken/utils/support_classes/__init__.py similarity index 100% rename from src/music_kraken/pages/support_classes/__init__.py rename to src/music_kraken/utils/support_classes/__init__.py diff --git a/src/music_kraken/pages/support_classes/default_target.py b/src/music_kraken/utils/support_classes/default_target.py similarity index 100% rename from src/music_kraken/pages/support_classes/default_target.py rename to src/music_kraken/utils/support_classes/default_target.py diff --git a/src/music_kraken/pages/support_classes/download_result.py b/src/music_kraken/utils/support_classes/download_result.py similarity index 100% rename from src/music_kraken/pages/support_classes/download_result.py rename to src/music_kraken/utils/support_classes/download_result.py diff --git a/src/music_kraken/utils/support_classes/query.py b/src/music_kraken/utils/support_classes/query.py new file mode 100644 index 0000000..dd492d6 --- /dev/null +++ b/src/music_kraken/utils/support_classes/query.py @@ -0,0 +1,28 @@ +from typing import Optional, List + +from ...objects import DatabaseObject, Artist, Album, Song + +class Query: + def __init__( + self, + raw_query: str = "", + music_object: DatabaseObject = None + ) -> None: + self.raw_query: str = raw_query + self.music_object: Optional[DatabaseObject] = None + + @property + def default_search(self) -> List[str]: + if self.music_object is None: + return [self.raw_query] + + if isinstance(self.music_object, Artist): + return [self.music_object.name] + + if isinstance(self.music_object, Song): + return [f"{artist.name} - {self.music_object}" for artist in self.music_object.main_artist_collection] + + if isinstance(self.music_object, Album): + return [f"{artist.name} - {self.music_object}" for artist in self.music_object.artist_collection] + + return [self.raw_query]