From 8938844ffad704bca81fa339467526083e1404bc Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sat, 28 Nov 2020 00:45:01 -0500 Subject: [PATCH] Added ability to select the max quality for a subscription. It defaults to 'best' which will get the best native mp4 video --- backend/app.js | 2 + backend/subscriptions.js | 11 ++++-- .../edit-subscription-dialog.component.html | 7 ++++ .../edit-subscription-dialog.component.ts | 30 +++++++++++++++ .../subscribe-dialog.component.html | 7 ++++ .../subscribe-dialog.component.ts | 37 ++++++++++++++++++- src/app/posts.services.ts | 8 ++-- 7 files changed, 94 insertions(+), 8 deletions(-) diff --git a/backend/app.js b/backend/app.js index 6bd7774..3c1af08 100644 --- a/backend/app.js +++ b/backend/app.js @@ -2196,6 +2196,7 @@ app.post('/api/updateCategories', optionalJwt, async (req, res) => { app.post('/api/subscribe', optionalJwt, async (req, res) => { let name = req.body.name; let url = req.body.url; + let maxQuality = req.body.maxQuality; let timerange = req.body.timerange; let streamingOnly = req.body.streamingOnly; let audioOnly = req.body.audioOnly; @@ -2205,6 +2206,7 @@ app.post('/api/subscribe', optionalJwt, async (req, res) => { const new_sub = { name: name, url: url, + maxQuality: maxQuality, id: uuid(), streamingOnly: streamingOnly, user_uid: user_uid, diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 5eafc4e..4bd071b 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -114,7 +114,11 @@ async function getSubscriptionInfo(sub, user_uid = null) { continue; } if (!sub.name) { - sub.name = sub.isPlaylist ? output_json.playlist_title : output_json.uploader; + if (sub.isPlaylist) { + sub.name = output_json.playlist_title ? output_json.playlist_title : output_json.playlist; + } else { + sub.name = output_json.uploader; + } // if it's now valid, update if (sub.name) { if (user_uid) @@ -296,7 +300,8 @@ async function getVideosForSub(sub, user_uid = null) { qualityPath.push('-x'); qualityPath.push('--audio-format', 'mp3'); } else { - qualityPath = ['-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4'] + if (!sub.maxQuality || sub.maxQuality === 'best') qualityPath = ['-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4']; + else qualityPath = ['-f', `bestvideo[height<=${sub.maxQuality}]+bestaudio/best[height<=${sub.maxQuality}]`, '--merge-output-format', 'mp4']; } downloadConfig.push(...qualityPath) @@ -351,7 +356,7 @@ async function getVideosForSub(sub, user_uid = null) { youtubedl.exec(sub.url, downloadConfig, {}, function(err, output) { logger.verbose('Subscription: finished check for ' + sub.name); if (err && !output) { - logger.error(err.stderr); + logger.error(err.stderr ? err.stderr : err.message); if (err.stderr.includes('This video is unavailable')) { logger.info('An error was encountered with at least one video, backup method will be used.') try { diff --git a/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.html b/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.html index 58a7670..00d5485 100644 --- a/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.html +++ b/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.html @@ -24,6 +24,13 @@ Audio-only mode +
+ + + {{available_quality['label']}} + + +
Streaming-only mode diff --git a/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.ts b/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.ts index 0be5253..b1d2dd4 100644 --- a/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.ts +++ b/src/app/dialogs/edit-subscription-dialog/edit-subscription-dialog.component.ts @@ -22,6 +22,36 @@ export class EditSubscriptionDialogComponent implements OnInit { audioOnlyMode = null; download_all = null; + available_qualities = [ + { + 'label': 'Best', + 'value': 'best' + }, + { + 'label': '4K', + 'value': '2160' + }, + { + 'label': '1440p', + 'value': '1440' + }, + { + 'label': '1080p', + 'value': '1080' + }, + { + 'label': '720p', + 'value': '720' + }, + { + 'label': '480p', + 'value': '480' + }, + { + 'label': '360p', + 'value': '360' + } + ]; time_units = [ 'day', diff --git a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html index 0e5665c..7b53c01 100644 --- a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html +++ b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html @@ -35,6 +35,13 @@
+
+ + + {{available_quality['label']}} + + +
Audio-only mode diff --git a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts index 2c33e92..0d3ab68 100644 --- a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts +++ b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.ts @@ -17,6 +17,8 @@ export class SubscribeDialogComponent implements OnInit { url = null; name = null; + maxQuality = 'best'; + // state subscribing = false; @@ -29,12 +31,43 @@ export class SubscribeDialogComponent implements OnInit { customFileOutput = ''; customArgs = ''; + available_qualities = [ + { + 'label': 'Best', + 'value': 'best' + }, + { + 'label': '4K', + 'value': '2160' + }, + { + 'label': '1440p', + 'value': '1440' + }, + { + 'label': '1080p', + 'value': '1080' + }, + { + 'label': '720p', + 'value': '720' + }, + { + 'label': '480p', + 'value': '480' + }, + { + 'label': '360p', + 'value': '360' + } + ]; + time_units = [ 'day', 'week', 'month', 'year' - ] + ]; constructor(private postsService: PostsService, private snackBar: MatSnackBar, @@ -57,7 +90,7 @@ 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, + this.postsService.createSubscription(this.url, this.name, timerange, this.streamingOnlyMode, this.maxQuality, this.audioOnlyMode, this.customArgs, this.customFileOutput).subscribe(res => { this.subscribing = false; if (res['new_sub']) { diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index d8bc8b3..307c3c5 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -337,9 +337,11 @@ export class PostsService implements CanActivate { }); } - 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); + createSubscription(url, name, timerange = null, streamingOnly = false, maxQuality = 'best', audioOnly = false, + customArgs = null, customFileOutput = null) { + return this.http.post(this.path + 'subscribe', {url: url, name: name, timerange: timerange, maxQuality: maxQuality, + streamingOnly: streamingOnly, audioOnly: audioOnly, customArgs: customArgs, + customFileOutput: customFileOutput}, this.httpOptions); } updateSubscription(subscription) {