mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-18 20:41:28 +03:00
In the subscription page, the subscription is now continuously retrieved at an interval of 1s to update for new videos or the downloading state
- There is now a visual indicator for when a subscription is retrieving videos
This commit is contained in:
@@ -261,12 +261,12 @@ paths:
|
|||||||
$ref: '#/components/schemas/inline_response_200_10'
|
$ref: '#/components/schemas/inline_response_200_10'
|
||||||
security:
|
security:
|
||||||
- Auth query parameter: []
|
- Auth query parameter: []
|
||||||
/api/getAllSubscriptions:
|
/api/getSubscriptions:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- subscriptions
|
- subscriptions
|
||||||
summary: Get all subscriptions
|
summary: Get all subscriptions
|
||||||
operationId: post-api-getAllSubscriptions
|
operationId: post-api-getSubscriptions
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
|
|||||||
@@ -628,6 +628,9 @@ async function loadConfig() {
|
|||||||
|
|
||||||
// get subscriptions
|
// get subscriptions
|
||||||
if (allowSubscriptions) {
|
if (allowSubscriptions) {
|
||||||
|
// set downloading to false
|
||||||
|
let subscriptions = subscriptions_api.getAllSubscriptions();
|
||||||
|
subscriptions_api.updateSubscriptionPropertyMultiple(subscriptions, {downloading: false});
|
||||||
// runs initially, then runs every ${subscriptionCheckInterval} seconds
|
// runs initially, then runs every ${subscriptionCheckInterval} seconds
|
||||||
watchSubscriptions();
|
watchSubscriptions();
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -686,18 +689,7 @@ function calculateSubcriptionRetrievalDelay(subscriptions_amount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function watchSubscriptions() {
|
async function watchSubscriptions() {
|
||||||
let subscriptions = null;
|
let subscriptions = subscriptions_api.getAllSubscriptions();
|
||||||
|
|
||||||
const multiUserMode = config_api.getConfigItem('ytdl_multi_user_mode');
|
|
||||||
if (multiUserMode) {
|
|
||||||
subscriptions = [];
|
|
||||||
let users = users_db.get('users').value();
|
|
||||||
for (let i = 0; i < users.length; i++) {
|
|
||||||
if (users[i]['subscriptions']) subscriptions = subscriptions.concat(users[i]['subscriptions']);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
subscriptions = subscriptions_api.getAllSubscriptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subscriptions) return;
|
if (!subscriptions) return;
|
||||||
|
|
||||||
@@ -707,6 +699,8 @@ async function watchSubscriptions() {
|
|||||||
let delay_interval = calculateSubcriptionRetrievalDelay(subscriptions_amount);
|
let delay_interval = calculateSubcriptionRetrievalDelay(subscriptions_amount);
|
||||||
|
|
||||||
let current_delay = 0;
|
let current_delay = 0;
|
||||||
|
|
||||||
|
const multiUserMode = config_api.getConfigItem('ytdl_multi_user_mode');
|
||||||
for (let i = 0; i < valid_subscriptions.length; i++) {
|
for (let i = 0; i < valid_subscriptions.length; i++) {
|
||||||
let sub = valid_subscriptions[i];
|
let sub = valid_subscriptions[i];
|
||||||
|
|
||||||
@@ -2026,7 +2020,7 @@ app.post('/api/getAllFiles', optionalJwt, async function (req, res) {
|
|||||||
let files = null;
|
let files = null;
|
||||||
let playlists = null;
|
let playlists = null;
|
||||||
|
|
||||||
let subscriptions = config_api.getConfigItem('ytdl_allow_subscriptions') ? (subscriptions_api.getAllSubscriptions(req.isAuthenticated() ? req.user.uid : null)) : [];
|
let subscriptions = config_api.getConfigItem('ytdl_allow_subscriptions') ? (subscriptions_api.getSubscriptions(req.isAuthenticated() ? req.user.uid : null)) : [];
|
||||||
|
|
||||||
// get basic info depending on multi-user mode being enabled
|
// get basic info depending on multi-user mode being enabled
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
@@ -2456,11 +2450,11 @@ app.post('/api/updateSubscription', optionalJwt, async (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/getAllSubscriptions', optionalJwt, async (req, res) => {
|
app.post('/api/getSubscriptions', optionalJwt, async (req, res) => {
|
||||||
let user_uid = req.isAuthenticated() ? req.user.uid : null;
|
let user_uid = req.isAuthenticated() ? req.user.uid : null;
|
||||||
|
|
||||||
// get subs from api
|
// get subs from api
|
||||||
let subscriptions = subscriptions_api.getAllSubscriptions(user_uid);
|
let subscriptions = subscriptions_api.getSubscriptions(user_uid);
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
subscriptions: subscriptions
|
subscriptions: subscriptions
|
||||||
|
|||||||
@@ -255,10 +255,6 @@ async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null,
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getVideosForSub(sub, user_uid = null) {
|
async function getVideosForSub(sub, user_uid = null) {
|
||||||
if (!subExists(sub.id, user_uid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get sub_db
|
// get sub_db
|
||||||
let sub_db = null;
|
let sub_db = null;
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
@@ -266,6 +262,13 @@ async function getVideosForSub(sub, user_uid = null) {
|
|||||||
else
|
else
|
||||||
sub_db = db.get('subscriptions').find({id: sub.id});
|
sub_db = db.get('subscriptions').find({id: sub.id});
|
||||||
|
|
||||||
|
const latest_sub_obj = sub_db.value();
|
||||||
|
if (!latest_sub_obj || latest_sub_obj['downloading']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubscriptionProperty(sub, {downloading: true}, user_uid);
|
||||||
|
|
||||||
// get basePath
|
// get basePath
|
||||||
let basePath = null;
|
let basePath = null;
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
@@ -290,6 +293,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
|||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
youtubedl.exec(sub.url, downloadConfig, {}, async function(err, output) {
|
youtubedl.exec(sub.url, downloadConfig, {}, async function(err, output) {
|
||||||
|
updateSubscriptionProperty(sub, {downloading: false}, user_uid);
|
||||||
logger.verbose('Subscription: finished check for ' + sub.name);
|
logger.verbose('Subscription: finished check for ' + sub.name);
|
||||||
if (err && !output) {
|
if (err && !output) {
|
||||||
logger.error(err.stderr ? err.stderr : err.message);
|
logger.error(err.stderr ? err.stderr : err.message);
|
||||||
@@ -319,6 +323,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
|||||||
if (output.length === 0 || (output.length === 1 && output[0] === '')) {
|
if (output.length === 0 || (output.length === 1 && output[0] === '')) {
|
||||||
logger.verbose('No additional videos to download for ' + sub.name);
|
logger.verbose('No additional videos to download for ' + sub.name);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < output.length; i++) {
|
for (let i = 0; i < output.length; i++) {
|
||||||
let output_json = null;
|
let output_json = null;
|
||||||
@@ -345,6 +350,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
|||||||
});
|
});
|
||||||
}, err => {
|
}, err => {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
updateSubscriptionProperty(sub, {downloading: false}, user_uid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,13 +466,28 @@ function handleOutputJSON(sub, sub_db, output_json, multiUserMode = null, reset_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllSubscriptions(user_uid = null) {
|
function getSubscriptions(user_uid = null) {
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
return users_db.get('users').find({uid: user_uid}).get('subscriptions').value();
|
return users_db.get('users').find({uid: user_uid}).get('subscriptions').value();
|
||||||
else
|
else
|
||||||
return db.get('subscriptions').value();
|
return db.get('subscriptions').value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllSubscriptions() {
|
||||||
|
let subscriptions = null;
|
||||||
|
const multiUserMode = config_api.getConfigItem('ytdl_multi_user_mode');
|
||||||
|
if (multiUserMode) {
|
||||||
|
subscriptions = [];
|
||||||
|
let users = users_db.get('users').value();
|
||||||
|
for (let i = 0; i < users.length; i++) {
|
||||||
|
if (users[i]['subscriptions']) subscriptions = subscriptions.concat(users[i]['subscriptions']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subscriptions = subscriptions_api.getSubscriptions();
|
||||||
|
}
|
||||||
|
return subscriptions;
|
||||||
|
}
|
||||||
|
|
||||||
function getSubscription(subID, user_uid = null) {
|
function getSubscription(subID, user_uid = null) {
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
return users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: subID}).value();
|
return users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: subID}).value();
|
||||||
@@ -490,6 +511,21 @@ function updateSubscription(sub, user_uid = null) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSubscriptionPropertyMultiple(subs, assignment_obj) {
|
||||||
|
subs.forEach(sub => {
|
||||||
|
updateSubscriptionProperty(sub, assignment_obj, sub.user_uid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSubscriptionProperty(sub, assignment_obj, user_uid = null) {
|
||||||
|
if (user_uid) {
|
||||||
|
users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: sub.id}).assign(assignment_obj).write();
|
||||||
|
} else {
|
||||||
|
db.get('subscriptions').find({id: sub.id}).assign(assignment_obj).write();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function subExists(subID, user_uid = null) {
|
function subExists(subID, user_uid = null) {
|
||||||
if (user_uid)
|
if (user_uid)
|
||||||
return !!users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: subID}).value();
|
return !!users_db.get('users').find({uid: user_uid}).get('subscriptions').find({id: subID}).value();
|
||||||
@@ -580,6 +616,7 @@ async function removeIDFromArchive(archive_path, id) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
getSubscription : getSubscription,
|
getSubscription : getSubscription,
|
||||||
getSubscriptionByName : getSubscriptionByName,
|
getSubscriptionByName : getSubscriptionByName,
|
||||||
|
getSubscriptions : getSubscriptions,
|
||||||
getAllSubscriptions : getAllSubscriptions,
|
getAllSubscriptions : getAllSubscriptions,
|
||||||
updateSubscription : updateSubscription,
|
updateSubscription : updateSubscription,
|
||||||
subscribe : subscribe,
|
subscribe : subscribe,
|
||||||
@@ -588,5 +625,6 @@ module.exports = {
|
|||||||
getVideosForSub : getVideosForSub,
|
getVideosForSub : getVideosForSub,
|
||||||
removeIDFromArchive : removeIDFromArchive,
|
removeIDFromArchive : removeIDFromArchive,
|
||||||
setLogger : setLogger,
|
setLogger : setLogger,
|
||||||
initialize : initialize
|
initialize : initialize,
|
||||||
|
updateSubscriptionPropertyMultiple : updateSubscriptionPropertyMultiple
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ export class PostsService implements CanActivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAllSubscriptions() {
|
getAllSubscriptions() {
|
||||||
return this.http.post(this.path + 'getAllSubscriptions', {}, this.httpOptions);
|
return this.http.post(this.path + 'getSubscriptions', {}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// current downloads
|
// current downloads
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<h2 style="text-align: center;" *ngIf="subscription">
|
<h2 style="text-align: center;" *ngIf="subscription">
|
||||||
{{subscription.name}} <ng-container *ngIf="subscription.paused" i18n="Paused suffix">(Paused)</ng-container>
|
{{subscription.name}} <ng-container *ngIf="subscription.paused" i18n="Paused suffix">(Paused)</ng-container>
|
||||||
</h2>
|
</h2>
|
||||||
|
<mat-progress-bar style="width: 80%; margin: 0 auto; margin-top: 15px;" *ngIf="subscription && subscription.downloading" mode="indeterminate"></mat-progress-bar>
|
||||||
</div>
|
</div>
|
||||||
<mat-divider style="width: 80%; margin: 0 auto"></mat-divider>
|
<mat-divider style="width: 80%; margin: 0 auto"></mat-divider>
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { PostsService } from 'app/posts.services';
|
import { PostsService } from 'app/posts.services';
|
||||||
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
|
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
@@ -9,7 +9,7 @@ import { EditSubscriptionDialogComponent } from 'app/dialogs/edit-subscription-d
|
|||||||
templateUrl: './subscription.component.html',
|
templateUrl: './subscription.component.html',
|
||||||
styleUrls: ['./subscription.component.scss']
|
styleUrls: ['./subscription.component.scss']
|
||||||
})
|
})
|
||||||
export class SubscriptionComponent implements OnInit {
|
export class SubscriptionComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
id = null;
|
id = null;
|
||||||
subscription = null;
|
subscription = null;
|
||||||
@@ -44,22 +44,11 @@ export class SubscriptionComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
filterProperty = this.filterProperties['upload_date'];
|
filterProperty = this.filterProperties['upload_date'];
|
||||||
downloading = false;
|
downloading = false;
|
||||||
|
sub_interval = null;
|
||||||
initialized = false;
|
|
||||||
|
|
||||||
constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router, private dialog: MatDialog) { }
|
constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router, private dialog: MatDialog) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.paramMap.subscribe((params: ParamMap) => {
|
|
||||||
this.id = params.get('id');
|
|
||||||
this.postsService.service_initialized.subscribe(init => {
|
|
||||||
if (init) {
|
|
||||||
this.initialized = true;
|
|
||||||
this.getConfig();
|
|
||||||
this.getSubscription();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (this.route.snapshot.paramMap.get('id')) {
|
if (this.route.snapshot.paramMap.get('id')) {
|
||||||
this.id = this.route.snapshot.paramMap.get('id');
|
this.id = this.route.snapshot.paramMap.get('id');
|
||||||
|
|
||||||
@@ -67,6 +56,7 @@ export class SubscriptionComponent implements OnInit {
|
|||||||
if (init) {
|
if (init) {
|
||||||
this.getConfig();
|
this.getConfig();
|
||||||
this.getSubscription();
|
this.getSubscription();
|
||||||
|
this.sub_interval = setInterval(() => this.getSubscription(), 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -78,6 +68,13 @@ export class SubscriptionComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
// prevents subscription getter from running in the background
|
||||||
|
if (this.sub_interval) {
|
||||||
|
clearInterval(this.sub_interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
goBack() {
|
goBack() {
|
||||||
this.router.navigate(['/subscriptions']);
|
this.router.navigate(['/subscriptions']);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user