Fix compatibility with new databases

Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
nathom 2021-07-03 13:48:29 -07:00
parent 2f3f425687
commit 97318017e0

View file

@ -43,7 +43,7 @@ from streamrip.constants import (
URL_REGEX, URL_REGEX,
YOUTUBE_URL_REGEX, YOUTUBE_URL_REGEX,
) )
from .db import MusicDB from . import db
from streamrip.exceptions import ( from streamrip.exceptions import (
AuthenticationError, AuthenticationError,
MissingCredentials, MissingCredentials,
@ -106,18 +106,18 @@ class MusicDL(list):
"soundcloud": SoundCloudClient(), "soundcloud": SoundCloudClient(),
} }
self.db: MusicDB self.db: db.Database
db_settings = self.config.session["database"] db_settings = self.config.session["database"]
if db_settings["enabled"]: if db_settings["enabled"]:
path = db_settings["path"] path = db_settings["path"]
if path: if path:
self.db = MusicDB(path) self.db = db.Downloads(path)
else: else:
self.db = MusicDB(DB_PATH) self.db = db.Downloads(DB_PATH)
self.config.file["database"]["path"] = DB_PATH self.config.file["database"]["path"] = DB_PATH
self.config.save() self.config.save()
else: else:
self.db = MusicDB(None, empty=True) self.db = db.Downloads(None, empty=True)
def handle_urls(self, urls): def handle_urls(self, urls):
"""Download a url. """Download a url.
@ -153,7 +153,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 item_id in self.db: if {"id": 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."
) )
@ -262,7 +262,7 @@ class MusicDL(list):
continue continue
if item.download(**arguments) and hasattr(item, "id"): if item.download(**arguments) and hasattr(item, "id"):
self.db.add(item.id) self.db.add([item.id])
if isinstance(item, Track): if isinstance(item, Track):
item.tag() item.tag()