diff --git a/app/YtManagerApp/management/jobs/synchronize.py b/app/YtManagerApp/management/jobs/synchronize.py index 71cc34e..4519b8a 100644 --- a/app/YtManagerApp/management/jobs/synchronize.py +++ b/app/YtManagerApp/management/jobs/synchronize.py @@ -1,11 +1,13 @@ import errno import itertools +import datetime from threading import Lock 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 YtManagerApp.management.appconfig import appconfig from YtManagerApp.management.downloader import fetch_thumbnail, downloader_process_subscription from YtManagerApp.models import * @@ -36,7 +38,7 @@ class SynchronizeJob(Job): def get_subscription_list(self): if self.__subscription is not None: 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): return Video.objects.filter(subscription__in=subs) @@ -110,6 +112,8 @@ class SynchronizeJob(Job): item.position = 1 + (highest or -1) 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]): if obj.thumbnail.startswith("http"): diff --git a/app/YtManagerApp/models.py b/app/YtManagerApp/models.py index 3b779d3..3014db5 100644 --- a/app/YtManagerApp/models.py +++ b/app/YtManagerApp/models.py @@ -110,6 +110,7 @@ class Subscription(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) # youtube adds videos to the 'Uploads' playlist at the top instead of the bottom rewrite_playlist_indices = models.BooleanField(null=False, default=False) + last_synchronised = models.DateTimeField(null=True, blank=True) # overrides auto_download = models.BooleanField(null=True, blank=True) diff --git a/app/YtManagerApp/views/index.py b/app/YtManagerApp/views/index.py index 57864f2..9212614 100644 --- a/app/YtManagerApp/views/index.py +++ b/app/YtManagerApp/views/index.py @@ -335,7 +335,7 @@ class UpdateSubscriptionForm(forms.ModelForm): class Meta: model = Subscription 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): super().__init__(*args, **kwargs) @@ -349,7 +349,8 @@ class UpdateSubscriptionForm(forms.ModelForm): 'auto_download', 'download_limit', 'download_order', - 'automatically_delete_watched' + 'automatically_delete_watched', + Field('last_synchronised', readonly=True) )