DB adjustments and def update_process
This commit is contained in:
15
backend.py
15
backend.py
@@ -44,7 +44,7 @@ def process_download(url):
|
|||||||
# this throws KeyError when downloading single file
|
# this throws KeyError when downloading single file
|
||||||
for video in query['entries']:
|
for video in query['entries']:
|
||||||
if check_already_exists(video['id']):
|
if check_already_exists(video['id']):
|
||||||
add_to_collection_if_not_added(parent, video['id'])
|
add_new_video_to_collection(parent, video['id'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# this throws DownloadError when not downloading playlist
|
# this throws DownloadError when not downloading playlist
|
||||||
@@ -71,7 +71,7 @@ def process_download(url):
|
|||||||
# for every video in their respective tabs
|
# for every video in their respective tabs
|
||||||
for video in tab['entries']:
|
for video in tab['entries']:
|
||||||
if check_already_exists(video['id']):
|
if check_already_exists(video['id']):
|
||||||
add_to_collection_if_not_added(parent, video['id'])
|
add_new_video_to_collection(parent, video['id'])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# there have been cases of duplicate urls or some with '/watch?v=@channel_name'
|
# there have been cases of duplicate urls or some with '/watch?v=@channel_name'
|
||||||
@@ -112,6 +112,11 @@ def process_download(url):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def process_update(url):
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
# checks whether a video is already in db
|
# checks whether a video is already in db
|
||||||
def check_already_exists(video_id) -> bool:
|
def check_already_exists(video_id) -> bool:
|
||||||
res = query_db_threaded('SELECT name FROM video WHERE id = :id',
|
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) + '\\'
|
relativePath += str(rowid_new) + '\\'
|
||||||
|
|
||||||
# set the relative path of playlist in recently added entry
|
# set the relative path of playlist in recently added entry
|
||||||
query_db_threaded('UPDATE playlist SET folder = :folder WHERE ROWID = :rowid',
|
update_playlist_folder_by_rowid(relativePath, rowid_new)
|
||||||
{'folder': relativePath, 'rowid': rowid_new})
|
|
||||||
|
|
||||||
# set path for new downloads
|
# set path for new downloads
|
||||||
location = downloads_path() + relativePath
|
location = downloads_path() + relativePath
|
||||||
@@ -181,8 +185,7 @@ def download_all(parent=None, ext='mp3'):
|
|||||||
# if that subdirectory does not already exist
|
# if that subdirectory does not already exist
|
||||||
else:
|
else:
|
||||||
# set the relative path of playlist in recently added entry
|
# set the relative path of playlist in recently added entry
|
||||||
query_db_threaded('UPDATE playlist SET folder = :folder WHERE ROWID = :rowid',
|
update_playlist_folder_by_rowid(relativePath, rowid_new)
|
||||||
{'folder': relativePath, 'rowid': rowid_new})
|
|
||||||
|
|
||||||
# db_add needs to be passed none so the correct folder can be set in collection
|
# db_add needs to be passed none so the correct folder can be set in collection
|
||||||
rowid_new = None
|
rowid_new = None
|
||||||
|
|||||||
22
db_tools.py
22
db_tools.py
@@ -55,16 +55,28 @@ def db_add(ext, parent_rowid=None, parent=None):
|
|||||||
for i in range(len(titles)):
|
for i in range(len(titles)):
|
||||||
query_db_threaded('INSERT INTO video(id, name, ext, path) VALUES (:id, :name, :ext, :path)',
|
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})
|
{'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
|
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',
|
exists = query_db_threaded('SELECT * FROM collection WHERE playlist = :folder AND video = :id',
|
||||||
{'folder': parent + '\\', 'id': video_id})
|
{'folder': parent + '\\', 'id': video_id})
|
||||||
|
|
||||||
if not len(exists) > 0:
|
if not len(exists) > 0:
|
||||||
query_db_threaded('INSERT INTO collection(playlist, video) VALUES (:folder, :id)',
|
add_collection_entry(parent + '\\', video_id)
|
||||||
{'folder': parent + '\\', 'id': 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
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ def download(file_path):
|
|||||||
|
|
||||||
@frontend.route('/update', methods=['GET', 'POST'])
|
@frontend.route('/update', methods=['GET', 'POST'])
|
||||||
def updater():
|
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)
|
return render_template('updater.html', downloads=downloads)
|
||||||
|
|
||||||
|
|
||||||
@frontend.route('/update/<int:url_rowid>')
|
@frontend.route('/update/<int:url_rowid>')
|
||||||
def update(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]
|
{'url_rowid': url_rowid})[0][0]
|
||||||
|
|
||||||
# kick off download process
|
# kick off download process
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS video (
|
|||||||
*/
|
*/
|
||||||
CREATE TABLE IF NOT EXISTS playlist (
|
CREATE TABLE IF NOT EXISTS playlist (
|
||||||
folder TEXT PRIMARY KEY,
|
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
|
video TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
|
||||||
- user-input url, only playlists get added
|
|
||||||
*/
|
|
||||||
CREATE TABLE IF NOT EXISTS updatelist (
|
|
||||||
url TEXT PRIMARY KEY NOT NULL
|
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user