DB adjustments and def update_process

This commit is contained in:
Maximilian Wagner
2023-08-02 19:38:11 +02:00
parent 582332b8f7
commit 0e8d6b9875
4 changed files with 30 additions and 20 deletions

View File

@@ -44,7 +44,7 @@ def process_download(url):
# this throws KeyError when downloading single file
for video in query['entries']:
if check_already_exists(video['id']):
add_to_collection_if_not_added(parent, video['id'])
add_new_video_to_collection(parent, video['id'])
continue
# this throws DownloadError when not downloading playlist
@@ -71,7 +71,7 @@ def process_download(url):
# for every video in their respective tabs
for video in tab['entries']:
if check_already_exists(video['id']):
add_to_collection_if_not_added(parent, video['id'])
add_new_video_to_collection(parent, video['id'])
continue
# there have been cases of duplicate urls or some with '/watch?v=@channel_name'
@@ -112,6 +112,11 @@ def process_download(url):
return
def process_update(url):
return
# checks whether a video is already in db
def check_already_exists(video_id) -> bool:
res = query_db_threaded('SELECT name FROM video WHERE id = :id',
@@ -172,8 +177,7 @@ def download_all(parent=None, ext='mp3'):
relativePath += str(rowid_new) + '\\'
# set the relative path of playlist in recently added entry
query_db_threaded('UPDATE playlist SET folder = :folder WHERE ROWID = :rowid',
{'folder': relativePath, 'rowid': rowid_new})
update_playlist_folder_by_rowid(relativePath, rowid_new)
# set path for new downloads
location = downloads_path() + relativePath
@@ -181,8 +185,7 @@ def download_all(parent=None, ext='mp3'):
# if that subdirectory does not already exist
else:
# set the relative path of playlist in recently added entry
query_db_threaded('UPDATE playlist SET folder = :folder WHERE ROWID = :rowid',
{'folder': relativePath, 'rowid': rowid_new})
update_playlist_folder_by_rowid(relativePath, rowid_new)
# db_add needs to be passed none so the correct folder can be set in collection
rowid_new = None

View File

@@ -55,16 +55,28 @@ def db_add(ext, parent_rowid=None, parent=None):
for i in range(len(titles)):
query_db_threaded('INSERT INTO video(id, name, ext, path) VALUES (:id, :name, :ext, :path)',
{'id': ids[i], 'name': titles[i], 'ext': '.' + ext, 'path': relative_path})
query_db_threaded('INSERT INTO collection(playlist, video) VALUES (:folder, :id)',
{'folder': relative_path, 'id': ids[i]})
add_collection_entry(relative_path, ids[i])
return
def add_to_collection_if_not_added(parent, video_id):
def add_new_video_to_collection(parent, video_id):
exists = query_db_threaded('SELECT * FROM collection WHERE playlist = :folder AND video = :id',
{'folder': parent + '\\', 'id': video_id})
if not len(exists) > 0:
query_db_threaded('INSERT INTO collection(playlist, video) VALUES (:folder, :id)',
{'folder': parent + '\\', 'id': video_id})
add_collection_entry(parent + '\\', video_id)
return
def add_collection_entry(folder, video_id):
query_db_threaded('INSERT INTO collection(playlist, video) VALUES (:folder, :id)',
{'folder': folder, 'id': video_id})
def update_playlist_folder_by_rowid(folder, rowid):
query_db_threaded('UPDATE playlist SET folder = :folder WHERE ROWID = :rowid',
{'folder': folder, 'rowid': rowid})
return

View File

@@ -78,13 +78,13 @@ def download(file_path):
@frontend.route('/update', methods=['GET', 'POST'])
def updater():
downloads = query_db('SELECT name, url FROM updatelist INNER JOIN playlist ON updatelist.ROWID = playlist.ROWID')
downloads = query_db('SELECT name, url FROM playlist')
return render_template('updater.html', downloads=downloads)
@frontend.route('/update/<int:url_rowid>')
def update(url_rowid):
url = query_db('SELECT url FROM updatelist WHERE ROWID = :url_rowid',
url = query_db('SELECT url FROM playlist WHERE ROWID = :url_rowid',
{'url_rowid': url_rowid})[0][0]
# kick off download process

View File

@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS video (
*/
CREATE TABLE IF NOT EXISTS playlist (
folder TEXT PRIMARY KEY,
name TEXT NOT NULL
name TEXT NOT NULL,
url TEXT NOT NULL
);
/*
@@ -42,9 +43,3 @@ CREATE TABLE IF NOT EXISTS collection (
video TEXT NOT NULL
);
/*
- user-input url, only playlists get added
*/
CREATE TABLE IF NOT EXISTS updatelist (
url TEXT PRIMARY KEY NOT NULL
);