diff --git a/.directory b/.directory
new file mode 100644
index 0000000..de81d98
--- /dev/null
+++ b/.directory
@@ -0,0 +1,6 @@
+[Dolphin]
+Timestamp=2018,11,1,23,18,12
+Version=4
+
+[Settings]
+HiddenFilesShown=true
diff --git a/.gitignore b/.gitignore
index 6fb4095..1817065 100644
--- a/.gitignore
+++ b/.gitignore
@@ -115,7 +115,7 @@ venv.bak/
.dmypy.json
dmypy.json
-media/
+data/
.vscode/*
!.vscode/settings.json
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d73a71e..6e78d19 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,6 +3,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -137,24 +148,31 @@
-
+
+
-
+
+
+
+
-
-
+
+
-
+
+
+
+
@@ -162,45 +180,63 @@
+
+
-
+
+
-
-
+
+
+
-
+
+
-
+
-
+
+
+
-
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -208,6 +244,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -223,7 +286,6 @@
- ajax_index_get_videos
ajax_index_get_tree
self.helper
csrf
@@ -253,6 +315,7 @@
DeleteS
dj_settings
is_true
+ _resolve_section_option
loading
@@ -276,13 +339,6 @@
@@ -336,11 +399,11 @@
true
DEFINITION_ORDER
-
-
-
-
-
+
+
+
+
+
@@ -412,8 +475,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -432,19 +512,19 @@
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
@@ -590,11 +670,11 @@
-
+
-
+
@@ -603,10 +683,10 @@
-
+
-
+
@@ -647,57 +727,8 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -733,13 +764,6 @@
-
-
-
-
-
-
-
@@ -799,35 +823,108 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
diff --git a/Dockerfile b/Dockerfile
index 4f10986..e00ffe9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,26 +1,21 @@
FROM python:3
-WORKDIR /usr/src/app
+WORKDIR /usr/src/ytsm/app
+# ffmpeg is needed for youtube-dl
RUN apt-get update
RUN apt-get install ffmpeg -y
-COPY ./app/requirements.txt ./
+COPY ./requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
-ENV YTSM_DATABASE_ENGINE='django.db.backends.sqlite3'
-ENV YTSM_DATABASE_NAME='/usr/src/app/data/db/ytmanager.db'
-ENV YTSM_DATABASE_HOST=''
-ENV YTSM_DATABASE_USERNAME=''
-ENV YTSM_DATABASE_PASSWORD=''
-ENV YTSM_DATABASE_PORT=''
-ENV YTSM_YOUTUBE_API_KEY='AIzaSyBabzE4Bup77WexdLMa9rN9z-wJidEfNX8'
+ENV YTSM_DEBUG='False'
-VOLUME /usr/src/app/data/media
-VOLUME /usr/src/app/data/db
+VOLUME /usr/src/ytsm/config
+VOLUME /usr/src/ytsm/data
-COPY ./app/ .
-COPY ./config/ ./config/
+COPY ./app/ ./
+COPY ./docker/init.sh ./
EXPOSE 8000
diff --git a/app/YtManager/settings.py b/app/YtManager/settings.py
index 310e72b..637a233 100644
--- a/app/YtManager/settings.py
+++ b/app/YtManager/settings.py
@@ -12,6 +12,7 @@ https://docs.djangoproject.com/en/1.11/ref/settings/
import os
import logging
+from os.path import dirname as up
#
# Basic Django stuff
@@ -119,9 +120,11 @@ LOG_FORMAT = '%(asctime)s|%(process)d|%(thread)d|%(name)s|%(filename)s|%(lineno)
#
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-CONFIG_DIR = os.path.join(BASE_DIR, "config")
-DATA_DIR = os.path.join(BASE_DIR, "data")
+PROJECT_ROOT = up(up(os.path.dirname(__file__))) # Project root
+BASE_DIR = os.path.join(PROJECT_ROOT, "app") # Base dir of the application
+CONFIG_DIR = os.path.join(PROJECT_ROOT, "config")
+DATA_DIR = os.path.join(PROJECT_ROOT, "data")
+STATIC_ROOT = os.path.join(PROJECT_ROOT, "static")
_DEFAULT_CONFIG_FILE = os.path.join(CONFIG_DIR, 'config.ini')
_DEFAULT_LOG_FILE = os.path.join(DATA_DIR, 'log.log')
@@ -160,7 +163,14 @@ def load_config_ini():
import dj_database_url
cfg = ConfigParser(allow_no_value=True, interpolation=ExtendedInterpolatorWithEnv())
- cfg.read([DEFAULTS_FILE, CONFIG_FILE])
+ read_ok = cfg.read([DEFAULTS_FILE, CONFIG_FILE])
+
+ if DEFAULTS_FILE not in read_ok:
+ print('Failed to read file ' + DEFAULTS_FILE)
+ raise Exception('Cannot read file ' + DEFAULTS_FILE)
+ if CONFIG_FILE not in read_ok:
+ print('Failed to read file ' + CONFIG_FILE)
+ raise Exception('Cannot read file ' + CONFIG_FILE)
# Debug
global DEBUG
@@ -183,7 +193,7 @@ def load_config_ini():
}
if cfg.has_option('global', 'DatabaseURL'):
- DATABASES['default'] = dj_database_url.parse(cfg.get('global', 'DatabaseURL'))
+ DATABASES['default'] = dj_database_url.parse(cfg.get('global', 'DatabaseURL'), conn_max_age=600)
else:
DATABASES['default'] = {
diff --git a/app/YtManagerApp/utils/extended_interpolation_with_env.py b/app/YtManagerApp/utils/extended_interpolation_with_env.py
index 2c66022..cef09d4 100644
--- a/app/YtManagerApp/utils/extended_interpolation_with_env.py
+++ b/app/YtManagerApp/utils/extended_interpolation_with_env.py
@@ -35,7 +35,7 @@ class ExtendedInterpolatorWithEnv(Interpolation):
def _resolve_section_option(self, section, option, parser):
if section == 'env':
return os.getenv(option, '')
- return parser.get(section, option, raw=True)
+ return parser.get(section, parser.optionxform(option), raw=True)
def _interpolate_some(self, parser, option, accum, rest, section, map,
depth):
@@ -70,7 +70,7 @@ class ExtendedInterpolatorWithEnv(Interpolation):
v = self._resolve_option(opt, map)
elif len(path) == 2:
sect = path[0]
- opt = parser.optionxform(path[1])
+ opt = path[1]
v = self._resolve_section_option(sect, opt, parser)
else:
raise InterpolationSyntaxError(
diff --git a/app/config b/app/config
deleted file mode 120000
index 30fa1ce..0000000
--- a/app/config
+++ /dev/null
@@ -1 +0,0 @@
-config
\ No newline at end of file
diff --git a/app/init.sh b/app/init.sh
deleted file mode 100755
index e0ede49..0000000
--- a/app/init.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-#./manage.py runserver 0.0.0.0:8000 --noreload
-./manage.py migrate
-gunicorn -b 0.0.0.0:8000 -w 4 YtManager.wsgi
diff --git a/config/config.ini b/config/config.ini
index c3d0f48..7a968c0 100644
--- a/config/config.ini
+++ b/config/config.ini
@@ -1,47 +1,75 @@
-; Use $ to use the value of an environment variable.
+; Use ${env:environment_variable} to use the value of an environment variable.
+; If a variable is not set here, it will be loaded from defaults.ini.
+
; The global section contains settings that apply to the entire server
[global]
+
+Debug=${env:YTSM_DEBUG}
+
+; This is the folder where thumbnails will be downloaded. By default project_root/data/media is used.
+;MediaRoot=
+
+; Secret key - django secret key
+;SecretKey=^zv8@i2h!ko2lo=%ivq(9e#x=%q*i^^)6#4@(juzdx%&0c+9a0
+
; YouTube API key - get this from your user account
-YoutubeApiKey=AIzaSyAonB6T-DrKjfGxBGuHyFMg0x_d0T9nlP8
+;YoutubeApiKey=AIzaSyAonB6T-DrKjfGxBGuHyFMg0x_d0T9nlP8
+
+; Database settings
+; You can use any database engine supported by Django, as long as you add the required dependencies.
+; Built-in engines: https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-DATABASE-ENGINE
+; Others databases might be supported by installing the corect pip package.
+
+;DatabaseEngine=django.db.backends.sqlite3
+;DatabaseName=data/ytmanager.db
+;DatabaseHost=
+;DatabaseUser=
+;DatabasePassword=
+;DatabasePort=
+
+; Database one-liner. If set, it will override any other Database* setting.
+; Documentation: https://github.com/kennethreitz/dj-database-url
+;DatabaseURL=sqlite:////full/path/to/your/database/file.sqlite
+
+; Log settings, sets the log file location and the log level
+;LogLevel=INFO
+;LogFile=data/log.log
; Specifies the synchronization schedule, in crontab format.
; Format:
-SynchronizationSchedule=5 * * * *
+;SynchronizationSchedule=5 * * * *
; Number of threads running the scheduler
; Since most of the jobs scheduled are downloads, there is no advantage to having
; a higher concurrency
-SchedulerConcurrency=1
-
-; Log level
-LogLevel=DEBUG
+;SchedulerConcurrency=1
; Default user settings
[user]
; When a video is deleted on the system, it will be marked as 'watched'
-MarkDeletedAsWatched=True
+;MarkDeletedAsWatched=True
; Videos marked as watched are automatically deleted
-DeleteWatched=True
+;DeleteWatched=True
; Enable automatic downloading
-AutoDownload=True
+;AutoDownload=True
; Limit the total number of videos downloaded (-1 or empty = no limit)
-DownloadGlobalLimit=10
+;DownloadGlobalLimit=10
; Limit the numbers of videos per subscription (-1 or empty = no limit)
-DownloadSubscriptionLimit=5
+;DownloadSubscriptionLimit=5
; Number of download attempts
-DownloadMaxAttempts=3
+;DownloadMaxAttempts=3
; Download order
; Options: newest, oldest, playlist, playlist_reverse, popularity, rating
-DownloadOrder=playlist
+;DownloadOrder=playlist
; Path where downloaded videos are stored
-DownloadPath=data/media/videos
+;DownloadPath=data/media/videos
; A pattern which describes how downloaded files are organized. Extensions are automatically appended.
; Supported fields: channel, channel_id, playlist, playlist_id, playlist_index, title, id
@@ -49,7 +77,7 @@ DownloadPath=data/media/videos
;DownloadFilePattern=${channel}/${playlist}/S01E${playlist_index} - ${title} [${id}]
; Download format that will be passed to youtube-dl. See the youtube-dl documentation for more details.
-DownloadFormat=bestvideo+bestaudio
+;DownloadFormat=bestvideo+bestaudio
; Subtitles - these options match the youtube-dl options
;DownloadSubtitles=True
diff --git a/config/defaults.ini b/config/defaults.ini
index a4a0b30..8735c7e 100644
--- a/config/defaults.ini
+++ b/config/defaults.ini
@@ -1,20 +1,48 @@
-; Use $ to use the value of an environment variable.
+; Use ${env:environment_variable} to use the value of an environment variable.
; The global section contains settings that apply to the entire server
[global]
+
+; Controls whether django debug mode is enabled. Should be false in production.
+Debug=False
+
+; This is the folder where thumbnails will be downloaded. By default project_root/data/media is used.
+;MediaRoot=
+
+; Secret key - django secret key
+SecretKey=^zv8@i2h!ko2lo=%ivq(9e#x=%q*i^^)6#4@(juzdx%&0c+9a0
+
; YouTube API key - get this from your user account
YoutubeApiKey=AIzaSyBabzE4Bup77WexdLMa9rN9z-wJidEfNX8
+; Database settings
+; You can use any database engine supported by Django, as long as you add the required dependencies.
+; Built-in engines: https://docs.djangoproject.com/en/2.1/ref/settings/#std:setting-DATABASE-ENGINE
+; Others databases might be supported by installing the corect pip package.
+
+;DatabaseEngine=django.db.backends.sqlite3
+;DatabaseName=data/ytmanager.db
+;DatabaseHost=
+;DatabaseUser=
+;DatabasePassword=
+;DatabasePort=
+
+; Database one-liner. If set, it will override any other Database* setting.
+; Documentation: https://github.com/kennethreitz/dj-database-url
+;DatabaseURL=sqlite:////full/path/to/your/database/file.sqlite
+
+; Log settings, sets the log file location and the log level
+LogLevel=INFO
+; LogFile=data/log.log
+
; Specifies the synchronization schedule, in crontab format.
; Format:
-SynchronizationSchedule=0 * * * *
+SynchronizationSchedule=5 * * * *
; Number of threads running the scheduler
; Since most of the jobs scheduled are downloads, there is no advantage to having
; a higher concurrency
-SchedulerConcurrency=2
+SchedulerConcurrency=1
-; Log level
-LogLevel=INFO
; Default user settings
[user]
diff --git a/docker-compose.yml b/docker-compose.yml
index c666333..4e1c024 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,7 +4,7 @@ services:
nginx:
image: nginx:latest
volumes:
- - ./nginx:/etc/nginx/conf.d/
+ - ./docker/nginx:/etc/nginx/conf.d/
- ./app/YtManagerApp/static:/www/static
ports:
- "80:80"
@@ -13,11 +13,9 @@ services:
web:
build: .
- env_file:
- - sqlite3.env.env
tty: true
ports:
- "8000:8000"
volumes:
- - ./media:/usr/src/app/data/media
- - ./db:/usr/src/app/data/db
+ - ./config:/usr/src/ytsm/config
+ - ./data:/usr/src/ytsm/data
diff --git a/docker/init.sh b/docker/init.sh
new file mode 100755
index 0000000..f5772be
--- /dev/null
+++ b/docker/init.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+./manage.py migrate
+gunicorn -b 0.0.0.0:8000 -w 1 YtManager.wsgi
diff --git a/nginx/nginx.conf b/docker/nginx/nginx.conf
similarity index 100%
rename from nginx/nginx.conf
rename to docker/nginx/nginx.conf
diff --git a/app/requirements.txt b/requirements.txt
similarity index 100%
rename from app/requirements.txt
rename to requirements.txt
diff --git a/sqlite3.env.env b/sqlite3.env.env
deleted file mode 100644
index adfe8b4..0000000
--- a/sqlite3.env.env
+++ /dev/null
@@ -1,3 +0,0 @@
-YTSM_DATABASE_ENGINE=django.db.backends.sqlite3
-YTSM_DATABASE_NAME=/usr/src/app/data/db/ytmanager.db
-YTSM_YOUTUBE_API_KEY=AIzaSyBabzE4Bup77WexdLMa9rN9z-wJidEfNX8