query function

This commit is contained in:
Hellow2 2023-05-23 10:25:12 +02:00
parent 07e2ef3543
commit 08339bab68
5 changed files with 30 additions and 2 deletions

View File

@ -7,8 +7,8 @@ import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from ..connection import Connection from ..connection import Connection
from .support_classes.default_target import DefaultTarget from ..utils.support_classes.default_target import DefaultTarget
from .support_classes.download_result import DownloadResult from ..utils.support_classes.download_result import DownloadResult
from ..objects import ( from ..objects import (
Song, Song,
Source, Source,

View File

@ -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]