forked from vitiko98/qobuz-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle duplicate IDs with database (close vitiko98#45) * Prettify the code with f strings * New filename format * Add label tag * Add technical info to the folder for Hi-Res downloads
- Loading branch information
Showing
8 changed files
with
137 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
import sqlite3 | ||
|
||
from qobuz_dl.color import YELLOW, RED | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_db(db_path): | ||
with sqlite3.connect(db_path) as conn: | ||
try: | ||
conn.execute("CREATE TABLE downloads (id TEXT UNIQUE NOT NULL);") | ||
logger.info(f"{YELLOW} Downloads database created") | ||
except sqlite3.OperationalError: | ||
pass | ||
return db_path | ||
|
||
|
||
def handle_download_id(db_path, item_id, add_id=False): | ||
if not db_path: | ||
return | ||
|
||
with sqlite3.connect(db_path) as conn: | ||
# If add_if is False return a string to know if the ID is in the DB | ||
# Otherwise just add the ID to the DB | ||
if add_id: | ||
try: | ||
conn.execute( | ||
"INSERT INTO downloads (id) VALUES (?)", | ||
(item_id,), | ||
) | ||
conn.commit() | ||
except sqlite3.Error as e: | ||
logger.error(f"{RED}Unexpected DB error: {e}") | ||
else: | ||
return conn.execute( | ||
"SELECT id FROM downloads where id=?", | ||
(item_id,), | ||
).fetchone() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.