2018-10-20 22:20:31 +00:00
|
|
|
from django.http import HttpRequest, HttpResponseBadRequest, JsonResponse
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django import forms
|
|
|
|
from django.views.generic import CreateView, UpdateView, DeleteView, View
|
|
|
|
from django.views.generic.edit import FormMixin
|
|
|
|
from YtManagerApp.management.videos import get_videos
|
|
|
|
from YtManagerApp.models import Subscription, SubscriptionFolder, Video
|
|
|
|
from YtManagerApp.views.controls.modal import ModalMixin
|
|
|
|
from crispy_forms.helper import FormHelper
|
|
|
|
from crispy_forms.layout import Layout, Field, Div, HTML
|
|
|
|
from django.db.models import Q
|
|
|
|
from YtManagerApp.utils import youtube
|
|
|
|
from YtManagerApp.management.jobs.synchronize import schedule_synchronize_now
|
|
|
|
|
|
|
|
|
|
|
|
class SyncNowView(View):
|
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
schedule_synchronize_now()
|
|
|
|
return JsonResponse({
|
|
|
|
'success': True
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteVideoFilesView(View):
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class DownloadVideoFilesView(View):
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class MarkVideoWatchedView(View):
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class MarkVideoUnwatchedView(View):
|
|
|
|
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
|
|
|
|
})
|