mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-22 11:15:30 -04:00
Check database when searching
Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
parent
2b68b96204
commit
4abe96825f
2 changed files with 25 additions and 3 deletions
17
rip/core.py
17
rip/core.py
|
@ -532,6 +532,7 @@ class MusicDL(list):
|
||||||
source: str,
|
source: str,
|
||||||
query: str,
|
query: str,
|
||||||
media_type: str = "album",
|
media_type: str = "album",
|
||||||
|
check_db: bool = False,
|
||||||
limit: int = 200,
|
limit: int = 200,
|
||||||
) -> Generator:
|
) -> Generator:
|
||||||
"""Universal search.
|
"""Universal search.
|
||||||
|
@ -559,9 +560,17 @@ class MusicDL(list):
|
||||||
else page["albums"]["items"]
|
else page["albums"]["items"]
|
||||||
)
|
)
|
||||||
for i, item in enumerate(tracklist):
|
for i, item in enumerate(tracklist):
|
||||||
|
if item_id := item["id"] in self.db:
|
||||||
|
click.secho(
|
||||||
|
f"ID {item_id} already logged in database. Skipping.",
|
||||||
|
fg="magenta",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
yield MEDIA_CLASS[ # type: ignore
|
yield MEDIA_CLASS[ # type: ignore
|
||||||
media_type if media_type != "featured" else "album"
|
media_type if media_type != "featured" else "album"
|
||||||
].from_api(item, client)
|
].from_api(item, client)
|
||||||
|
|
||||||
if i > limit:
|
if i > limit:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
@ -611,7 +620,11 @@ class MusicDL(list):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def interactive_search(
|
def interactive_search(
|
||||||
self, query: str, source: str = "qobuz", media_type: str = "album"
|
self,
|
||||||
|
query: str,
|
||||||
|
source: str = "qobuz",
|
||||||
|
media_type: str = "album",
|
||||||
|
limit: int = 50,
|
||||||
):
|
):
|
||||||
"""Show an interactive menu that contains search results.
|
"""Show an interactive menu that contains search results.
|
||||||
|
|
||||||
|
@ -622,7 +635,7 @@ class MusicDL(list):
|
||||||
:param media_type:
|
:param media_type:
|
||||||
:type media_type: str
|
:type media_type: str
|
||||||
"""
|
"""
|
||||||
results = tuple(self.search(source, query, media_type, limit=50))
|
results = tuple(self.search(source, query, media_type, limit=limit))
|
||||||
|
|
||||||
def title(res):
|
def title(res):
|
||||||
if isinstance(res[1], Album):
|
if isinstance(res[1], Album):
|
||||||
|
|
11
rip/db.py
11
rip/db.py
|
@ -73,7 +73,16 @@ class Database:
|
||||||
return bool(conn.execute(command, tuple(items.values())).fetchone()[0])
|
return bool(conn.execute(command, tuple(items.values())).fetchone()[0])
|
||||||
|
|
||||||
def __contains__(self, keys: dict) -> bool:
|
def __contains__(self, keys: dict) -> bool:
|
||||||
return self.contains(**keys)
|
if isinstance(keys, dict):
|
||||||
|
return self.contains(**keys)
|
||||||
|
|
||||||
|
if isinstance(keys, str) and len(self.structure) == 1:
|
||||||
|
only_key = tuple(self.structure.keys())[0]
|
||||||
|
query = {only_key: keys}
|
||||||
|
logger.debug("Searching for %s in database", query)
|
||||||
|
return self.contains(**query)
|
||||||
|
|
||||||
|
raise TypeError(keys)
|
||||||
|
|
||||||
def add(self, items: List[str]):
|
def add(self, items: List[str]):
|
||||||
"""Add a row to the table.
|
"""Add a row to the table.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue