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:
|
def get_db(db_type: str) -> db.Database:
|
||||||
db_settings = self.config.session["database"]
|
db_settings = self.config.session["database"]
|
||||||
db_class = db.CLASS_MAP[db_type]
|
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"] and db_settings.get("enabled", True):
|
||||||
if db_settings[db_type]["enabled"]:
|
default_db_path = DB_PATH_MAP[db_type]
|
||||||
path = db_settings[db_type]["path"]
|
path = db_settings[db_type]["path"]
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
|
@ -123,6 +122,8 @@ class MusicDL(list):
|
||||||
assert config is not None
|
assert config is not None
|
||||||
config.file["database"][db_type]["path"] = default_db_path
|
config.file["database"][db_type]["path"] = default_db_path
|
||||||
config.save()
|
config.save()
|
||||||
|
else:
|
||||||
|
database = db_class(None, dummy=True)
|
||||||
|
|
||||||
return database
|
return database
|
||||||
|
|
||||||
|
@ -163,7 +164,7 @@ class MusicDL(list):
|
||||||
raise ParsingError(message)
|
raise ParsingError(message)
|
||||||
|
|
||||||
for source, url_type, item_id in parsed:
|
for source, url_type, item_id in parsed:
|
||||||
if {"id": item_id} in self.db:
|
if item_id in self.db:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"ID {item_id} already downloaded, use --no-db to override."
|
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"]
|
source_subdirs = self.config.session["downloads"]["source_subdirectories"]
|
||||||
for item in self:
|
for item in self:
|
||||||
|
# Item already checked in database in handle_urls
|
||||||
if source_subdirs:
|
if source_subdirs:
|
||||||
arguments["parent_folder"] = self.__get_source_subdir(
|
arguments["parent_folder"] = self.__get_source_subdir(
|
||||||
item.client.source
|
item.client.source
|
||||||
|
@ -285,7 +287,7 @@ class MusicDL(list):
|
||||||
arguments["filters"] = filters_
|
arguments["filters"] = filters_
|
||||||
logger.debug("Added filter argument for artist/label: %s", 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")
|
logger.debug("Loading metadata")
|
||||||
try:
|
try:
|
||||||
item.load_meta(**arguments)
|
item.load_meta(**arguments)
|
||||||
|
@ -296,20 +298,25 @@ class MusicDL(list):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
item.download(**arguments)
|
item.download(**arguments)
|
||||||
|
for item_id in item.downloaded_ids:
|
||||||
|
self.db.add([item_id])
|
||||||
except NonStreamable as e:
|
except NonStreamable as e:
|
||||||
e.print(item)
|
e.print(item)
|
||||||
self.failed_db.add((item.client.source, item.type, item.id))
|
self.failed_db.add((item.client.source, item.type, item.id))
|
||||||
continue
|
continue
|
||||||
except PartialFailure as e:
|
except PartialFailure as e:
|
||||||
for failed_item in e.failed_items:
|
# add successful downloads to database?
|
||||||
self.failed_db.add(failed_item)
|
for failed_item_info in e.failed_items:
|
||||||
|
self.failed_db.add(failed_item_info)
|
||||||
continue
|
continue
|
||||||
except ItemExists as e:
|
except ItemExists as e:
|
||||||
click.secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
click.secho(f'"{e!s}" already exists. Skipping.', fg="yellow")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if hasattr(item, "id"):
|
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):
|
if isinstance(item, Track):
|
||||||
item.tag()
|
item.tag()
|
||||||
|
@ -560,7 +567,7 @@ 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:
|
if item_id := str(item["id"]) in self.db:
|
||||||
click.secho(
|
click.secho(
|
||||||
f"ID {item_id} already logged in database. Skipping.",
|
f"ID {item_id} already logged in database. Skipping.",
|
||||||
fg="magenta",
|
fg="magenta",
|
||||||
|
|
14
rip/db.py
14
rip/db.py
|
@ -3,7 +3,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import List
|
from typing import Tuple, Union
|
||||||
|
|
||||||
logger = logging.getLogger("streamrip")
|
logger = logging.getLogger("streamrip")
|
||||||
|
|
||||||
|
@ -84,15 +84,23 @@ class Database:
|
||||||
|
|
||||||
raise TypeError(keys)
|
raise TypeError(keys)
|
||||||
|
|
||||||
def add(self, items: List[str]):
|
def add(self, items: Union[str, Tuple[str]]):
|
||||||
"""Add a row to the table.
|
"""Add a row to the table.
|
||||||
|
|
||||||
:param items: Column-name + value. Values must be provided for all cols.
|
:param items: Column-name + value. Values must be provided for all cols.
|
||||||
:type items: List[str]
|
:type items: Tuple[str]
|
||||||
"""
|
"""
|
||||||
if self.is_dummy:
|
if self.is_dummy:
|
||||||
return
|
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)
|
assert len(items) == len(self.structure)
|
||||||
|
|
||||||
params = ", ".join(self.structure.keys())
|
params = ", ".join(self.structure.keys())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue