mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Added video detail page
This commit is contained in:
parent
c7f740a4d1
commit
ad9138ae1f
@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
from typing import Callable, Union, Any, Optional
|
from typing import Callable, Union, Any, Optional
|
||||||
|
|
||||||
@ -218,6 +219,19 @@ class Video(models.Model):
|
|||||||
if file.startswith(file_pattern):
|
if file.startswith(file_pattern):
|
||||||
yield os.path.join(directory, file)
|
yield os.path.join(directory, file)
|
||||||
|
|
||||||
|
def find_video(self):
|
||||||
|
"""
|
||||||
|
Finds the video file from the downloaded files, and
|
||||||
|
returns
|
||||||
|
:return: Tuple containing file path and mime type
|
||||||
|
"""
|
||||||
|
for file in self.get_files():
|
||||||
|
mime, _ = mimetypes.guess_type(file)
|
||||||
|
if mime is not None and mime.startswith('video/'):
|
||||||
|
return (file, mime)
|
||||||
|
|
||||||
|
return None, None
|
||||||
|
|
||||||
def delete_files(self):
|
def delete_files(self):
|
||||||
if self.downloaded_path is not None:
|
if self.downloaded_path is not None:
|
||||||
from YtManagerApp.management.jobs.delete_video import schedule_delete_video
|
from YtManagerApp.management.jobs.delete_video import schedule_delete_video
|
||||||
|
@ -6,13 +6,17 @@
|
|||||||
{% for video in videos %}
|
{% for video in videos %}
|
||||||
<div class="card-wrapper col-12 col-sm-6 col-lg-4 col-xl-3 d-flex align-items-stretch">
|
<div class="card-wrapper col-12 col-sm-6 col-lg-4 col-xl-3 d-flex align-items-stretch">
|
||||||
<div class="card mx-auto">
|
<div class="card mx-auto">
|
||||||
|
<a href="{% url 'video' video.id %}">
|
||||||
<img class="card-img-top" src="{{ video.icon_best }}" alt="Thumbnail">
|
<img class="card-img-top" src="{{ video.icon_best }}" alt="Thumbnail">
|
||||||
|
</a>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">
|
<h5 class="card-title">
|
||||||
{% if not video.watched %}
|
{% if not video.watched %}
|
||||||
<sup class="badge badge-primary">New</sup>
|
<sup class="badge badge-primary">New</sup>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a href="{% url 'video' video.id %}">
|
||||||
{{ video.name }}
|
{{ video.name }}
|
||||||
|
</a>
|
||||||
</h5>
|
</h5>
|
||||||
<p class="card-text small text-muted">
|
<p class="card-text small text-muted">
|
||||||
<span>{{ video.views | intcomma }} views</span>
|
<span>{{ video.views | intcomma }} views</span>
|
||||||
|
69
app/YtManagerApp/templates/YtManagerApp/video.html
Normal file
69
app/YtManagerApp/templates/YtManagerApp/video.html
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
{% extends "YtManagerApp/master_default.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% load humanize %}
|
||||||
|
{% load ratings %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<h2>{{ object.name }}</h2>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-8">
|
||||||
|
{% if video_mime != None %}
|
||||||
|
<video width="100%" controls autoplay>
|
||||||
|
<source src="{% url 'video-src' object.id %}" type="{{ video_mime }}">
|
||||||
|
</video>
|
||||||
|
{% else %}
|
||||||
|
<iframe id="ytplayer" type="text/html" width="100%" height="400"
|
||||||
|
src="https://www.youtube.com/embed/{{ object.video_id }}?autoplay=1"
|
||||||
|
frameborder="0"></iframe>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="row mx-0 mt-2">
|
||||||
|
<p class="text-muted mb-1">
|
||||||
|
<span>{{ object.views | intcomma }} views</span>
|
||||||
|
<span>•</span>
|
||||||
|
<span>{{ object.publish_date | naturaltime }}</span>
|
||||||
|
</p>
|
||||||
|
<div class="ml-auto">
|
||||||
|
{% starrating object.rating %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="video-description">
|
||||||
|
{{ object.description | linebreaks | urlize }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-4">
|
||||||
|
<h5>Manage video</h5>
|
||||||
|
{% if object.watched %}
|
||||||
|
<a class="btn btn-secondary ajax-link" href="#" data-post-url="{% url 'ajax_action_mark_video_unwatched' object.id %}">
|
||||||
|
Mark not watched
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-secondary ajax-link" href="#" data-post-url="{% url 'ajax_action_mark_video_watched' object.id %}">
|
||||||
|
Mark watched
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if object.downloaded_path %}
|
||||||
|
<a class="btn btn-secondary ajax-link" href="#" data-post-url="{% url 'ajax_action_delete_video_files' object.id %}">
|
||||||
|
Delete downloaded
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="btn btn-secondary ajax-link" href="#" data-post-url="{% url 'ajax_action_download_video_files' object.id %}" >
|
||||||
|
Download
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -18,13 +18,14 @@ from django.conf.urls import include
|
|||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from YtManagerApp.views.video import VideoDetailView, video_detail_view
|
||||||
|
from .views import first_time
|
||||||
from .views.actions import SyncNowView, DeleteVideoFilesView, DownloadVideoFilesView, MarkVideoWatchedView, \
|
from .views.actions import SyncNowView, DeleteVideoFilesView, DownloadVideoFilesView, MarkVideoWatchedView, \
|
||||||
MarkVideoUnwatchedView
|
MarkVideoUnwatchedView
|
||||||
from .views.auth import ExtendedLoginView, RegisterView, RegisterDoneView
|
from .views.auth import ExtendedLoginView, RegisterView, RegisterDoneView
|
||||||
from .views.index import index, ajax_get_tree, ajax_get_videos, CreateFolderModal, UpdateFolderModal, DeleteFolderModal, \
|
from .views.index import index, ajax_get_tree, ajax_get_videos, CreateFolderModal, UpdateFolderModal, DeleteFolderModal, \
|
||||||
CreateSubscriptionModal, UpdateSubscriptionModal, DeleteSubscriptionModal, ImportSubscriptionsModal
|
CreateSubscriptionModal, UpdateSubscriptionModal, DeleteSubscriptionModal, ImportSubscriptionsModal
|
||||||
from .views.settings import SettingsView, AdminSettingsView
|
from .views.settings import SettingsView, AdminSettingsView
|
||||||
from .views import first_time
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Authentication URLs
|
# Authentication URLs
|
||||||
@ -60,6 +61,8 @@ urlpatterns = [
|
|||||||
path('', index, name='home'),
|
path('', index, name='home'),
|
||||||
path('settings/', SettingsView.as_view(), name='settings'),
|
path('settings/', SettingsView.as_view(), name='settings'),
|
||||||
path('admin_settings/', AdminSettingsView.as_view(), name='admin_settings'),
|
path('admin_settings/', AdminSettingsView.as_view(), name='admin_settings'),
|
||||||
|
path('video/<int:pk>/', VideoDetailView.as_view(), name='video'),
|
||||||
|
path('video-src/<int:pk>/', video_detail_view, name='video-src'),
|
||||||
|
|
||||||
# First time setup
|
# First time setup
|
||||||
path('first_time/step0_welcome', first_time.Step0WelcomeView.as_view(), name='first_time_0'),
|
path('first_time/step0_welcome', first_time.Step0WelcomeView.as_view(), name='first_time_0'),
|
||||||
|
30
app/YtManagerApp/views/video.py
Normal file
30
app/YtManagerApp/views/video.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
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 YtManagerApp.models import Video
|
||||||
|
|
||||||
|
|
||||||
|
class VideoDetailView(LoginRequiredMixin, DetailView):
|
||||||
|
template_name = 'YtManagerApp/video.html'
|
||||||
|
model = Video
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
video, mime = self.object.find_video()
|
||||||
|
if video is not None:
|
||||||
|
context['video_mime'] = mime
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def video_detail_view(request: HttpRequest, pk):
|
||||||
|
video = Video.objects.get(id = pk)
|
||||||
|
video_file, _ = video.find_video()
|
||||||
|
|
||||||
|
f = open(video_file, 'rb')
|
||||||
|
return FileResponse(f)
|
Loading…
Reference in New Issue
Block a user