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 %} +
+ Watch All +
+{% endif %} + - \ No newline at end of file + diff --git a/app/YtManagerApp/templates/YtManagerApp/video.html b/app/YtManagerApp/templates/YtManagerApp/video.html index d5b1383..cac35f0 100644 --- a/app/YtManagerApp/templates/YtManagerApp/video.html +++ b/app/YtManagerApp/templates/YtManagerApp/video.html @@ -3,32 +3,103 @@ {% load humanize %} {% load ratings %} +{% block scripts %} + + + {% if video_mime is None %} + + + + {% endif %} +{% endblock scripts%} + {% block body %} -
+
-
+

{{ object.name }}

-
- +
+ {% if object.watched %} - + {% else %} - + {% endif %} {% if object.downloaded_path %} - + {% else %} - + {% endif %} + {% if up_next_count %} + {{ up_next_count }}, {{ up_next_duration }} + {% endif %}
@@ -38,9 +109,37 @@ {% else %} - +
+ + {% endif %}
diff --git a/app/YtManagerApp/views/video.py b/app/YtManagerApp/views/video.py index f2e073b..a17b169 100644 --- a/app/YtManagerApp/views/video.py +++ b/app/YtManagerApp/views/video.py @@ -4,9 +4,11 @@ from django.http import HttpRequest, StreamingHttpResponse, FileResponse from django.urls import reverse, reverse_lazy from django.views import View from django.views.generic import DetailView +from django.db.models import Sum from YtManagerApp.models import Video +import datetime class VideoDetailView(LoginRequiredMixin, DetailView): template_name = 'YtManagerApp/video.html' @@ -18,6 +20,11 @@ class VideoDetailView(LoginRequiredMixin, DetailView): if video is not None: context['video_mime'] = mime + if self.request.GET.get('next'): + up_next_videos = self.request.GET.get('next').split(',') + context['up_next_count'] = len(up_next_videos) + context['up_next_duration'] = str(datetime.timedelta(seconds=Video.objects.filter(id__in=up_next_videos).aggregate(Sum('duration'))['duration__sum'])) + return context