Skip to content

Commit 42e5468

Browse files
committedSep 20, 2020
add database connection path and folder
Folder needed for docker so that the volume can be mounted and persistent across installations
1 parent e5e966a commit 42e5468

9 files changed

+50
-31
lines changed
 

‎.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ flask_session
55
youtube-dl-server-database.db
66
.vscode
77
README.md
8-
docker-compose.yml
8+
docker-compose.yml
9+
db/*

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__pycache__
22
flask_session
3+
db/*
34
youtube-dl-server-database.db
45
.vscode

‎Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ FROM ubuntu:20.04
33
# Folder we're keeping the app in
44
WORKDIR /app
55
# Where videos download by default
6-
VOLUME ./downloads
6+
VOLUME /app/downloads
77
# It is a very good idea to put this somewhere else
8-
VOLUME ./youtube-dl-server-database.db
8+
VOLUME /app/db
99

1010
# To prevent tzdata ruining the build process
1111
ENV TZ=Australia/Melbourne

‎app.py

+29-23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
import urllib.parse as URLLIB_PARSE
44
import werkzeug.security as WZS
55

6+
from config import DATABASE_PATH
7+
68
#make a connection to the database
7-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
9+
# DATABASE_PATH = os.path.join('db' + os.sep + 'youtube-dl-server-database.db')
10+
# LEGACY DATABASE_PATH
11+
#DATABASE_PATH = ('./youtube-dl-server-database.db')
12+
13+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
814
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
915

1016
#the default directory for the videos to be downloaded to
@@ -36,7 +42,7 @@ def WEB_INDEX():
3642
listOfProxies = []
3743

3844
#connect to the database
39-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
45+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
4046
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
4147

4248
#get the list of proxies from the database
@@ -140,7 +146,7 @@ def WEB_QUEUE():
140146
return flask.render_template('error2.html', applicationName = GET_APP_TITLE(), error = 'General error downloading the video. This site/format is probably not supported. Try using bestvideo/bestaudio if you are sure that this site is supported.')
141147

142148
#the database connection
143-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
149+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
144150

145151
#the database cursor
146152
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
@@ -217,7 +223,7 @@ def WEB_HISTORY():
217223
#this code can also be repurposed with an option to refresh the webpage or have it only load once
218224
'''
219225
#the database connection
220-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
226+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
221227
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
222228
223229
#get the history data
@@ -259,7 +265,7 @@ def WEB_HISTORY_JSON():
259265
if (isUserLoggedIn(flask.session)):
260266

261267
#connect to the database
262-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
268+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
263269
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
264270

265271
#get the data about the download history
@@ -287,7 +293,7 @@ def WEB_HISTORYCLR():
287293
#check that they are an admin
288294

289295
#connect to the database
290-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
296+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
291297
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
292298

293299
#get the data for the current user to make sure that they are an admin
@@ -321,7 +327,7 @@ def WEB_HISTORYCLR():
321327
def WEB_LOGIN():
322328

323329
#connect to the database
324-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
330+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
325331
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
326332

327333
#get the amount of login keys
@@ -336,7 +342,7 @@ def WEB_LOGIN():
336342
def WEB_REGISTER():
337343

338344
#connect to the database
339-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
345+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
340346
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
341347

342348
#get the amount of login keys
@@ -395,7 +401,7 @@ def WEB_AUTH():
395401
alwaysSamePath = '/'.join(referringURLPath)
396402

397403
#initialize a connection with the database
398-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
404+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
399405

400406
#giant try catch just in case
401407
try:
@@ -443,7 +449,7 @@ def WEB_ADDUSER():
443449
if (isUserLoggedIn(flask.session)):
444450

445451
#connect to the database
446-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
452+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
447453
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
448454

449455
#get the data for the current user to make sure that they are an admin
@@ -503,7 +509,7 @@ def WEB_REGNEWUSER():
503509
newUserRegistrationKey = flask.request.form.get('registration_key')
504510

505511
#connect to the database
506-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
512+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
507513
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
508514

509515
#check if the registration key is in the database
@@ -550,7 +556,7 @@ def WEB_DELETEUSER():
550556
if (isUserLoggedIn(flask.session)):
551557

552558
#connect to the database
553-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
559+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
554560
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
555561

556562
#get the data for the current user to make sure that they are an admin
@@ -600,7 +606,7 @@ def WEB_MAKEREGKEY():
600606
if (isUserLoggedIn(flask.session)):
601607

602608
#connect to the database
603-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
609+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
604610
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
605611

606612
#get the data for the current user to make sure that they are an admin
@@ -642,7 +648,7 @@ def WEB_DELETEREGKEY():
642648
if (isUserLoggedIn(flask.session)):
643649

644650
#connect to the database
645-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
651+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
646652
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
647653

648654
#get the data for the current user to make sure that they are an admin
@@ -685,7 +691,7 @@ def WEB_SUBSCRIPTIONS():
685691
#get the subscription data from the database (lines below)
686692

687693
#connect to the database
688-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
694+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
689695
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
690696

691697
#get all the data from the subscriptions table (its fine to dump it all, no sensitive data is here)
@@ -733,7 +739,7 @@ def WEB_MANAGESUBSCRIPTION():
733739
#add the subscription to the subscription table (the code below)
734740

735741
#create the database connection
736-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
742+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
737743
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
738744

739745
#the list of "downloaded" videos
@@ -775,7 +781,7 @@ def WEB_MANAGESUBSCRIPTION():
775781
FORM_ID = str(flask.request.form.get('subscription_id'))
776782

777783
#delete the entry with the matching id in the subscriptions table
778-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
784+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
779785
DATABASE_CONNECTION.execute('DELETE FROM subscriptions WHERE subscription_id = ?', (FORM_ID,))
780786
DATABASE_CONNECTION.commit()
781787

@@ -802,7 +808,7 @@ def WEB_ADMIN():
802808
if (isUserLoggedIn(flask.session)):
803809

804810
#connect to the database
805-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
811+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
806812
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
807813

808814
#get the data for the current user to make sure that they are an admin
@@ -869,7 +875,7 @@ def WEB_ADMINACTION():
869875
if (isUserLoggedIn(flask.session)):
870876

871877
#connect to the database
872-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
878+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
873879
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
874880

875881
#get the form data
@@ -968,7 +974,7 @@ def isUserLoggedIn(userSession) -> bool:
968974
PASSWORD = userSession['LOGGED_IN_ACCOUNT_DATA'][1]
969975

970976
#connect to the database
971-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
977+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
972978
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
973979

974980
#try to get the users password that is in the database
@@ -1134,7 +1140,7 @@ def downloadVideo(videoURL, videoFormat, parentDownloadDir = DEFAULT_VIDEO_DOWNL
11341140
def GET_APP_TITLE() -> str:
11351141

11361142
#connect to the database
1137-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
1143+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
11381144
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
11391145

11401146
#get the app title
@@ -1147,7 +1153,7 @@ def GET_APP_TITLE() -> str:
11471153
def GET_DL_DIRS(get_default = False) -> list:
11481154

11491155
#connect to the database
1150-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
1156+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
11511157
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
11521158

11531159
#get the list of directories that can be downloaded to
@@ -1184,7 +1190,7 @@ def YTDL_POLLER():
11841190
while (1):
11851191

11861192
#initialize a connection with the database
1187-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
1193+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
11881194
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
11891195

11901196
#get the queue for the videos (the ones where the status is 1 (pending download))

‎config.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
DATABASE_PATH = os.path.join('db' + os.sep + 'youtube-dl-server-database.db')
3+
# LEGACY DATABASE_PATH
4+
#DATABASE_PATH = ('./youtube-dl-server-database.db')

‎docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
# Where downloaded videos should go
1313
- /opt/youtubedownloads:/app/downloads
1414
# Where the database is
15-
- /opt/database:/app/youtube-dl-server-database.db
15+
- /opt/database:/app/db
1616
environment:
1717
- APPNAME=YDL
1818
- ADMINUSER=admin

‎edit-user-password.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
import sqlite3, getpass
55
import werkzeug.security as WZS
66

7+
from config import DATABASE_PATH
8+
79
#connect to the database
8-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
10+
11+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
912
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
1013

1114
#get the account that they want to change the password for

‎setup.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import werkzeug.security as WZS
44
import argparse
55

6+
from config import DATABASE_PATH
7+
68
parser = argparse.ArgumentParser()
79
parser.add_argument("--appname", type=str, help="name for the application")
810
parser.add_argument("--username", type=str, help="username for the admin account")
911
parser.add_argument("--password", type=str, help="password for the admin account")
1012

1113
#check if there is already a database
12-
if (os.path.exists('./youtube-dl-server-database.db')):
14+
if (os.path.exists(DATABASE_PATH)):
1315

1416
#tell the user that there is a database, then exit. the user will then do what they need to do with the old database.
1517
print('There already is an existing database! Please move the old database to another directory, or if you are trying to use the old database again, rename it to "youtube-dl-server-database.db.old", then run the setup program again, and then replace the new database with the old database. Please keep in mind that importing a database from an older version of the program can lead to errors, if its not converted properly!')
@@ -45,7 +47,7 @@
4547
exit()
4648

4749
#create the database
48-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
50+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
4951

5052
#make the users table
5153
DATABASE_CONNECTION.execute('''

‎subscription-daemon.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#import statements
44
import flask, youtube_dl, sqlite3, json, time, os
55

6+
from config import DATABASE_PATH
7+
68
#make a connection to the database
7-
DATABASE_CONNECTION = sqlite3.connect('./youtube-dl-server-database.db')
9+
DATABASE_CONNECTION = sqlite3.connect(DATABASE_PATH)
810
DATABASE_CURSOR = DATABASE_CONNECTION.cursor()
911

1012
#select the data from the subscriptions table

0 commit comments

Comments
 (0)
Please sign in to comment.