diff --git a/backend/app.js b/backend/app.js index 0c08a84..d616e57 100644 --- a/backend/app.js +++ b/backend/app.js @@ -19,7 +19,7 @@ var subscriptions_api = require('./subscriptions') var app = express(); const FileSync = require('lowdb/adapters/FileSync') -const adapter = new FileSync('db.json'); +const adapter = new FileSync('./appdata/db.json'); const db = low(adapter) // Set some defaults @@ -41,7 +41,6 @@ var usingEncryption = null; var basePath = null; var audioFolderPath = null; var videoFolderPath = null; -var useYoutubeDLArchive = null; var downloadOnlyMode = null; var useDefaultDownloadingAgent = null; var customDownloadingAgent = null; @@ -140,7 +139,6 @@ async function loadConfig() { usingEncryption = config_api.getConfigItem('ytdl_use_encryption'); audioFolderPath = config_api.getConfigItem('ytdl_audio_folder_path'); videoFolderPath = config_api.getConfigItem('ytdl_video_folder_path'); - useYoutubeDLArchive = config_api.getConfigItem('ytdl_use_youtubedl_archive'); downloadOnlyMode = config_api.getConfigItem('ytdl_download_only_mode'); useDefaultDownloadingAgent = config_api.getConfigItem('ytdl_use_default_downloading_agent'); customDownloadingAgent = config_api.getConfigItem('ytdl_custom_downloading_agent'); @@ -414,6 +412,7 @@ async function deleteAudioFile(name, blacklistMode = false) { } } + let useYoutubeDLArchive = config_api.getConfigItem('ytdl_use_youtubedl_archive'); if (useYoutubeDLArchive) { const archive_path = audioFolderPath + 'archive.txt'; @@ -424,8 +423,13 @@ async function deleteAudioFile(name, blacklistMode = false) { if (jsonobj) id = jsonobj.id; // use subscriptions API to remove video from the archive file, and write it to the blacklist - const line = id ? subscriptions_api.removeIDFromArchive(archive_path, id) : null; - if (blacklistMode && line) writeToBlacklist('audio', line); + if (fs.existsSync(archive_path)) { + const line = id ? subscriptions_api.removeIDFromArchive(archive_path, id) : null; + if (blacklistMode && line) writeToBlacklist('audio', line); + } else { + console.log('Could not find archive file for audio files. Creating...'); + fs.closeSync(fs.openSync(archive_path, 'w')); + } } if (jsonExists) fs.unlinkSync(jsonPath); @@ -466,6 +470,7 @@ async function deleteVideoFile(name, customPath = null, blacklistMode = false) { } } + let useYoutubeDLArchive = config_api.getConfigItem('ytdl_use_youtubedl_archive'); if (useYoutubeDLArchive) { const archive_path = videoFolderPath + 'archive.txt'; @@ -476,8 +481,13 @@ async function deleteVideoFile(name, customPath = null, blacklistMode = false) { if (jsonobj) id = jsonobj.id; // use subscriptions API to remove video from the archive file, and write it to the blacklist - const line = id ? subscriptions_api.removeIDFromArchive(archive_path, id) : null; - if (blacklistMode && line) writeToBlacklist('video', line); + if (fs.existsSync(archive_path)) { + const line = id ? subscriptions_api.removeIDFromArchive(archive_path, id) : null; + if (blacklistMode && line) writeToBlacklist('video', line); + } else { + console.log('Could not find archive file for videos. Creating...'); + fs.closeSync(fs.openSync(archive_path, 'w')); + } } if (jsonExists) fs.unlinkSync(jsonPath); @@ -671,6 +681,7 @@ app.post('/api/tomp3', async function(req, res) { downloadConfig.splice(0, 0, '--external-downloader', customDownloadingAgent); } + let useYoutubeDLArchive = config_api.getConfigItem('ytdl_use_youtubedl_archive'); if (useYoutubeDLArchive) { let archive_path = audioFolderPath + 'archive.txt'; // create archive file if it doesn't exist @@ -795,6 +806,7 @@ app.post('/api/tomp4', async function(req, res) { downloadConfig.splice(0, 0, '--external-downloader', customDownloadingAgent); } + let useYoutubeDLArchive = config_api.getConfigItem('ytdl_use_youtubedl_archive'); if (useYoutubeDLArchive) { let archive_path = videoFolderPath + 'archive.txt'; // create archive file if it doesn't exist diff --git a/backend/config/default.json b/backend/appdata/default.json similarity index 100% rename from backend/config/default.json rename to backend/appdata/default.json diff --git a/backend/config/encrypted.json b/backend/appdata/encrypted.json similarity index 100% rename from backend/config/encrypted.json rename to backend/appdata/encrypted.json diff --git a/backend/config.js b/backend/config.js index f61d321..fd6d854 100644 --- a/backend/config.js +++ b/backend/config.js @@ -3,7 +3,7 @@ const fs = require('fs'); let CONFIG_ITEMS = require('./consts.js')['CONFIG_ITEMS']; const debugMode = process.env.YTDL_MODE === 'debug'; -let configPath = debugMode ? '../src/assets/default.json' : 'config/default.json'; +let configPath = debugMode ? '../src/assets/default.json' : 'appdata/default.json'; // https://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key Object.byString = function(o, s) { diff --git a/backend/consts.js b/backend/consts.js index 73e4087..767dc0a 100644 --- a/backend/consts.js +++ b/backend/consts.js @@ -1,5 +1,3 @@ -var config = require('config'); - let CONFIG_ITEMS = { // Host 'ytdl_url': { diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 8fa9ce6..d324d74 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -8,7 +8,7 @@ var path = require('path'); var youtubedl = require('youtube-dl'); const config_api = require('./config'); -const adapter = new FileSync('db.json'); +const adapter = new FileSync('./appdata/db.json'); const db = low(adapter) const debugMode = process.env.YTDL_MODE === 'debug'; diff --git a/docker-compose.yml b/docker-compose.yml index 6db5ceb..f03bdea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,35 +4,11 @@ services: ytdl_material: build: . environment: - # config items - ytdl_url: http://localhost:8998 - ytdl_port: '17442' - ytdl_use_encryption: 'false' - ytdl_cert_file_path: /etc/letsencrypt/live/example.com/fullchain.pem - ytdl_key_file_path: /etc/letsencrypt/live/example.com/privkey.pem - ytdl_audio_folder_path: audio/ - ytdl_video_folder_path: video/ - ytdl_custom_args: '' - ytdl_title_top: Youtube Downloader - ytdl_file_manager_enabled: 'true' - ytdl_allow_quality_select: 'true' - ytdl_download_only_mode: 'false' - ytdl_allow_multi_download_mode: 'true' - ytdl_use_youtube_api: 'false' - ytdl_youtube_api_key: 'false' - ytdl_default_theme: default - ytdl_allow_theme_change: 'true' - ytdl_allow_subscriptions: 'true' - ytdl_subscriptions_base_path: subscriptions/ - ytdl_subscriptions_check_interval: '300' - ytdl_subscriptions_use_youtubedl_archive: 'true' - ytdl_use_default_downloading_agent: 'true' - ytdl_custom_downloading_agent: 'false' - ytdl_allow_advanced_download: 'false' - # do not touch this write_ytdl_config: 'true' ALLOW_CONFIG_MUTATIONS: 'true' restart: always + volumes: + - ./appdata:/app/config ports: - "8998:17442" - image: tzahi12345/youtubedl-material:3.4 \ No newline at end of file + image: tzahi12345/youtubedl-material:experimental \ No newline at end of file