Added backend and database support for video streaming

Added UI support for video streaming. branch is now feature-complete
pull/49/head
Isaac Grynsztein 5 years ago
parent a61606b69f
commit e15141c5e0

@ -1708,11 +1708,13 @@ app.post('/api/subscribe', async (req, res) => {
let name = req.body.name; let name = req.body.name;
let url = req.body.url; let url = req.body.url;
let timerange = req.body.timerange; let timerange = req.body.timerange;
let streamingOnly = req.body.streamingOnly;
const new_sub = { const new_sub = {
name: name, name: name,
url: url, url: url,
id: uuid() id: uuid(),
streamingOnly: streamingOnly
}; };
// adds timerange if it exists, otherwise all videos will be downloaded // 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 // get sub videos
if (subscription.name) { if (subscription.name && !subscription.streamingOnly) {
let base_path = config_api.getConfigItem('ytdl_subscriptions_base_path'); 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 appended_base_path = path.join(base_path, subscription.isPlaylist ? 'playlists' : 'channels', subscription.name, '/');
let files; let files;
@ -1817,6 +1819,19 @@ app.post('/api/getSubscription', async (req, res) => {
parsed_files.push(file_obj); 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({ res.send({
subscription: subscription, subscription: subscription,
files: parsed_files files: parsed_files

@ -187,6 +187,7 @@ async function getVideosForSub(sub) {
resolve(false); resolve(false);
return; return;
} }
const sub_db = db.get('subscriptions').find({id: sub.id});
const basePath = config_api.getConfigItem('ytdl_subscriptions_base_path'); const basePath = config_api.getConfigItem('ytdl_subscriptions_base_path');
const useArchive = config_api.getConfigItem('ytdl_subscriptions_use_youtubedl_archive'); 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']; 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_dir = null;
let archive_path = null; let archive_path = null;
@ -214,6 +211,15 @@ async function getVideosForSub(sub) {
downloadConfig.push('--download-archive', archive_path); 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 // get videos
logger.verbose('Subscribe: getting videos for subscription ' + sub.name); logger.verbose('Subscribe: getting videos for subscription ' + sub.name);
youtubedl.exec(sub.url, downloadConfig, {}, function(err, output) { youtubedl.exec(sub.url, downloadConfig, {}, function(err, output) {
@ -236,6 +242,18 @@ async function getVideosForSub(sub) {
continue; 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? // TODO: Potentially store downloaded files in db?
} }

@ -29,11 +29,13 @@
</mat-option> </mat-option>
</mat-select> </mat-select>
</div> </div>
<div class="col-12">
<div> <div>
<mat-checkbox [(ngModel)]="streamingOnlyMode">Streaming-only mode</mat-checkbox> <mat-checkbox [(ngModel)]="streamingOnlyMode">Streaming-only mode</mat-checkbox>
</div> </div>
</div> </div>
</div> </div>
</div>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions> <mat-dialog-actions>

@ -49,8 +49,7 @@ export class SubscribeDialogComponent implements OnInit {
if (!this.download_all) { if (!this.download_all) {
timerange = 'now-' + this.timerange_amount.toString() + this.timerange_unit; 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).subscribe(res => {
this.subscribing = false; this.subscribing = false;
if (res['new_sub']) { if (res['new_sub']) {
this.dialogRef.close(res['new_sub']); this.dialogRef.close(res['new_sub']);

@ -184,8 +184,8 @@ export class PostsService {
return this.http.post(this.path + 'deletePlaylist', {playlistID: playlistID, type: type}); return this.http.post(this.path + 'deletePlaylist', {playlistID: playlistID, type: type});
} }
createSubscription(url, name, timerange = null) { createSubscription(url, name, timerange = null, streamingOnly = false) {
return this.http.post(this.path + 'subscribe', {url: url, name: name, timerange: timerange}) return this.http.post(this.path + 'subscribe', {url: url, name: name, timerange: timerange, streamingOnly: streamingOnly});
} }
unsubscribe(sub, deleteMode = false) { unsubscribe(sub, deleteMode = false) {

@ -54,7 +54,11 @@ export class SubscriptionFileCardComponent implements OnInit {
} }
goToFile() { goToFile() {
this.goToFileEmit.emit(this.file.id); const emit_obj = {
name: this.file.id,
url: this.file.requested_formats ? this.file.requested_formats[0].url : this.file.url
}
this.goToFileEmit.emit(emit_obj);
} }
openSubscriptionInfoDialog() { openSubscriptionInfoDialog() {

@ -84,11 +84,17 @@ export class SubscriptionComponent implements OnInit {
}); });
} }
goToFile(name) { goToFile(emit_obj) {
const name = emit_obj['name'];
const url = emit_obj['url'];
localStorage.setItem('player_navigator', this.router.url); localStorage.setItem('player_navigator', this.router.url);
if (this.subscription.streamingOnly) {
this.router.navigate(['/player', {name: name, url: url}]);
} else {
this.router.navigate(['/player', {fileNames: name, type: 'subscription', subscriptionName: this.subscription.name, this.router.navigate(['/player', {fileNames: name, type: 'subscription', subscriptionName: this.subscription.name,
subPlaylist: this.subscription.isPlaylist}]); subPlaylist: this.subscription.isPlaylist}]);
} }
}
onSearchInputChanged(newvalue) { onSearchInputChanged(newvalue) {
if (newvalue.length > 0) { if (newvalue.length > 0) {

Loading…
Cancel
Save