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
|
|
|
|
|
|
|
|
from YtManagerApp.models import Video
|
2019-12-16 20:19:50 +00:00
|
|
|
from YtManagerApp.scheduler.jobs.synchronize_job import SynchronizeJob
|
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-08-14 14:14:16 +00:00
|
|
|
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
|
|
|
|
})
|