Using subtitle id instead of subitle path in the url
This commit is contained in:
parent
a14f4edc99
commit
b2ba593dbe
@ -24,13 +24,13 @@ def setup_plugin():
|
||||
|
||||
routes = [
|
||||
('mediagoblin.plugins.subtitles.customize',
|
||||
'/u/<string:user>/m/<int:media_id>/customize/<string:path>',
|
||||
'/u/<string:user>/m/<int:media_id>/customize/<int:id>',
|
||||
'mediagoblin.plugins.subtitles.views:custom_subtitles'),
|
||||
('mediagoblin.plugins.subtitles.subtitles',
|
||||
'/u/<string:user>/m/<int:media_id>/subtitles/',
|
||||
'mediagoblin.plugins.subtitles.views:edit_subtitles'),
|
||||
('mediagoblin.plugins.subtitles.delete_subtitles',
|
||||
'/u/<string:user>/m/<int:media_id>/delete/<string:path>',
|
||||
'/u/<string:user>/m/<int:media_id>/delete/<int:id>',
|
||||
'mediagoblin.plugins.subtitles.views:delete_subtitles')]
|
||||
|
||||
pluginapi.register_routes(routes)
|
||||
|
@ -31,14 +31,14 @@
|
||||
<form action="{{ request.urlgen('mediagoblin.plugins.subtitles.customize',
|
||||
user=media.get_actor.username,
|
||||
media_id=media.id,
|
||||
path=path) }}" method="POST" enctype="multipart/form-data">
|
||||
id=id) }}" method="POST" enctype="multipart/form-data">
|
||||
<div class="form_box edit_box">
|
||||
{{ wtforms_util.render_divs(form) }}
|
||||
<div class="form_submit_buttons">
|
||||
{% set delete_url = request.urlgen('mediagoblin.plugins.subtitles.delete_subtitles',
|
||||
user= media.get_actor.username,
|
||||
media_id=media.id,
|
||||
path=path) %}
|
||||
id=id) %}
|
||||
<a class="button_action button_warning" href="{{ delete_url }}">{% trans %}Delete Subtitle{% endtrans %}</a>
|
||||
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
|
||||
{{ csrf_token }}
|
||||
|
@ -26,7 +26,7 @@
|
||||
<a href="{{ request.urlgen('mediagoblin.plugins.subtitles.customize',
|
||||
user=media.get_actor.username,
|
||||
media_id=media.id,
|
||||
path=subtitle.filepath) }}">
|
||||
id=subtitle.id ) }}">
|
||||
{{- subtitle.name -}}
|
||||
</li>
|
||||
{%- endfor %}
|
||||
|
@ -17,19 +17,15 @@
|
||||
from mediagoblin import mg_globals
|
||||
import os
|
||||
|
||||
def get_path(path):
|
||||
path = eval(path) # Converting string to a tuple
|
||||
return path
|
||||
|
||||
def open_subtitle(path):
|
||||
subtitle_public_filepath = get_path(path)
|
||||
subtitle_public_filepath = path
|
||||
with mg_globals.public_store.get_file(
|
||||
subtitle_public_filepath, 'rb') as subtitle_public_file:
|
||||
text = subtitle_public_file.read().decode('utf-8','ignore')
|
||||
return text
|
||||
|
||||
def save_subtitle(path,text):
|
||||
subtitle_public_filepath = get_path(path)
|
||||
subtitle_public_filepath = path
|
||||
with mg_globals.public_store.get_file(
|
||||
subtitle_public_filepath, 'wb') as subtitle_public_file:
|
||||
subtitle_public_file.write(text)
|
||||
subtitle_public_file.write(text.encode('utf-8','ignore'))
|
@ -35,7 +35,7 @@ from mediagoblin.tools.response import (render_to_response,
|
||||
|
||||
import mimetypes
|
||||
|
||||
from mediagoblin.plugins.subtitles.tools import open_subtitle,save_subtitle,get_path
|
||||
from mediagoblin.plugins.subtitles.tools import open_subtitle,save_subtitle
|
||||
|
||||
UNSAFE_MIMETYPES = [
|
||||
'text/html',
|
||||
@ -46,7 +46,7 @@ UNSAFE_MIMETYPES = [
|
||||
@require_active_login
|
||||
def edit_subtitles(request, media):
|
||||
allowed_extensions = ['aqt','gsub','jss','sub','ttxt','pjs','psb',
|
||||
'rt','smi','rst','stl','ssf','srt','ssa','ass','usf','vtt','lrc']
|
||||
'rt','smi','stl','ssf','srt','ssa','ass','usf','vtt','lrc']
|
||||
form = forms.EditSubtitlesForm(request.form)
|
||||
|
||||
# Add any subtitles
|
||||
@ -116,8 +116,12 @@ def edit_subtitles(request, media):
|
||||
@require_active_login
|
||||
@get_media_entry_by_id
|
||||
@user_may_delete_media
|
||||
def custom_subtitles(request,media,path=None):
|
||||
path = request.matchdict['path']
|
||||
def custom_subtitles(request,media,id=None):
|
||||
id = request.matchdict['id']
|
||||
path = ""
|
||||
for subtitle in media.subtitle_files:
|
||||
if subtitle["id"] == id:
|
||||
path = subtitle["filepath"]
|
||||
text=""
|
||||
text = open_subtitle(path)
|
||||
form = forms.CustomizeSubtitlesForm(request.form,
|
||||
@ -135,7 +139,7 @@ def custom_subtitles(request,media,path=None):
|
||||
return render_to_response(
|
||||
request,
|
||||
"mediagoblin/plugins/subtitles/custom_subtitles.html",
|
||||
{"path": path,
|
||||
{"id": id,
|
||||
"media": media,
|
||||
"form": form })
|
||||
|
||||
@ -144,18 +148,18 @@ def custom_subtitles(request,media,path=None):
|
||||
@get_media_entry_by_id
|
||||
@user_may_delete_media
|
||||
def delete_subtitles(request,media):
|
||||
path = request.matchdict['path']
|
||||
path = get_path(path)
|
||||
mg_globals.public_store.delete_file(path)
|
||||
id = request.matchdict['id']
|
||||
delete_container = None
|
||||
index = 0
|
||||
for subtitle in media.subtitle_files:
|
||||
if str(subtitle["filepath"]) == str(path):
|
||||
if subtitle["id"] == id:
|
||||
path = subtitle["filepath"]
|
||||
mg_globals.public_store.delete_file(path)
|
||||
delete_container = index
|
||||
index += 1
|
||||
media.subtitle_files.pop(delete_container)
|
||||
media.save()
|
||||
break
|
||||
index += 1
|
||||
|
||||
messages.add_message(
|
||||
request,
|
||||
@ -163,4 +167,4 @@ def delete_subtitles(request,media):
|
||||
("Subtitle file deleted!!!"))
|
||||
|
||||
return redirect(request,
|
||||
location=media.url_for_self(request.urlgen))
|
||||
location=media.url_for_self(request.urlgen))
|
Loading…
x
Reference in New Issue
Block a user