2018-10-27 00:33:45 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from django.views.generic import View
|
|
|
|
|
2019-08-14 14:14:16 +00:00
|
|
|
from YtManagerApp.management.jobs.synchronize import SynchronizeJob
|
2019-11-22 17:11:52 +00:00
|
|
|
from YtManagerApp.models import Video, Subscription
|
2018-10-20 22:20:31 +00:00
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class SyncNowView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
2019-11-22 17:11:52 +00:00
|
|
|
if 'pk' in kwargs:
|
|
|
|
SynchronizeJob.schedule_now_for_subscription(Subscription.objects.get(id=kwargs['pk']))
|
|
|
|
else:
|
|
|
|
SynchronizeJob.schedule_now()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class DeleteVideoFilesView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.delete_files()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class DownloadVideoFilesView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.download()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class MarkVideoWatchedView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.mark_watched()
|
2018-10-20 22:20:31 +00:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 00:33:45 +00:00
|
|
|
class MarkVideoUnwatchedView(LoginRequiredMixin, View):
|
2018-10-20 22:20:31 +00:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-20 22:37:51 +00:00
|
|
|
video.mark_unwatched()
|
2018-10-20 22:20:31 +00:00
|
|
|
video.save()
|
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|