Skip to content

Commit a8342c8

Browse files
committed
feat: Edit movies
1 parent ccc8277 commit a8342c8

File tree

5 files changed

+76
-12
lines changed

5 files changed

+76
-12
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{% extends "generic/base.html" %}
22

33
{% block title %}
4-
Upload Video - Nintendo Channel Admin
4+
{{ action }} Video - Nintendo Channel Admin
55
{% endblock %}
66

77
{% block content %}
88
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
9-
<h1 class="mb-6 text-2xl font-bold text-white">Upload New Video</h1>
9+
<h1 class="mb-6 text-2xl font-bold text-white">{{ action }} Video</h1>
1010
<div class="relative group mb-10">
1111
<div class="relative bg-gray-800 rounded-lg shadow-lg overflow-hidden border border-gray-700 p-8">
1212
<div class="flex items-center mb-6 pb-4 border-b border-gray-700">

templates/video_list.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ <h2 class="text-xl font-bold text-white">Videos</h2>
119119
</td>
120120
<td class="px-6 py-4 whitespace-nowrap text-sm">
121121
<div class="flex space-x-2">
122+
<div id="status" class="text-sm text-gray-400 sm:mr-2"></div>
123+
<a href="{{ url_for('thegateway.edit_video', movie_id=video.id) }}"
124+
class="inline-flex items-center px-3 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition duration-200 text-xs">
125+
<img src="/static/icon/pencil.svg" alt="Edit" class="h-3.5 w-3.5 mr-1.5 invert" />
126+
<span>Edit</span>
127+
</a>
122128
<a href="/thegateway/videos"
123129
class="inline-flex items-center px-3 py-1 rounded-md bg-red-700/30 text-red-300 hover:bg-red-600/50 hover:text-white transition-colors duration-200">
124130
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1.5" fill="none"

thegateway/form.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def choices(cls):
2828

2929

3030
class VideoForm(FlaskForm):
31-
video = FileField("Video", validators=[FileRequired()])
31+
video = FileField("Video")
3232
title_jpn = StringField(
3333
"Title (Japanese)", validators=[DataRequired(), Length(max=102)]
3434
)
@@ -51,7 +51,7 @@ class VideoForm(FlaskForm):
5151
"Title (Dutch)", validators=[DataRequired(), Length(max=102)]
5252
)
5353
video_type = SelectField("Video Type", choices=VideoType.choices())
54-
thumbnail = FileField("Video thumbnail", validators=[FileRequired()])
54+
thumbnail = FileField("Video thumbnail")
5555
upload = SubmitField("Add Video")
5656

5757

thegateway/mobiclip.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ def save_video_data(movie_id: int, thumbnail_data: bytes, video_data: bytes):
3636
os.makedirs("./assets/videos")
3737

3838
# Resize and write thumbnail
39-
thumbnail_data = video_thumbnail_encode(thumbnail_data)
40-
thumbnail = open(f"./assets/videos/{movie_id}.img", "wb")
41-
thumbnail.write(thumbnail_data)
42-
thumbnail.close()
39+
if thumbnail_data:
40+
thumbnail_data = video_thumbnail_encode(thumbnail_data)
41+
thumbnail = open(f"./assets/videos/{movie_id}.img", "wb")
42+
thumbnail.write(thumbnail_data)
43+
thumbnail.close()
4344

4445
# Write video
45-
video = open(f"./assets/videos/{movie_id}.mo", "wb")
46-
video.write(video_data)
47-
video.close()
46+
if video_data:
47+
video = open(f"./assets/videos/{movie_id}.mo", "wb")
48+
video.write(video_data)
49+
video.close()

thegateway/videos.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from werkzeug.utils import redirect
1818
import threading
1919
import subprocess
20+
from werkzeug import exceptions
21+
from flask_wtf.file import FileRequired
2022

2123

2224
generate_status = {
@@ -44,10 +46,64 @@ def list_videos():
4446
)
4547

4648

49+
@thegateway_blueprint.route("/thegateway/videos/<movie_id>/edit", methods=["GET", "POST"])
50+
@oidc.require_login
51+
def edit_video(movie_id):
52+
form = VideoForm()
53+
form.upload.label.text = "Edit Video"
54+
55+
movie = Videos.query.filter_by(id=movie_id).first()
56+
if not movie:
57+
return exceptions.NotFound()
58+
59+
if form.validate_on_submit():
60+
thumbnail_data = None
61+
video_data = None
62+
if form.video.data:
63+
video_data = form.video.data.read()
64+
if validate_mobiclip(video_data):
65+
length = get_mobiclip_length(video_data)
66+
movie.length = length
67+
else:
68+
flash("Invalid movie")
69+
return render_template("video_action.html", form=form, action="Edit")
70+
71+
if form.thumbnail.data:
72+
thumbnail_data = form.thumbnail.data.read()
73+
74+
save_video_data(movie.id, thumbnail_data, video_data)
75+
76+
movie.name_japanese = form.title_jpn.data
77+
movie.name_english = form.title_en.data
78+
movie.name_german = form.title_de.data
79+
movie.name_french = form.title_fr.data
80+
movie.name_spanish = form.title_es.data
81+
movie.name_italian = form.title_it.data
82+
movie.name_dutch = form.title_dutch.data
83+
movie.video_type = form.video_type.data
84+
db.session.commit()
85+
86+
return redirect(url_for("thegateway.list_videos"))
87+
else:
88+
form.title_jpn.data = movie.name_japanese
89+
form.title_en.data = movie.name_english
90+
form.title_de.data = movie.name_german
91+
form.title_fr.data = movie.name_french
92+
form.title_es.data = movie.name_spanish
93+
form.title_it.data = movie.name_italian
94+
form.title_dutch.data = movie.name_dutch
95+
form.video_type.data = movie.video_type
96+
97+
return render_template("video_action.html", form=form, action="Edit")
98+
99+
47100
@thegateway_blueprint.route("/thegateway/videos/add", methods=["GET", "POST"])
48101
@oidc.require_login
49102
def add_video():
50103
form = VideoForm()
104+
form.video_type.validators = [FileRequired()]
105+
form.thumbnail.validators = [FileRequired()]
106+
51107
if form.validate_on_submit():
52108
video = form.video.data
53109
thumbnail = form.thumbnail.data
@@ -82,7 +138,7 @@ def add_video():
82138
else:
83139
flash("Error uploading video!")
84140

85-
return render_template("video_add.html", form=form)
141+
return render_template("video_action.html", form=form, action="Add")
86142

87143

88144
@thegateway_blueprint.route("/thegateway/movies/<movie_id>/thumbnail.jpg")

0 commit comments

Comments
 (0)