From db8112064558bdd65e637c5c540392cbb66d90e3 Mon Sep 17 00:00:00 2001 From: Tzahi12345 Date: Fri, 12 Jun 2020 17:57:34 -0400 Subject: [PATCH] Added audioOnlyMode, customArgs, and customFileOutput fields to the subscribe dialog --- backend/app.js | 14 +++++++- backend/db.js | 12 +++++-- backend/subscriptions.js | 1 - .../subscribe-dialog.component.html | 33 +++++++++++++++++-- .../subscribe-dialog.component.ts | 9 ++++- src/app/posts.services.ts | 6 ++-- 6 files changed, 64 insertions(+), 11 deletions(-) diff --git a/backend/app.js b/backend/app.js index f09c78d..d0c1107 100644 --- a/backend/app.js +++ b/backend/app.js @@ -2099,6 +2099,9 @@ app.post('/api/subscribe', optionalJwt, async (req, res) => { let url = req.body.url; let timerange = req.body.timerange; let streamingOnly = req.body.streamingOnly; + let audioOnly = req.body.audioOnly; + let customArgs = req.body.customArgs; + let customOutput = req.body.customOutput; let user_uid = req.isAuthenticated() ? req.user.uid : null; const new_sub = { @@ -2106,7 +2109,8 @@ app.post('/api/subscribe', optionalJwt, async (req, res) => { url: url, id: uuid(), streamingOnly: streamingOnly, - user_uid: user_uid + user_uid: user_uid, + type: audioOnly ? 'audio' : 'video' }; // adds timerange if it exists, otherwise all videos will be downloaded @@ -2114,6 +2118,14 @@ app.post('/api/subscribe', optionalJwt, async (req, res) => { new_sub.timerange = timerange; } + if (customArgs && customArgs !== '') { + sub.custom_args = customArgs; + } + + if (customOutput && customOutput !== '') { + sub.custom_output = customOutput; + } + const result_obj = await subscriptions_api.subscribe(new_sub, user_uid); if (result_obj.success) { diff --git a/backend/db.js b/backend/db.js index 104d343..4bf2ba8 100644 --- a/backend/db.js +++ b/backend/db.js @@ -2,6 +2,7 @@ var fs = require('fs-extra') var path = require('path') var utils = require('./utils') const { uuid } = require('uuidv4'); +const config_api = require('./config'); var logger = null; var db = null; @@ -16,7 +17,7 @@ function initialize(input_db, input_users_db, input_logger) { function registerFileDB(file_path, type, multiUserMode = null, sub = null) { const file_id = file_path.substring(0, file_path.length-4); - const file_object = generateFileObject(file_id, type, multiUserMode && multiUserMode.file_path); + const file_object = generateFileObject(file_id, type, multiUserMode && multiUserMode.file_path, sub); if (!file_object) { logger.error(`Could not find associated JSON file for ${type} file ${file_id}`); return false; @@ -64,7 +65,10 @@ function registerFileDB(file_path, type, multiUserMode = null, sub = null) { return file_object['uid']; } -function generateFileObject(id, type, customPath = null) { +function generateFileObject(id, type, customPath = null, sub = null) { + if (!customPath && sub) { + customPath = getAppendedBasePathSub(sub, config_api.getConfigItem('ytdl_subscriptions_base_path')); + } var jsonobj = (type === 'audio') ? utils.getJSONMp3(id, customPath, true) : utils.getJSONMp4(id, customPath, true); if (!jsonobj) { return null; @@ -89,6 +93,10 @@ function generateFileObject(id, type, customPath = null) { return file_obj; } +function getAppendedBasePathSub(sub, base_path) { + return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name); +} + module.exports = { initialize: initialize, registerFileDB: registerFileDB diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 780b5bb..87d225f 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -31,7 +31,6 @@ async function subscribe(sub, user_uid = null) { return new Promise(async resolve => { // sub should just have url and name. here we will get isPlaylist and path sub.isPlaylist = sub.url.includes('playlist'); - sub.type = 'video'; // TODO: eventually change sub.videos = []; let url_exists = false; diff --git a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html index 8b5abd9..b813f0b 100644 --- a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html +++ b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html @@ -3,16 +3,20 @@
-
+
The playlist or channel URL
+
+
+ +
+
- This is optional
@@ -31,9 +35,32 @@
- Streaming-only mode + Audio-only mode +
+
+
+
+ Streaming-only mode
+
+ + + + These are added after the standard args. + + +
+
+ + + + + Documentation. + Path is relative to the config download path. Don't include extension. + + +
diff --git a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts index 69f9326..c9da7b5 100644 --- a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts +++ b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts @@ -22,6 +22,12 @@ export class SubscribeDialogComponent implements OnInit { // no videos actually downloaded, just streamed streamingOnlyMode = false; + // audio only mode + audioOnlyMode = false; + + customFileOutput = null; + customArgs = null; + time_units = [ 'day', 'week', @@ -49,7 +55,8 @@ export class SubscribeDialogComponent implements OnInit { if (!this.download_all) { timerange = 'now-' + this.timerange_amount.toString() + this.timerange_unit; } - this.postsService.createSubscription(this.url, this.name, timerange, this.streamingOnlyMode).subscribe(res => { + this.postsService.createSubscription(this.url, this.name, timerange, this.streamingOnlyMode, + this.audioOnlyMode, this.customArgs, this.customFileOutput).subscribe(res => { this.subscribing = false; if (res['new_sub']) { this.dialogRef.close(res['new_sub']); diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 1619016..3b68cdc 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -280,9 +280,9 @@ export class PostsService implements CanActivate { return this.http.post(this.path + 'deletePlaylist', {playlistID: playlistID, type: type}, this.httpOptions); } - createSubscription(url, name, timerange = null, streamingOnly = false) { - return this.http.post(this.path + 'subscribe', {url: url, name: name, timerange: timerange, streamingOnly: streamingOnly}, - this.httpOptions); + createSubscription(url, name, timerange = null, streamingOnly = false, audioOnly = false, customArgs = null, customFileOutput = null) { + return this.http.post(this.path + 'subscribe', {url: url, name: name, timerange: timerange, streamingOnly: streamingOnly, + audioOnly: audioOnly, customArgs: customArgs, customFileOutput: customFileOutput}, this.httpOptions); } unsubscribe(sub, deleteMode = false) {