mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-14 15:15:06 -04:00
Fix database issues
Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
parent
16c8976e27
commit
07d0df382b
2 changed files with 27 additions and 12 deletions
25
rip/core.py
25
rip/core.py
|
@ -109,10 +109,9 @@ class MusicDL(list):
|
|||
def get_db(db_type: str) -> db.Database:
|
||||
db_settings = self.config.session["database"]
|
||||
db_class = db.CLASS_MAP[db_type]
|
||||
database = db_class(None, dummy=True)
|
||||
|
||||
default_db_path = DB_PATH_MAP[db_type]
|
||||
if db_settings[db_type]["enabled"]:
|
||||
if db_settings[db_type]["enabled"] and db_settings.get("enabled", True):
|
||||
default_db_path = DB_PATH_MAP[db_type]
|
||||
path = db_settings[db_type]["path"]
|
||||
|
||||
if path:
|
||||
|
@ -123,6 +122,8 @@ class MusicDL(list):
|
|||
assert config is not None
|
||||
config.file["database"][db_type]["path"] = default_db_path
|
||||
config.save()
|
||||
else:
|
||||
database = db_class(None, dummy=True)
|
||||
|
||||
return database
|
||||
|
||||
|
@ -163,7 +164,7 @@ class MusicDL(list):
|
|||
raise ParsingError(message)
|
||||
|
||||
for source, url_type, item_id in parsed:
|
||||
if {"id": item_id} in self.db:
|
||||
if item_id in self.db:
|
||||
logger.info(
|
||||
f"ID {item_id} already downloaded, use --no-db to override."
|
||||
)
|
||||
|
@ -268,6 +269,7 @@ class MusicDL(list):
|
|||
|
||||
source_subdirs = self.config.session["downloads"]["source_subdirectories"]
|
||||
for item in self:
|
||||
# Item already checked in database in handle_urls
|
||||
if source_subdirs:
|
||||
arguments["parent_folder"] = self.__get_source_subdir(
|
||||
item.client.source
|
||||
|
@ -285,7 +287,7 @@ class MusicDL(list):
|
|||
arguments["filters"] = filters_
|
||||
logger.debug("Added filter argument for artist/label: %s", filters_)
|
||||
|
||||
if not (isinstance(item, Tracklist) and item.loaded):
|
||||
if not isinstance(item, Tracklist) or not item.loaded:
|
||||
logger.debug("Loading metadata")
|
||||
try:
|
||||
item.load_meta(**arguments)
|
||||
|
@ -296,20 +298,25 @@ class MusicDL(list):
|
|||
|
||||
try:
|
||||
item.download(**arguments)
|
||||
for item_id in item.downloaded_ids:
|
||||
self.db.add([item_id])
|
||||
except NonStreamable as e:
|
||||
e.print(item)
|
||||
self.failed_db.add((item.client.source, item.type, item.id))
|
||||
continue
|
||||
except PartialFailure as e:
|
||||
for failed_item in e.failed_items:
|
||||
self.failed_db.add(failed_item)
|
||||
# add successful downloads to database?
|
||||
for failed_item_info in e.failed_items:
|
||||
self.failed_db.add(failed_item_info)
|
||||
continue
|
||||
except ItemExists as e:
|
||||
click.secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
||||
continue
|
||||
|
||||
if hasattr(item, "id"):
|
||||
self.db.add([item.id])
|
||||
self.db.add(item.id)
|
||||
for item_id in item.downloaded_ids:
|
||||
self.db.add(item_id)
|
||||
|
||||
if isinstance(item, Track):
|
||||
item.tag()
|
||||
|
@ -560,7 +567,7 @@ class MusicDL(list):
|
|||
else page["albums"]["items"]
|
||||
)
|
||||
for i, item in enumerate(tracklist):
|
||||
if item_id := item["id"] in self.db:
|
||||
if item_id := str(item["id"]) in self.db:
|
||||
click.secho(
|
||||
f"ID {item_id} already logged in database. Skipping.",
|
||||
fg="magenta",
|
||||
|
|
14
rip/db.py
14
rip/db.py
|
@ -3,7 +3,7 @@
|
|||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
from typing import List
|
||||
from typing import Tuple, Union
|
||||
|
||||
logger = logging.getLogger("streamrip")
|
||||
|
||||
|
@ -84,15 +84,23 @@ class Database:
|
|||
|
||||
raise TypeError(keys)
|
||||
|
||||
def add(self, items: List[str]):
|
||||
def add(self, items: Union[str, Tuple[str]]):
|
||||
"""Add a row to the table.
|
||||
|
||||
:param items: Column-name + value. Values must be provided for all cols.
|
||||
:type items: List[str]
|
||||
:type items: Tuple[str]
|
||||
"""
|
||||
if self.is_dummy:
|
||||
return
|
||||
|
||||
if isinstance(items, str) and len(self.structure) == 1:
|
||||
items = [items]
|
||||
else:
|
||||
raise TypeError(
|
||||
"Only tables with 1 column can have string inputs. Use a list "
|
||||
"where len(list) == len(structure)."
|
||||
)
|
||||
|
||||
assert len(items) == len(self.structure)
|
||||
|
||||
params = ", ".join(self.structure.keys())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue