Merge pull request #49 from Tzahi12345/streaming-only-mode

Streaming-only mode
pull/60/head
Tzahi12345 5 years ago committed by GitHub
commit 4666aa15b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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?
}

@ -29,6 +29,11 @@
</mat-option>
</mat-select>
</div>
<div class="col-12">
<div>
<mat-checkbox [(ngModel)]="streamingOnlyMode">Streaming-only mode</mat-checkbox>
</div>
</div>
</div>
</div>
</mat-dialog-content>
@ -36,7 +41,7 @@
<mat-dialog-actions>
<button mat-button mat-dialog-close><ng-container i18n="Subscribe cancel button">Cancel</ng-container></button>
<!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
<button mat-button [disabled]="!url" type="submit" (click)="subscribeClicked()">Subscribe</button>
<button mat-button [disabled]="!url" type="submit" (click)="subscribeClicked()"><ng-container i18n="Subscribe button">Subscribe</ng-container></button>
<div class="mat-spinner" *ngIf="subscribing">
<mat-spinner [diameter]="25"></mat-spinner>
</div>

@ -19,6 +19,9 @@ export class SubscribeDialogComponent implements OnInit {
// state
subscribing = false;
// no videos actually downloaded, just streamed
streamingOnlyMode = false;
time_units = [
'day',
'week',
@ -46,8 +49,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).subscribe(res => {
this.postsService.createSubscription(this.url, this.name, timerange, this.streamingOnlyMode).subscribe(res => {
this.subscribing = false;
if (res['new_sub']) {
this.dialogRef.close(res['new_sub']);

@ -15,15 +15,15 @@
</div>
<div class="info-item">
<div class="info-item-label"><strong><ng-container i18n="Video file size property">File size:</ng-container>&nbsp;</strong></div>
<div class="info-item-value">{{filesize(file.size)}}</div>
<div class="info-item-value">{{file.size ? filesize(file.size) : 'N/A'}}</div>
</div>
<div class="info-item">
<div class="info-item-label"><strong><ng-container i18n="Video path property">Path:</ng-container>&nbsp;</strong></div>
<div class="info-item-value">{{file.path}}</div>
<div class="info-item-value">{{file.path ? file.path : 'N/A'}}</div>
</div>
<div class="info-item">
<div class="info-item-label"><strong><ng-container i18n="Video upload date property">Upload Date:</ng-container>&nbsp;</strong></div>
<div class="info-item-value">{{file.upload_date}}</div>
<div class="info-item-value">{{file.upload_date ? file.upload_date : 'N/A'}}</div>
</div>
</mat-dialog-content>

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

@ -54,7 +54,11 @@ export class SubscriptionFileCardComponent implements OnInit {
}
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() {

@ -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);
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,
subPlaylist: this.subscription.isPlaylist}]);
}
}
onSearchInputChanged(newvalue) {
if (newvalue.length > 0) {

Loading…
Cancel
Save