mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-07 12:00:01 +03:00
Added backend and database support for video streaming
Added UI support for video streaming. branch is now feature-complete
This commit is contained in:
@@ -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,8 +29,10 @@
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</div>
|
||||
<div>
|
||||
<mat-checkbox [(ngModel)]="streamingOnlyMode">Streaming-only mode</mat-checkbox>
|
||||
<div class="col-12">
|
||||
<div>
|
||||
<mat-checkbox [(ngModel)]="streamingOnlyMode">Streaming-only mode</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -49,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']);
|
||||
|
||||
@@ -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,10 +84,16 @@ 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);
|
||||
this.router.navigate(['/player', {fileNames: name, type: 'subscription', subscriptionName: this.subscription.name,
|
||||
subPlaylist: this.subscription.isPlaylist}]);
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user