2018-10-27 03:33:45 +03:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from django.views.generic import View
|
|
|
|
|
|
|
|
from YtManagerApp.models import Video
|
2020-04-11 00:30:24 +03:00
|
|
|
from YtManagerApp.services import Services
|
2018-10-21 01:20:31 +03:00
|
|
|
|
|
|
|
|
2018-10-27 03:33:45 +03:00
|
|
|
class SyncNowView(LoginRequiredMixin, View):
|
2018-10-21 01:20:31 +03:00
|
|
|
def post(self, *args, **kwargs):
|
2020-04-11 00:30:24 +03:00
|
|
|
Services.subscriptionManager().synchronize_all()
|
2018-10-21 01:20:31 +03:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 03:33:45 +03:00
|
|
|
class DeleteVideoFilesView(LoginRequiredMixin, View):
|
2018-10-21 01:20:31 +03:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-21 01:37:51 +03:00
|
|
|
video.delete_files()
|
2018-10-21 01:20:31 +03:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 03:33:45 +03:00
|
|
|
class DownloadVideoFilesView(LoginRequiredMixin, View):
|
2018-10-21 01:20:31 +03:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-21 01:37:51 +03:00
|
|
|
video.download()
|
2018-10-21 01:20:31 +03:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 03:33:45 +03:00
|
|
|
class MarkVideoWatchedView(LoginRequiredMixin, View):
|
2018-10-21 01:20:31 +03:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-21 01:37:51 +03:00
|
|
|
video.mark_watched()
|
2018-10-21 01:20:31 +03:00
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-10-27 03:33:45 +03:00
|
|
|
class MarkVideoUnwatchedView(LoginRequiredMixin, View):
|
2018-10-21 01:20:31 +03:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
video = Video.objects.get(id=kwargs['pk'])
|
2018-10-21 01:37:51 +03:00
|
|
|
video.mark_unwatched()
|
2018-10-21 01:20:31 +03:00
|
|
|
video.save()
|
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|