diff --git a/backend/app.js b/backend/app.js index 7f6df42..194dc8b 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1708,11 +1708,13 @@ app.post('/api/subscribe', async (req, res) => { let name = req.body.name; let url = req.body.url; let timerange = req.body.timerange; + let streamingOnly = req.body.streamingOnly; const new_sub = { name: name, url: url, - id: uuid() + id: uuid(), + streamingOnly: streamingOnly }; // adds timerange if it exists, otherwise all videos will be downloaded @@ -1781,7 +1783,7 @@ app.post('/api/getSubscription', async (req, res) => { } // get sub videos - if (subscription.name) { + if (subscription.name && !subscription.streamingOnly) { let base_path = config_api.getConfigItem('ytdl_subscriptions_base_path'); let appended_base_path = path.join(base_path, subscription.isPlaylist ? 'playlists' : 'channels', subscription.name, '/'); let files; @@ -1817,6 +1819,19 @@ app.post('/api/getSubscription', async (req, res) => { parsed_files.push(file_obj); } + res.send({ + subscription: subscription, + files: parsed_files + }); + } else if (subscription.name && subscription.streamingOnly) { + // return list of videos + let parsed_files = []; + if (subscription.videos) { + for (let i = 0; i < subscription.videos.length; i++) { + const video = subscription.videos[i]; + parsed_files.push(new File(video.title, video.title, video.thumbnail, false, video.duration, video.url, video.uploader, video.size, null, null, video.upload_date)); + } + } res.send({ subscription: subscription, files: parsed_files diff --git a/backend/subscriptions.js b/backend/subscriptions.js index 14458b5..24be735 100644 --- a/backend/subscriptions.js +++ b/backend/subscriptions.js @@ -187,6 +187,7 @@ async function getVideosForSub(sub) { resolve(false); return; } + const sub_db = db.get('subscriptions').find({id: sub.id}); const basePath = config_api.getConfigItem('ytdl_subscriptions_base_path'); const useArchive = config_api.getConfigItem('ytdl_subscriptions_use_youtubedl_archive'); @@ -199,10 +200,6 @@ async function getVideosForSub(sub) { let downloadConfig = ['-o', appendedBasePath + '/%(title)s.mp4', '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4', '-ciw', '--write-annotations', '--write-thumbnail', '--write-info-json', '--print-json']; - if (sub.timerange) { - downloadConfig.push('--dateafter', sub.timerange); - } - let archive_dir = null; let archive_path = null; @@ -214,6 +211,15 @@ async function getVideosForSub(sub) { downloadConfig.push('--download-archive', archive_path); } + // if streaming only mode, just get the list of videos + if (sub.streamingOnly) { + downloadConfig = ['-f', 'best', '--dump-json']; + } + + if (sub.timerange) { + downloadConfig.push('--dateafter', sub.timerange); + } + // get videos logger.verbose('Subscribe: getting videos for subscription ' + sub.name); youtubedl.exec(sub.url, downloadConfig, {}, function(err, output) { @@ -236,6 +242,18 @@ async function getVideosForSub(sub) { continue; } + if (sub.streamingOnly) { + if (i === 0) { + sub_db.assign({videos: []}).write(); + } + + // remove unnecessary info + output_json.formats = null; + + // add to db + sub_db.get('videos').push(output_json).write(); + } + // TODO: Potentially store downloaded files in db? } diff --git a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html index d82c66d..5efbe3f 100644 --- a/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html +++ b/src/app/dialogs/subscribe-dialog/subscribe-dialog.component.html @@ -29,8 +29,10 @@ -