diff --git a/app/YtManagerApp/management/jobs/synchronize.py b/app/YtManagerApp/management/jobs/synchronize.py index 4519b8a..c937e52 100644 --- a/app/YtManagerApp/management/jobs/synchronize.py +++ b/app/YtManagerApp/management/jobs/synchronize.py @@ -74,7 +74,10 @@ class SynchronizeJob(Job): if _ENABLE_UPDATE_STATS: batch_ids = [video.video_id for video in batch] - video_stats = {v.id: v for v in self.__api.videos(batch_ids, part='id,statistics')} + video_stats = {v.id: v for v in self.__api.videos(batch_ids, part='id,statistics,contentDetails')} + else: + batch_ids = [video.video_id for video in filter(lambda video: video.duration == 0, batch)] + video_stats = {v.id: v for v in self.__api.videos(batch_ids, part='id,statistics,contentDetails')} for video in batch: self.progress_advance(1, "Updating video " + video.name) @@ -167,6 +170,7 @@ class SynchronizeJob(Job): video.rating = yt_video.n_likes / (yt_video.n_likes + yt_video.n_dislikes) video.views = yt_video.n_views + video.duration = yt_video.duration.total_seconds() video.save() @staticmethod diff --git a/app/YtManagerApp/migrations/video_duration.py b/app/YtManagerApp/migrations/video_duration.py new file mode 100644 index 0000000..e919943 --- /dev/null +++ b/app/YtManagerApp/migrations/video_duration.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.5 on 2019-10-18 21:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('YtManagerApp', '0012_auto_20190819_1615'), + ] + + operations = [ + migrations.AddField( + model_name='video', + name='duration', + field=models.IntegerField(default=0), + ), + ] diff --git a/app/YtManagerApp/models.py b/app/YtManagerApp/models.py index eb6b5f2..85a9d84 100644 --- a/app/YtManagerApp/models.py +++ b/app/YtManagerApp/models.py @@ -182,6 +182,7 @@ class Video(models.Model): uploader_name = models.CharField(null=False, max_length=255) views = models.IntegerField(null=False, default=0) rating = models.FloatField(null=False, default=0.5) + duration = models.IntegerField(null=False, default=0) @staticmethod def create(playlist_item: youtube.PlaylistItem, subscription: Subscription): diff --git a/app/YtManagerApp/templates/YtManagerApp/index_videos.html b/app/YtManagerApp/templates/YtManagerApp/index_videos.html index 5f472fa..8dd3a12 100644 --- a/app/YtManagerApp/templates/YtManagerApp/index_videos.html +++ b/app/YtManagerApp/templates/YtManagerApp/index_videos.html @@ -1,6 +1,12 @@ {% load humanize %} {% load ratings %} +{% if videos %} +