Sync channels in reverse order from when they were last synced

This commit is contained in:
Jacob Mansfield [root@Helix] 2019-11-22 16:58:36 +00:00
parent 794b9bd42d
commit 7bcfda70a2
3 changed files with 10 additions and 4 deletions

View File

@ -1,11 +1,13 @@
import errno import errno
import itertools import itertools
import datetime
from threading import Lock from threading import Lock
from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.cron import CronTrigger
from django.db.models import Max from django.db.models import Max, F
from django.conf import settings from django.conf import settings
from YtManagerApp.management.appconfig import appconfig from YtManagerApp.management.appconfig import appconfig
from YtManagerApp.management.downloader import fetch_thumbnail, downloader_process_subscription from YtManagerApp.management.downloader import fetch_thumbnail, downloader_process_subscription
from YtManagerApp.models import * from YtManagerApp.models import *
@ -36,7 +38,7 @@ class SynchronizeJob(Job):
def get_subscription_list(self): def get_subscription_list(self):
if self.__subscription is not None: if self.__subscription is not None:
return [self.__subscription] return [self.__subscription]
return Subscription.objects.all() return Subscription.objects.all().order_by(F('last_synchronised').desc(nulls_first=True))
def get_videos_list(self, subs): def get_videos_list(self, subs):
return Video.objects.filter(subscription__in=subs) return Video.objects.filter(subscription__in=subs)
@ -110,6 +112,8 @@ class SynchronizeJob(Job):
item.position = 1 + (highest or -1) item.position = 1 + (highest or -1)
self.__new_vids.append(Video.create(item, sub)) self.__new_vids.append(Video.create(item, sub))
sub.last_synchronised = datetime.datetime.now()
sub.save()
def fetch_missing_thumbnails(self, obj: Union[Subscription, Video]): def fetch_missing_thumbnails(self, obj: Union[Subscription, Video]):
if obj.thumbnail.startswith("http"): if obj.thumbnail.startswith("http"):

View File

@ -110,6 +110,7 @@ class Subscription(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
# youtube adds videos to the 'Uploads' playlist at the top instead of the bottom # youtube adds videos to the 'Uploads' playlist at the top instead of the bottom
rewrite_playlist_indices = models.BooleanField(null=False, default=False) rewrite_playlist_indices = models.BooleanField(null=False, default=False)
last_synchronised = models.DateTimeField(null=True, blank=True)
# overrides # overrides
auto_download = models.BooleanField(null=True, blank=True) auto_download = models.BooleanField(null=True, blank=True)

View File

@ -335,7 +335,7 @@ class UpdateSubscriptionForm(forms.ModelForm):
class Meta: class Meta:
model = Subscription model = Subscription
fields = ['name', 'parent_folder', 'auto_download', fields = ['name', 'parent_folder', 'auto_download',
'download_limit', 'download_order', "automatically_delete_watched"] 'download_limit', 'download_order', "automatically_delete_watched", 'last_synchronised']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -349,7 +349,8 @@ class UpdateSubscriptionForm(forms.ModelForm):
'auto_download', 'auto_download',
'download_limit', 'download_limit',
'download_order', 'download_order',
'automatically_delete_watched' 'automatically_delete_watched',
Field('last_synchronised', readonly=True)
) )