mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Merge pull request #85 from cyberjacob/sync-oldest-first
Sync oldest first
This commit is contained in:
commit
43a2bafdf5
@ -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"):
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 2.2.5 on 2019-11-14 20:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('YtManagerApp', '0012_auto_20190819_1615'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='subscription',
|
||||||
|
name='last_synchronised',
|
||||||
|
field=models.DateTimeField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -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)
|
||||||
|
@ -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)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user