mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-27 15:10:55 +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'
|
||||
security:
|
||||
- Auth query parameter: []
|
||||
/api/getAllSubscriptions:
|
||||
/api/getSubscriptions:
|
||||
post:
|
||||
tags:
|
||||
- subscriptions
|
||||
summary: Get all subscriptions
|
||||
operationId: post-api-getAllSubscriptions
|
||||
operationId: post-api-getSubscriptions
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
|
||||
@@ -628,6 +628,9 @@ async function loadConfig() {
|
||||
|
||||
// get subscriptions
|
||||
if (allowSubscriptions) {
|
||||
// set downloading to false
|
||||
let subscriptions = subscriptions_api.getAllSubscriptions();
|
||||
subscriptions_api.updateSubscriptionPropertyMultiple(subscriptions, {downloading: false});
|
||||
// runs initially, then runs every ${subscriptionCheckInterval} seconds
|
||||
watchSubscriptions();
|
||||
setInterval(() => {
|
||||
@@ -686,18 +689,7 @@ function calculateSubcriptionRetrievalDelay(subscriptions_amount) {
|
||||
}
|
||||
|
||||
async function watchSubscriptions() {
|
||||
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.getAllSubscriptions();
|
||||
}
|
||||
let subscriptions = subscriptions_api.getAllSubscriptions();
|
||||
|
||||
if (!subscriptions) return;
|
||||
|
||||
@@ -707,6 +699,8 @@ async function watchSubscriptions() {
|
||||
let delay_interval = calculateSubcriptionRetrievalDelay(subscriptions_amount);
|
||||
|
||||
let current_delay = 0;
|
||||
|
||||
const multiUserMode = config_api.getConfigItem('ytdl_multi_user_mode');
|
||||
for (let i = 0; i < valid_subscriptions.length; i++) {
|
||||
let sub = valid_subscriptions[i];
|
||||
|
||||
@@ -2026,7 +2020,7 @@ app.post('/api/getAllFiles', optionalJwt, async function (req, res) {
|
||||
let files = 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
|
||||
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;
|
||||
|
||||
// get subs from api
|
||||
let subscriptions = subscriptions_api.getAllSubscriptions(user_uid);
|
||||
let subscriptions = subscriptions_api.getSubscriptions(user_uid);
|
||||
|
||||
res.send({
|
||||
subscriptions: subscriptions
|
||||
|
||||
@@ -255,10 +255,6 @@ async function deleteSubscriptionFile(sub, file, deleteForever, file_uid = null,
|
||||
}
|
||||
|
||||
async function getVideosForSub(sub, user_uid = null) {
|
||||
if (!subExists(sub.id, user_uid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get sub_db
|
||||
let sub_db = null;
|
||||
if (user_uid)
|
||||
@@ -266,6 +262,13 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
else
|
||||
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
|
||||
let basePath = null;
|
||||
if (user_uid)
|
||||
@@ -290,6 +293,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
|
||||
return new Promise(resolve => {
|
||||
youtubedl.exec(sub.url, downloadConfig, {}, async function(err, output) {
|
||||
updateSubscriptionProperty(sub, {downloading: false}, user_uid);
|
||||
logger.verbose('Subscription: finished check for ' + sub.name);
|
||||
if (err && !output) {
|
||||
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] === '')) {
|
||||
logger.verbose('No additional videos to download for ' + sub.name);
|
||||
resolve(true);
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < output.length; i++) {
|
||||
let output_json = null;
|
||||
@@ -345,6 +350,7 @@ async function getVideosForSub(sub, user_uid = null) {
|
||||
});
|
||||
}, 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)
|
||||
return users_db.get('users').find({uid: user_uid}).get('subscriptions').value();
|
||||
else
|
||||
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) {
|
||||
if (user_uid)
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (user_uid)
|
||||
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 = {
|
||||
getSubscription : getSubscription,
|
||||
getSubscriptionByName : getSubscriptionByName,
|
||||
getSubscriptions : getSubscriptions,
|
||||
getAllSubscriptions : getAllSubscriptions,
|
||||
updateSubscription : updateSubscription,
|
||||
subscribe : subscribe,
|
||||
@@ -588,5 +625,6 @@ module.exports = {
|
||||
getVideosForSub : getVideosForSub,
|
||||
removeIDFromArchive : removeIDFromArchive,
|
||||
setLogger : setLogger,
|
||||
initialize : initialize
|
||||
initialize : initialize,
|
||||
updateSubscriptionPropertyMultiple : updateSubscriptionPropertyMultiple
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ export class PostsService implements CanActivate {
|
||||
}
|
||||
|
||||
getAllSubscriptions() {
|
||||
return this.http.post(this.path + 'getAllSubscriptions', {}, this.httpOptions);
|
||||
return this.http.post(this.path + 'getSubscriptions', {}, this.httpOptions);
|
||||
}
|
||||
|
||||
// current downloads
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<h2 style="text-align: center;" *ngIf="subscription">
|
||||
{{subscription.name}} <ng-container *ngIf="subscription.paused" i18n="Paused suffix">(Paused)</ng-container>
|
||||
</h2>
|
||||
<mat-progress-bar style="width: 80%; margin: 0 auto; margin-top: 15px;" *ngIf="subscription && subscription.downloading" mode="indeterminate"></mat-progress-bar>
|
||||
</div>
|
||||
<mat-divider style="width: 80%; margin: 0 auto"></mat-divider>
|
||||
<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 { ActivatedRoute, Router, ParamMap } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
@@ -9,7 +9,7 @@ import { EditSubscriptionDialogComponent } from 'app/dialogs/edit-subscription-d
|
||||
templateUrl: './subscription.component.html',
|
||||
styleUrls: ['./subscription.component.scss']
|
||||
})
|
||||
export class SubscriptionComponent implements OnInit {
|
||||
export class SubscriptionComponent implements OnInit, OnDestroy {
|
||||
|
||||
id = null;
|
||||
subscription = null;
|
||||
@@ -44,22 +44,11 @@ export class SubscriptionComponent implements OnInit {
|
||||
};
|
||||
filterProperty = this.filterProperties['upload_date'];
|
||||
downloading = false;
|
||||
|
||||
initialized = false;
|
||||
sub_interval = null;
|
||||
|
||||
constructor(private postsService: PostsService, private route: ActivatedRoute, private router: Router, private dialog: MatDialog) { }
|
||||
|
||||
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')) {
|
||||
this.id = this.route.snapshot.paramMap.get('id');
|
||||
|
||||
@@ -67,6 +56,7 @@ export class SubscriptionComponent implements OnInit {
|
||||
if (init) {
|
||||
this.getConfig();
|
||||
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() {
|
||||
this.router.navigate(['/subscriptions']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user