From 8c36ec5246828e3c99d956edd8524f3ade430571 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 25 May 2016 22:19:06 +0000 Subject: [PATCH 01/49] Revert "Import messages in blog views" This reverts commit 41302ad2b622b340caeb13339338ab3a5d0f7e6b. --- mediagoblin/media_types/blog/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/media_types/blog/views.py b/mediagoblin/media_types/blog/views.py index f1d5c49d..d48cf82f 100644 --- a/mediagoblin/media_types/blog/views.py +++ b/mediagoblin/media_types/blog/views.py @@ -24,7 +24,7 @@ import six from werkzeug.exceptions import Forbidden from mediagoblin.tools import pluginapi -from mediagoblin import messages, mg_globals +from mediagoblin import mg_globals from mediagoblin.media_types.blog import forms as blog_forms from mediagoblin.media_types.blog.models import Blog, BlogPostData From 3019306e0037b994ebc7f0d8f27fc1f1f92dbc8f Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 25 May 2016 22:26:43 +0000 Subject: [PATCH 02/49] Lightbox effect for images --- mediagoblin/static/css/lightbox.css | 21 ++++++ mediagoblin/static/js/lightbox.js | 70 +++++++++++++++++++ .../mediagoblin/user_pages/media.html | 6 +- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 mediagoblin/static/css/lightbox.css create mode 100644 mediagoblin/static/js/lightbox.js diff --git a/mediagoblin/static/css/lightbox.css b/mediagoblin/static/css/lightbox.css new file mode 100644 index 00000000..e4fa4c48 --- /dev/null +++ b/mediagoblin/static/css/lightbox.css @@ -0,0 +1,21 @@ +body { + height: 100%; +} +.overlay { + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + opacity: 0; + filter: alpha(opacity=0); + z-index: 50; + cursor: pointer; +} +.box { + position: absolute; + opacity: 0; + filter: alpha(opacity=0); + left: -9999em; + z-index: 51; +} diff --git a/mediagoblin/static/js/lightbox.js b/mediagoblin/static/js/lightbox.js new file mode 100644 index 00000000..8d7bf31f --- /dev/null +++ b/mediagoblin/static/js/lightbox.js @@ -0,0 +1,70 @@ +$(document).ready(function() { + $(".lightbox").click(function() { + overlayLink = $(this).attr("href"); //Getting the link for the media + window.startOverlay(overlayLink); + return false; + }); +}); + +function startOverlay(overlayLink) { + + // Adding elements to the page + $("body") + .append('
') + .css({ + "overflow-y": "hidden" + }); + + // To create the lightbox effect + $(".container").animate({ + "opacity": "0.2" + }, 300, "linear"); + + var imgWidth = $(".box img").width(); + var imgHeight = $(".box img").height(); + + //adding the image to the box + + $(".box").html(''); + //Position + $(".box img").load(function() { + var imgWidth = $(".box img").width(); + var imgHeight = $(".box img").height(); + if (imgHeight > screen.height - 170) imgHeight = screen.height - 170; + if (imgWidth > screen.width - 300) imgWidth = screen.width - 300; + $(".box") + .css({ + "position": "absolute", + "top": "50%", + "left": "50%", + "height": imgHeight + 10, + "width": imgWidth + 10, + "border": "5px solid white", + "margin-top": -(imgHeight / 2), + "margin-left": -(imgWidth / 2) //to position it in the middle + }) + .animate({ + "opacity": "1" + }, 400, "linear"); + + //To remove + window.closeOverlay(); + }); +} + +function closeOverlay() { + // allow users to be able to close the lightbox + $(".overlay").click(function() { + $(".box, .overlay").animate({ + "opacity": "0" + }, 200, "linear", function() { + $(".box, .overlay").remove(); + }); + $(".container").animate({ + "opacity": "1" + }, 200, "linear"); + $("body").css({ + "overflow-y": "scroll" + }); + }); +} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index ed3d1842..f76e0a8f 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -25,10 +25,14 @@ {% block mediagoblin_head %} + + + {% template_hook("location_head") %} {% template_hook("media_head") %} @@ -57,7 +61,7 @@ #} {% if media.media_files.has_key('medium') %} + media.media_files['original']) }}" class="lightbox"> {% trans media_title=media.title -%}

From 74bc86732e016f5926f5654525485afb6411bb8d Mon Sep 17 00:00:00 2001
From: saksham1115 <saksham115@gmail.com>
Date: Sun, 29 May 2016 17:35:24 +0000
Subject: [PATCH 03/49] Subtitle interface using attachments

---
 mediagoblin/config_spec.ini                                 | 2 +-
 mediagoblin/templates/mediagoblin/media_displays/video.html | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index 0a8da73e..6ded23fd 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -81,7 +81,7 @@ celery_setup_elsewhere = boolean(default=False)
 # Whether or not users are able to upload files of any filetype with
 # their media entries -- This is useful if you want to provide the
 # source files for a media file but can also be a HUGE security risk.
-allow_attachments = boolean(default=False)
+allow_attachments = boolean(default=True)
 
 # Cookie stuff
 csrf_cookie_name = string(default='mediagoblin_csrftoken')
diff --git a/mediagoblin/templates/mediagoblin/media_displays/video.html b/mediagoblin/templates/mediagoblin/media_displays/video.html
index 5aac3529..c9a27702 100644
--- a/mediagoblin/templates/mediagoblin/media_displays/video.html
+++ b/mediagoblin/templates/mediagoblin/media_displays/video.html
@@ -60,6 +60,10 @@
             {% else %}
               type= + {%- for attachment in media.attachment_files %} + + {%- endfor %}
{%- trans -%}Sorry, this video will not work because your web browser does not support HTML5 From 19ba17d95066e55afde4db125cf139aae1831650 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 3 Jun 2016 11:55:46 +0000 Subject: [PATCH 04/49] Subtitle built over attachments : working --- mediagoblin/config_spec.ini | 3 +- mediagoblin/db/models.py | 27 +++++++- mediagoblin/edit/forms.py | 6 ++ mediagoblin/edit/views.py | 58 ++++++++++++++++ .../templates/mediagoblin/edit/subtitles.html | 69 +++++++++++++++++++ .../mediagoblin/media_displays/video.html | 6 +- .../mediagoblin/user_pages/media.html | 27 ++++++++ mediagoblin/tools/files.py | 7 ++ mediagoblin/user_pages/routing.py | 5 ++ 9 files changed, 203 insertions(+), 5 deletions(-) create mode 100644 mediagoblin/templates/mediagoblin/edit/subtitles.html diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index 6ded23fd..7acc72c2 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -81,7 +81,8 @@ celery_setup_elsewhere = boolean(default=False) # Whether or not users are able to upload files of any filetype with # their media entries -- This is useful if you want to provide the # source files for a media file but can also be a HUGE security risk. -allow_attachments = boolean(default=True) +allow_attachments = boolean(default=False) +allow_subtitles = boolean(default=True) # Cookie stuff csrf_cookie_name = string(default='mediagoblin_csrftoken') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 5393f679..9bbb252b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -573,6 +573,15 @@ class MediaEntry(Base, MediaEntryMixin, CommentingMixin): name=v["name"], filepath=v["filepath"]) ) + subtitle_files_helper = relationship("MediaSubtitleFile", + cascade="all, delete-orphan", + order_by="MediaSubtitleFile.created" + ) + subtitle_files = association_proxy("subtitle_files_helper", "dict_view", + creator=lambda v: MediaSubtitleFile( + name=v["name"], filepath=v["filepath"]) + ) + tags_helper = relationship("MediaTag", cascade="all, delete-orphan" # should be automatically deleted ) @@ -888,6 +897,22 @@ class MediaAttachmentFile(Base): """A dict like view on this object""" return DictReadAttrProxy(self) +class MediaSubtitleFile(Base): + __tablename__ = "core__subtitle_files" + + id = Column(Integer, primary_key=True) + media_entry = Column( + Integer, ForeignKey(MediaEntry.id), + nullable=False) + name = Column(Unicode, nullable=False) + filepath = Column(PathTupleWithSlashes) + created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow) + + @property + def dict_view(self): + """A dict like view on this object""" + return DictReadAttrProxy(self) + class Tag(Base): __tablename__ = "core__tags" @@ -1581,7 +1606,7 @@ class Graveyard(Base): return context MODELS = [ LocalUser, RemoteUser, User, MediaEntry, Tag, MediaTag, Comment, TextComment, - Collection, CollectionItem, MediaFile, FileKeynames, MediaAttachmentFile, + Collection, CollectionItem, MediaFile, FileKeynames, MediaAttachmentFile, MediaSubtitleFile, ProcessingMetaData, Notification, Client, CommentSubscription, Report, UserBan, Privilege, PrivilegeUserAssociation, RequestToken, AccessToken, NonceTimestamp, Activity, Generator, Location, GenericModelReference, Graveyard] diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 83e83c3c..f98b672d 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -100,6 +100,12 @@ class EditAttachmentsForm(wtforms.Form): attachment_file = wtforms.FileField( 'File') +class EditSubtitlesForm(wtforms.Form): + subtitle_name = wtforms.StringField( + 'Title') + subtitle_file = wtforms.FileField( + 'File') + class EditCollectionForm(wtforms.Form): title = wtforms.StringField( diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 521359f5..dfc256e2 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -181,6 +181,64 @@ def edit_attachments(request, media): else: raise Forbidden("Attachments are disabled") +@get_media_entry_by_id +@require_active_login +def edit_subtitles(request, media): + if mg_globals.app_config['allow_subtitles']: + form = forms.EditSubtitlesForm(request.form) + + # Add any subtitles + if 'subtitle_file' in request.files \ + and request.files['subtitle_file']: + if mimetypes.guess_type( + request.files['subtitle_file'].filename)[0] in \ + UNSAFE_MIMETYPES: + public_filename = secure_filename('{0}.notsafe'.format( + request.files['subtitle_file'].filename)) + else: + public_filename = secure_filename( + request.files['subtitle_file'].filename) + + subtitle_public_filepath \ + = mg_globals.public_store.get_unique_filepath( + ['media_entries', six.text_type(media.id), 'subtitle', + public_filename]) + + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') + + try: + subtitle_public_file.write( + request.files['subtitle_file'].stream.read()) + finally: + request.files['subtitle_file'].stream.close() + + media.subtitle_files.append(dict( + name=form.subtitle_name.data \ + or request.files['subtitle_file'].filename, + filepath=subtitle_public_filepath, + created=datetime.utcnow(), + )) + + media.save() + + messages.add_message( + request, + messages.SUCCESS, + _("You added the subttile %s!") % + (form.subtitle_name.data or + request.files['subtitle_file'].filename)) + + return redirect(request, + location=media.url_for_self(request.urlgen)) + return render_to_response( + request, + 'mediagoblin/edit/subtitles.html', + {'media': media, + 'form': form}) + else: + raise Forbidden("Subtitles are disabled") + @require_active_login def legacy_edit_profile(request): """redirect the old /edit/profile/?username=USER to /u/USER/edit/""" diff --git a/mediagoblin/templates/mediagoblin/edit/subtitles.html b/mediagoblin/templates/mediagoblin/edit/subtitles.html new file mode 100644 index 00000000..023388f1 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/subtitles.html @@ -0,0 +1,69 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{%- extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block title -%} + {% trans media_title=media.title -%} + Editing subtitles for {{ media_title }} + {%- endtrans %} — {{ super() }} +{%- endblock %} + +{% block mediagoblin_content %} +
+ +
+{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/media_displays/video.html b/mediagoblin/templates/mediagoblin/media_displays/video.html index c9a27702..8e3a202f 100644 --- a/mediagoblin/templates/mediagoblin/media_displays/video.html +++ b/mediagoblin/templates/mediagoblin/media_displays/video.html @@ -60,9 +60,9 @@ {% else %} type="{{ media.media_manager['default_webm_type'] }}" {% endif %} /> - {%- for attachment in media.attachment_files %} - + {%- for subtitle in media.subtitle_files %} + {%- endfor %}
{%- trans -%}Sorry, this video will not work because diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index f76e0a8f..529f638c 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -233,6 +233,33 @@

{%- endif %} + {%- if media.subtitle_files|count %} +

{% trans %}Subtitles{% endtrans %}

+ + {%- endif %} + {%- if app_config['allow_subtitles'] + and request.user + and (media.actor == request.user.id + or request.user.has_privilege('admin')) %} + {%- if not media.subtitle_files|count %} +

{% trans %}Subtitles{% endtrans %}

+ {%- endif %} +

+ + {%- trans %}Add subtitle{% endtrans -%} + +

+ {%- endif %} {% block mediagoblin_sidebar %} {% endblock %} diff --git a/mediagoblin/tools/files.py b/mediagoblin/tools/files.py index 2c486ac8..0509a387 100644 --- a/mediagoblin/tools/files.py +++ b/mediagoblin/tools/files.py @@ -41,5 +41,12 @@ def delete_media_files(media): except OSError: no_such_files.append("/".join(attachment['filepath'])) + for subtitle in media.subtitle_files: + try: + mg_globals.public_store.delete_file( + subtitle['filepath']) + except OSError: + no_such_files.append("/".join(subtitle['filepath'])) + if no_such_files: raise OSError(", ".join(no_such_files)) diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index 68cb0a3b..f7abf7bf 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -111,6 +111,11 @@ add_route('mediagoblin.edit.attachments', '/u//m//attachments/', 'mediagoblin.edit.views:edit_attachments') +add_route('mediagoblin.edit.subtitles', + '/u//m//subtitles/', + 'mediagoblin.edit.views:edit_subtitles') + + add_route('mediagoblin.edit.metadata', '/u//m//metadata/', 'mediagoblin.edit.views:edit_metadata') From 913e281980dd802e0375a5c36be64ed05d3325c3 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 3 Jun 2016 12:19:47 +0000 Subject: [PATCH 05/49] Minor Change --- mediagoblin/edit/forms.py | 4 ++-- mediagoblin/edit/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index f98b672d..c9eae429 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -101,8 +101,8 @@ class EditAttachmentsForm(wtforms.Form): 'File') class EditSubtitlesForm(wtforms.Form): - subtitle_name = wtforms.StringField( - 'Title') + subtitle_language = wtforms.StringField( + 'Language') subtitle_file = wtforms.FileField( 'File') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index dfc256e2..8a4df903 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -214,7 +214,7 @@ def edit_subtitles(request, media): request.files['subtitle_file'].stream.close() media.subtitle_files.append(dict( - name=form.subtitle_name.data \ + name=form.subtitle_language.data \ or request.files['subtitle_file'].filename, filepath=subtitle_public_filepath, created=datetime.utcnow(), @@ -226,7 +226,7 @@ def edit_subtitles(request, media): request, messages.SUCCESS, _("You added the subttile %s!") % - (form.subtitle_name.data or + (form.subtitle_language.data or request.files['subtitle_file'].filename)) return redirect(request, From 682b891d914c99f9881b1d7f345afa481cf5eb48 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Tue, 7 Jun 2016 17:15:06 +0000 Subject: [PATCH 06/49] Starting Customize Interface --- mediagoblin/plugins/custom_subtitles/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/__init__.py diff --git a/mediagoblin/plugins/custom_subtitles/__init__.py b/mediagoblin/plugins/custom_subtitles/__init__.py new file mode 100644 index 00000000..520b43fc --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/__init__.py @@ -0,0 +1,16 @@ +from mediagoblin.tools import pluginapi +import os + +PLUGIN_DIR = os.path.dirname(__file__) + +def setup_plugin(): + config = pluginapi.get_config('mediagoblin.plugins.custom_subtitles') + + # Register the template path. + pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) + + + +hooks = { + 'setup': setup_plugin + } From 991a0c911e25a48caf9d4e264bd61d921b6b6814 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 8 Jun 2016 16:50:03 +0000 Subject: [PATCH 07/49] Customize Interface in progress --- mediagoblin/edit/views.py | 9 +++++++++ .../mediagoblin/user_pages/custom_subtitles.html | 1 + mediagoblin/templates/mediagoblin/user_pages/media.html | 6 ++++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 8a4df903..0c66451f 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -578,3 +578,12 @@ def edit_metadata(request, media): 'mediagoblin/edit/metadata.html', {'form':form, 'media':media}) + + +@require_active_login +def custom_subtitles(request,path): + return render_to_response( + request, + "mediagoblin/templates/user_pages/custom_subtitles.html", + {"path": path} + ) \ No newline at end of file diff --git a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html new file mode 100644 index 00000000..0457fcc3 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html @@ -0,0 +1 @@ +{{path}} \ No newline at end of file diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 529f638c..ed493390 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -238,9 +238,11 @@ From 447d1c2533b2dfffadd0a8febcaf3909c93c4f56 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 8 Jun 2016 18:58:14 +0000 Subject: [PATCH 08/49] Made decorators views for Customize Interface --- mediagoblin/decorators.py | 24 ++++++++++++++++++++++++ mediagoblin/edit/views.py | 9 ++++++--- mediagoblin/user_pages/routing.py | 5 +++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index daeddb3f..30916f14 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -120,6 +120,30 @@ def active_user_from_url(controller): return wrapper +def path_subtitle(controller): + """Retrieve URL pattern and pass in as path=...""" + + + @wraps(controller) + def wrapper(request, *args, **kwargs): + path_sub = request.matchdict['path'] + + return controller(request, *args, path=path_sub, **kwargs) + + return wrapper + +def path_subtitle(controller): + """Retrieve URL pattern and pass in as path=...""" + + + @wraps(controller) + def wrapper(request, *args, **kwargs): + path_sub = request.matchdict['path'] + + return controller(request, *args, path=path_sub, **kwargs) + + return wrapper + def user_may_delete_media(controller): """ diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 0c66451f..b3f4318b 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -17,6 +17,7 @@ import six from datetime import datetime +import os from itsdangerous import BadSignature from pyld import jsonld @@ -34,7 +35,7 @@ from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import (require_active_login, active_user_from_url, get_media_entry_by_id, user_may_alter_collection, get_user_collection, user_has_privilege, - user_not_banned) + user_not_banned, path_subtitle) from mediagoblin.tools.crypto import get_timed_signer_url from mediagoblin.tools.metadata import (compact_and_validate, DEFAULT_CHECKER, DEFAULT_SCHEMA) @@ -581,9 +582,11 @@ def edit_metadata(request, media): @require_active_login -def custom_subtitles(request,path): +@path_subtitle +def custom_subtitles(request,path=None): + path = path.encode('ascii','ignore')[1:-1] return render_to_response( request, - "mediagoblin/templates/user_pages/custom_subtitles.html", + "mediagoblin/user_pages/custom_subtitles.html", {"path": path} ) \ No newline at end of file diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index f7abf7bf..0165ab6c 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -119,3 +119,8 @@ add_route('mediagoblin.edit.subtitles', add_route('mediagoblin.edit.metadata', '/u//m//metadata/', 'mediagoblin.edit.views:edit_metadata') + + +add_route('mediagoblin.edit.custom_subtitles', + '/c_s/', + 'mediagoblin.edit.views:custom_subtitles') \ No newline at end of file From ff60d4a544927ddf4f9f48d3120196e0e10db1e5 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 13 Jun 2016 06:47:32 +0000 Subject: [PATCH 09/49] Path decoded and sent to html page --- mediagoblin/edit/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index b3f4318b..ba727b07 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -584,7 +584,15 @@ def edit_metadata(request, media): @require_active_login @path_subtitle def custom_subtitles(request,path=None): - path = path.encode('ascii','ignore')[1:-1] + path = path.encode('ascii','ignore')[1:-1].split(',') + for index in range(0,len(path)): + path[index] = path[index].encode('utf8') + path[index] = path[index].strip() + path[index] = path[index][2:-1] + temp = path[0] + for index in range(1,len(path)): + temp = temp + "/" + path[index] + path = temp return render_to_response( request, "mediagoblin/user_pages/custom_subtitles.html", From 7cf96b8e6df332461d1edb79a80ec15854bdd5af Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 13 Jun 2016 10:27:23 +0000 Subject: [PATCH 10/49] Loading subtitle files [Not working] --- mediagoblin/edit/views.py | 5 +-- .../user_pages/custom_subtitles.html | 35 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index ba727b07..cad58306 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -592,9 +592,10 @@ def custom_subtitles(request,path=None): temp = path[0] for index in range(1,len(path)): temp = temp + "/" + path[index] - path = temp + path = "/mgoblin_media/" + temp #Bug, have to solve this return render_to_response( request, "mediagoblin/user_pages/custom_subtitles.html", {"path": path} - ) \ No newline at end of file + ) + diff --git a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html index 0457fcc3..6730ab92 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html +++ b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html @@ -1 +1,34 @@ -{{path}} \ No newline at end of file +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# + +# This is the main user homepage for active users +#} + + + +{% extends "mediagoblin/base.html" %} + + +{% block mediagoblin_content %} +

{{ path }}

+ +{% endblock %} \ No newline at end of file From 92497b7af6434d2358fd0ec52a6f6b2127ce0ae5 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Tue, 14 Jun 2016 15:27:11 +0000 Subject: [PATCH 11/49] Working for firefox --- .../mediagoblin/user_pages/custom_subtitles.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html index 6730ab92..d484d1a2 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html +++ b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html @@ -20,15 +20,18 @@ #} - {% extends "mediagoblin/base.html" %} {% block mediagoblin_content %}

{{ path }}

- + + {% endblock %} \ No newline at end of file From 330f409ee91ad142a70617cf05a68916ef6c591e Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 20 Jun 2016 05:47:43 +0000 Subject: [PATCH 12/49] Customizing Subs using Wtforms --- mediagoblin/edit/forms.py | 6 ++++ mediagoblin/edit/routing.py | 2 ++ mediagoblin/edit/views.py | 20 +++++++++-- .../mediagoblin/edit/edit_subtitles.html | 36 +++++++++++++++++++ .../mediagoblin/user_pages/media.html | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 mediagoblin/templates/mediagoblin/edit/edit_subtitles.html diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index c9eae429..7208593b 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -78,6 +78,12 @@ class EditProfileForm(wtforms.Form): location = wtforms.StringField(_('Hometown')) +class CustomizeSubtitlesForm(wtforms.Form): + subtitle = wtforms.TextAreaField( + _('Subtitle'), + [wtforms.validators.Optional()], + description=_("")) + class EditAccountForm(wtforms.Form): wants_comment_notification = wtforms.BooleanField( diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index b349975d..d6d07dae 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -30,3 +30,5 @@ add_route('mediagoblin.edit.email', '/edit/email/', 'mediagoblin.edit.views:change_email') add_route('mediagoblin.edit.deauthorize_applications', '/edit/deauthorize/', 'mediagoblin.edit.views:deauthorize_applications') +add_route('mediagoblin.edit.edit_subtitles', '/c_s//edit/', + 'mediagoblin.edit.views:edit_subtitles') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index cad58306..0582b08c 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -17,7 +17,6 @@ import six from datetime import datetime -import os from itsdangerous import BadSignature from pyld import jsonld @@ -580,7 +579,6 @@ def edit_metadata(request, media): {'form':form, 'media':media}) - @require_active_login @path_subtitle def custom_subtitles(request,path=None): @@ -599,3 +597,21 @@ def custom_subtitles(request,path=None): {"path": path} ) +@require_active_login +@path_subtitle +def edit_subtitles(request,path=None): + path = path.encode('ascii','ignore')[1:-1].split(',') + for index in range(0,len(path)): + path[index] = path[index].encode('utf8') + path[index] = path[index].strip() + path[index] = path[index][2:-1] + temp = path[0] + for index in range(1,len(path)): + temp = temp + "/" + path[index] + path = "/mgoblin_media/" + temp #Bug, have to solve this + form = forms.CustomizeSubtitlesForm(request.form) + return render_to_response( + request, + "mediagoblin/edit/edit_subtitles.html", + {"path": path, + "form": form }) \ No newline at end of file diff --git a/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html b/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html new file mode 100644 index 00000000..51bae307 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html @@ -0,0 +1,36 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block title -%} +{%- endblock %} + +{% block mediagoblin_content %} +{{ path }} +
+
+ {{ wtforms_util.render_divs(form) }} +
+ + {{ csrf_token }} +
+
+
+{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index ed493390..a9c71c8e 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -239,7 +239,7 @@ {%- for subtitle in media.subtitle_files %}
  • - {{- subtitle.name -}} From 6721143fe36778f75889b16db771b35f63f9854a Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sun, 26 Jun 2016 12:15:47 +0000 Subject: [PATCH 13/49] Cleaning up --- mediagoblin/edit/routing.py | 4 +- mediagoblin/edit/views.py | 30 +-------------- .../mediagoblin/edit/custom_subtitles.html | 37 +++++++++++++++++++ .../mediagoblin/user_pages/media.html | 10 ++--- 4 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 mediagoblin/templates/mediagoblin/edit/custom_subtitles.html diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index d6d07dae..ec776bd9 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -30,5 +30,5 @@ add_route('mediagoblin.edit.email', '/edit/email/', 'mediagoblin.edit.views:change_email') add_route('mediagoblin.edit.deauthorize_applications', '/edit/deauthorize/', 'mediagoblin.edit.views:deauthorize_applications') -add_route('mediagoblin.edit.edit_subtitles', '/c_s//edit/', - 'mediagoblin.edit.views:edit_subtitles') +add_route('mediagoblin.edit.custom_subtitles', '/c_s//edit/', + 'mediagoblin.edit.views:custom_subtitles') diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 0582b08c..6d3e684b 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -579,39 +579,13 @@ def edit_metadata(request, media): {'form':form, 'media':media}) -@require_active_login -@path_subtitle -def custom_subtitles(request,path=None): - path = path.encode('ascii','ignore')[1:-1].split(',') - for index in range(0,len(path)): - path[index] = path[index].encode('utf8') - path[index] = path[index].strip() - path[index] = path[index][2:-1] - temp = path[0] - for index in range(1,len(path)): - temp = temp + "/" + path[index] - path = "/mgoblin_media/" + temp #Bug, have to solve this - return render_to_response( - request, - "mediagoblin/user_pages/custom_subtitles.html", - {"path": path} - ) @require_active_login @path_subtitle -def edit_subtitles(request,path=None): - path = path.encode('ascii','ignore')[1:-1].split(',') - for index in range(0,len(path)): - path[index] = path[index].encode('utf8') - path[index] = path[index].strip() - path[index] = path[index][2:-1] - temp = path[0] - for index in range(1,len(path)): - temp = temp + "/" + path[index] - path = "/mgoblin_media/" + temp #Bug, have to solve this +def custom_subtitles(request,path=None): form = forms.CustomizeSubtitlesForm(request.form) return render_to_response( request, - "mediagoblin/edit/edit_subtitles.html", + "mediagoblin/edit/custom_subtitles.html", {"path": path, "form": form }) \ No newline at end of file diff --git a/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html b/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html new file mode 100644 index 00000000..005e661a --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html @@ -0,0 +1,37 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block title -%} +{%- endblock %} + +{% block mediagoblin_content %} +{{ path }} + +
    +
    + {{ wtforms_util.render_divs(form) }} +
    + + {{ csrf_token }} +
    +
    +
    +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index a9c71c8e..0654bcf9 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -25,14 +25,10 @@ {% block mediagoblin_head %} - - - {% template_hook("location_head") %} {% template_hook("media_head") %} @@ -61,7 +57,7 @@ #} {% if media.media_files.has_key('medium') %}
    + media.media_files['original']) }}"> {% trans media_title=media.title -%}
@@ -239,9 +235,9 @@
         {%- for subtitle in media.subtitle_files %}
           <li>
         <!--    <a href= --> - - {{- subtitle.name -}} + {{- subtitle.filepath -}}
  • {%- endfor %} From 533c7ab44a6210f4734b77d5785c5825d70e0c36 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sun, 26 Jun 2016 12:32:27 +0000 Subject: [PATCH 14/49] Removing commented code --- mediagoblin/templates/mediagoblin/user_pages/media.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 0654bcf9..a44f6377 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -234,11 +234,9 @@ From 2c36555bfe4b21880d82b95c4c7a676967f10f96 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Tue, 28 Jun 2016 06:58:22 +0000 Subject: [PATCH 15/49] Converting the path to subtitle into a tuple --- mediagoblin/edit/views.py | 3 +++ .../templates/mediagoblin/user_pages/media.html | 2 +- mediagoblin/tools/subtitles.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 mediagoblin/tools/subtitles.py diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 6d3e684b..33643bf8 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -580,10 +580,13 @@ def edit_metadata(request, media): 'media':media}) +from mediagoblin.tools.subtitles import get_path + @require_active_login @path_subtitle def custom_subtitles(request,path=None): form = forms.CustomizeSubtitlesForm(request.form) + path = get_path(path) return render_to_response( request, "mediagoblin/edit/custom_subtitles.html", diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index a44f6377..3d28cf76 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -236,7 +236,7 @@
  • - {{- subtitle.filepath -}} + {{- subtitle.name -}}
  • {%- endfor %} diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py new file mode 100644 index 00000000..7002cdfc --- /dev/null +++ b/mediagoblin/tools/subtitles.py @@ -0,0 +1,10 @@ +import ast + +def get_path(path): + """ + Converting the path of the form + x = u'[ "A","B","C" ," D"]' + to + x = ["A", "B", "C", "D"] + """ + return ast.literal_eval(path) \ No newline at end of file From 316bef690842b5015fce68d028f92cb7d6766e41 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 29 Jun 2016 11:18:34 +0000 Subject: [PATCH 16/49] Opening ths subtitle using absolute path and open function --- mediagoblin/edit/views.py | 7 ++++--- mediagoblin/tools/subtitles.py | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 33643bf8..ff5c0881 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -580,13 +580,14 @@ def edit_metadata(request, media): 'media':media}) -from mediagoblin.tools.subtitles import get_path +from mediagoblin.tools.subtitles import open_subtitle @require_active_login @path_subtitle def custom_subtitles(request,path=None): - form = forms.CustomizeSubtitlesForm(request.form) - path = get_path(path) + text = open_subtitle(path) + form = forms.CustomizeSubtitlesForm(request.form, + subtitle=text) return render_to_response( request, "mediagoblin/edit/custom_subtitles.html", diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py index 7002cdfc..bfb4a7ea 100644 --- a/mediagoblin/tools/subtitles.py +++ b/mediagoblin/tools/subtitles.py @@ -1,4 +1,4 @@ -import ast +import ast,os def get_path(path): """ @@ -7,4 +7,20 @@ def get_path(path): to x = ["A", "B", "C", "D"] """ - return ast.literal_eval(path) \ No newline at end of file + return ast.literal_eval(path) + +def open_subtitle(path): + temp = ['user_dev','media','public'] + path = list(get_path(path)) + file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary + """ + Creating the absolute path for the subtitle file + """ + subtitle_path = file_path[:-3] + temp + path + subtitle_path = "/" + os.path.join(*subtitle_path) + """ + Opening the file using the absolute path + """ + subtitle = open(subtitle_path,"r") + text = subtitle.read() + return text \ No newline at end of file From 885c2ad4f25648e91edea36c8001ad3ad24769bf Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Thu, 30 Jun 2016 08:45:15 +0000 Subject: [PATCH 17/49] Adding css to textarea --- mediagoblin/static/css/subtitles.css | 4 ++++ mediagoblin/templates/mediagoblin/edit/custom_subtitles.html | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 mediagoblin/static/css/subtitles.css diff --git a/mediagoblin/static/css/subtitles.css b/mediagoblin/static/css/subtitles.css new file mode 100644 index 00000000..73dcbc7d --- /dev/null +++ b/mediagoblin/static/css/subtitles.css @@ -0,0 +1,4 @@ +textarea#subtitle { + height: 500px; + border: 3px solid #cccccc; +} \ No newline at end of file diff --git a/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html b/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html index 005e661a..494cffad 100644 --- a/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html +++ b/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html @@ -22,8 +22,11 @@ {% block title -%} {%- endblock %} + {% block mediagoblin_content %} -{{ path }} +
    From 0e60155a6fd2605ccdb787246bfd6132c0f8fa73 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 8 Jul 2016 10:55:56 +0000 Subject: [PATCH 18/49] Adding the migration file --- ...a5e29_subtitle_plugin_initial_migration.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 mediagoblin/db/migrations/versions/afd3d1da5e29_subtitle_plugin_initial_migration.py diff --git a/mediagoblin/db/migrations/versions/afd3d1da5e29_subtitle_plugin_initial_migration.py b/mediagoblin/db/migrations/versions/afd3d1da5e29_subtitle_plugin_initial_migration.py new file mode 100644 index 00000000..565d4864 --- /dev/null +++ b/mediagoblin/db/migrations/versions/afd3d1da5e29_subtitle_plugin_initial_migration.py @@ -0,0 +1,36 @@ +"""Subtitle plugin initial migration + +Revision ID: afd3d1da5e29 +Revises: 228916769bd2 +Create Date: 2016-06-03 11:48:03.369079 + +""" + +# revision identifiers, used by Alembic. +revision = 'afd3d1da5e29' +down_revision = '228916769bd2' +branch_labels = ('subtitles_plugin',) +depends_on = None + +from alembic import op +import sqlalchemy as sa +from mediagoblin.db.extratypes import PathTupleWithSlashes + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.create_table('core__subtitle_files', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('media_entry', sa.Integer(), nullable=False), + sa.Column('name', sa.Unicode(), nullable=False), + sa.Column('filepath', PathTupleWithSlashes(), nullable=True), + sa.Column('created', sa.DateTime(), nullable=False), + sa.ForeignKeyConstraint(['media_entry'], [u'core__media_entries.id'], ), + sa.PrimaryKeyConstraint('id') + ) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_table('core__subtitle_files') + ### end Alembic commands ### From 1ba4556b90730f94e8b173bf6282373d85a3e69e Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 8 Jul 2016 19:47:35 +0000 Subject: [PATCH 19/49] Removed ast and fixed comments --- mediagoblin/tools/subtitles.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py index bfb4a7ea..2888fe99 100644 --- a/mediagoblin/tools/subtitles.py +++ b/mediagoblin/tools/subtitles.py @@ -1,26 +1,14 @@ -import ast,os +import os def get_path(path): - """ - Converting the path of the form - x = u'[ "A","B","C" ," D"]' - to - x = ["A", "B", "C", "D"] - """ - return ast.literal_eval(path) + return eval(path) def open_subtitle(path): temp = ['user_dev','media','public'] path = list(get_path(path)) file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary - """ - Creating the absolute path for the subtitle file - """ - subtitle_path = file_path[:-3] + temp + path + subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file subtitle_path = "/" + os.path.join(*subtitle_path) - """ - Opening the file using the absolute path - """ - subtitle = open(subtitle_path,"r") + subtitle = open(subtitle_path,"r") # Opening the file using the absolute path text = subtitle.read() return text \ No newline at end of file From a8902a5edb973a0c3ab444a02d51b1108f32d207 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 11 Jul 2016 06:46:12 +0000 Subject: [PATCH 20/49] Saing subtitle after edit --- mediagoblin/edit/views.py | 6 +++++- mediagoblin/tools/subtitles.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index ff5c0881..9ab4a60c 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -580,7 +580,7 @@ def edit_metadata(request, media): 'media':media}) -from mediagoblin.tools.subtitles import open_subtitle +from mediagoblin.tools.subtitles import open_subtitle,save_subtitle @require_active_login @path_subtitle @@ -588,6 +588,10 @@ def custom_subtitles(request,path=None): text = open_subtitle(path) form = forms.CustomizeSubtitlesForm(request.form, subtitle=text) + if request.method == 'POST' and form.validate(): + subtitle_data = form.subtitle.data + save_subtitle(path,subtitle_data) + return render_to_response( request, "mediagoblin/edit/custom_subtitles.html", diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py index 2888fe99..7fcf5f11 100644 --- a/mediagoblin/tools/subtitles.py +++ b/mediagoblin/tools/subtitles.py @@ -11,4 +11,13 @@ def open_subtitle(path): subtitle_path = "/" + os.path.join(*subtitle_path) subtitle = open(subtitle_path,"r") # Opening the file using the absolute path text = subtitle.read() - return text \ No newline at end of file + return text + +def save_subtitle(path,text): + temp = ['user_dev','media','public'] + path = list(get_path(path)) + file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary + subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file + subtitle_path = "/" + os.path.join(*subtitle_path) + subtitle = open(subtitle_path,"w") # Opening the file using the absolute path + subtitle.write(text) \ No newline at end of file From 9f8e9ff18a92757c599530936eafcf08ab7ee709 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 11 Jul 2016 18:49:39 +0000 Subject: [PATCH 21/49] Removed option for adding subtitles for image etc --- .../mediagoblin/user_pages/media.html | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 3d28cf76..f7997571 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -229,33 +229,35 @@

    {%- endif %} - {%- if media.subtitle_files|count %} -

    {% trans %}Subtitles{% endtrans %}

    - - {%- endif %} - {%- if app_config['allow_subtitles'] - and request.user - and (media.actor == request.user.id - or request.user.has_privilege('admin')) %} - {%- if not media.subtitle_files|count %} + {% if "video.html" in media.media_manager.display_template or "audio.html" in media.media_manager.display_template %} + {%- if media.subtitle_files|count %}

    {% trans %}Subtitles{% endtrans %}

    +
    {%- endif %} -

    - - {%- trans %}Add subtitle{% endtrans -%} - -

    - {%- endif %} + {%- if app_config['allow_subtitles'] + and request.user + and (media.actor == request.user.id + or request.user.has_privilege('admin')) %} + {%- if not media.subtitle_files|count %} +

    {% trans %}Subtitles{% endtrans %}

    + {%- endif %} +

    + + {%- trans %}Add subtitle {% endtrans -%} + +

    + {%- endif %} + {% endif %} {% block mediagoblin_sidebar %} {% endblock %} From 4292c6aaaa1fb49740ecd0a26946f2460d805e46 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 13 Jul 2016 13:36:14 +0000 Subject: [PATCH 22/49] Modified get_path function in tools/subtitles.py --- mediagoblin/tools/subtitles.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py index 7fcf5f11..efafbeec 100644 --- a/mediagoblin/tools/subtitles.py +++ b/mediagoblin/tools/subtitles.py @@ -1,23 +1,20 @@ import os def get_path(path): - return eval(path) - -def open_subtitle(path): temp = ['user_dev','media','public'] - path = list(get_path(path)) + path = list(eval(path)) file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file subtitle_path = "/" + os.path.join(*subtitle_path) + return subtitle_path + +def open_subtitle(path): + subtitle_path = get_path(path) subtitle = open(subtitle_path,"r") # Opening the file using the absolute path text = subtitle.read() return text def save_subtitle(path,text): - temp = ['user_dev','media','public'] - path = list(get_path(path)) - file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary - subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file - subtitle_path = "/" + os.path.join(*subtitle_path) + subtitle_path = get_path(path) subtitle = open(subtitle_path,"w") # Opening the file using the absolute path subtitle.write(text) \ No newline at end of file From def53bc3ed189b2e9928b4046a3c2c8a61e31d59 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 13 Jul 2016 13:48:52 +0000 Subject: [PATCH 23/49] Only video owner can upload the subtitle for the video --- mediagoblin/edit/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 9ab4a60c..6b22fbae 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -34,7 +34,7 @@ from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import (require_active_login, active_user_from_url, get_media_entry_by_id, user_may_alter_collection, get_user_collection, user_has_privilege, - user_not_banned, path_subtitle) + user_not_banned, path_subtitle, user_may_delete_media) from mediagoblin.tools.crypto import get_timed_signer_url from mediagoblin.tools.metadata import (compact_and_validate, DEFAULT_CHECKER, DEFAULT_SCHEMA) @@ -182,6 +182,7 @@ def edit_attachments(request, media): raise Forbidden("Attachments are disabled") @get_media_entry_by_id +@user_may_delete_media @require_active_login def edit_subtitles(request, media): if mg_globals.app_config['allow_subtitles']: From 772a07e94f037f62f013aca376019989ebf8cb28 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 13 Jul 2016 15:09:49 +0000 Subject: [PATCH 24/49] Only video uploader can edit their subtitles --- mediagoblin/edit/views.py | 4 +++- mediagoblin/templates/mediagoblin/user_pages/media.html | 4 +++- mediagoblin/user_pages/routing.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 6b22fbae..eb9334e9 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -584,8 +584,10 @@ def edit_metadata(request, media): from mediagoblin.tools.subtitles import open_subtitle,save_subtitle @require_active_login +@get_media_entry_by_id +@user_may_delete_media @path_subtitle -def custom_subtitles(request,path=None): +def custom_subtitles(request,media,path=None): text = open_subtitle(path) form = forms.CustomizeSubtitlesForm(request.form, subtitle=text) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index f7997571..2ba561dd 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -236,8 +236,10 @@ {%- for subtitle in media.subtitle_files %}
  • - {{- subtitle.name -}} + {{- subtitle.name -}}
  • {%- endfor %} diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index 0165ab6c..beb16a0f 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -122,5 +122,5 @@ add_route('mediagoblin.edit.metadata', add_route('mediagoblin.edit.custom_subtitles', - '/c_s/', + '/u//m//c_s/', 'mediagoblin.edit.views:custom_subtitles') \ No newline at end of file From 849b498f9aa6be933358c72ffa05d8828d6bab8d Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 17:52:00 +0000 Subject: [PATCH 25/49] Deleted some files --- .../mediagoblin/edit/edit_subtitles.html | 36 ------------------ .../user_pages/custom_subtitles.html | 37 ------------------- 2 files changed, 73 deletions(-) delete mode 100644 mediagoblin/templates/mediagoblin/edit/edit_subtitles.html delete mode 100644 mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html diff --git a/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html b/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html deleted file mode 100644 index 51bae307..00000000 --- a/mediagoblin/templates/mediagoblin/edit/edit_subtitles.html +++ /dev/null @@ -1,36 +0,0 @@ -{# -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -#} -{% extends "mediagoblin/base.html" %} - -{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} - -{% block title -%} -{%- endblock %} - -{% block mediagoblin_content %} -{{ path }} - -
    - {{ wtforms_util.render_divs(form) }} -
    - - {{ csrf_token }} -
    -
    - -{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html b/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html deleted file mode 100644 index d484d1a2..00000000 --- a/mediagoblin/templates/mediagoblin/user_pages/custom_subtitles.html +++ /dev/null @@ -1,37 +0,0 @@ -{# -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -# This is the main user homepage for active users -#} - - -{% extends "mediagoblin/base.html" %} - - -{% block mediagoblin_content %} -

    {{ path }}

    - - -{% endblock %} \ No newline at end of file From 4688fc0582d29fc949b1fa58b6c228260fa39c13 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:44:28 +0000 Subject: [PATCH 26/49] Converting to subtitle plugin --- mediagoblin/config_spec.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index 7acc72c2..0a8da73e 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -82,7 +82,6 @@ celery_setup_elsewhere = boolean(default=False) # their media entries -- This is useful if you want to provide the # source files for a media file but can also be a HUGE security risk. allow_attachments = boolean(default=False) -allow_subtitles = boolean(default=True) # Cookie stuff csrf_cookie_name = string(default='mediagoblin_csrftoken') From b73fcd96fe471c1e034ef878a8ec59f015ed8103 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:45:11 +0000 Subject: [PATCH 27/49] Making changes to plugins __init__.py --- .../plugins/custom_subtitles/__init__.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/mediagoblin/plugins/custom_subtitles/__init__.py b/mediagoblin/plugins/custom_subtitles/__init__.py index 520b43fc..c50e1762 100644 --- a/mediagoblin/plugins/custom_subtitles/__init__.py +++ b/mediagoblin/plugins/custom_subtitles/__init__.py @@ -1,3 +1,19 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from mediagoblin.tools import pluginapi import os @@ -6,9 +22,24 @@ PLUGIN_DIR = os.path.dirname(__file__) def setup_plugin(): config = pluginapi.get_config('mediagoblin.plugins.custom_subtitles') + routes = [ + ('mediagoblin.plugins.custom_subtitles.customize', + '/u//m//customize/', + 'mediagoblin.plugins.custom_subtitles.views:custom_subtitles'), + ('mediagoblin.plugins.custom_subtitles.subtitles', + '/u//m//subtitles/', + 'mediagoblin.plugins.custom_subtitles.views:edit_subtitles')] + + pluginapi.register_routes(routes) + # Register the template path. pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) + pluginapi.register_template_hooks( + {"customize_subtitles": "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", + "add_subtitles": "mediagoblin/plugins/custom_subtitles/subtitles.html", + "subtitle_sidebar": "mediagoblin/plugins/custom_subtitles/subtitle_media_block.html"}) + hooks = { From c27ecd5bdbeabfa949c6c380424a7b0a3ceeb74c Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:46:06 +0000 Subject: [PATCH 28/49] Creating plugin forms.py --- mediagoblin/plugins/custom_subtitles/forms.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/forms.py diff --git a/mediagoblin/plugins/custom_subtitles/forms.py b/mediagoblin/plugins/custom_subtitles/forms.py new file mode 100644 index 00000000..69afd6e7 --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/forms.py @@ -0,0 +1,29 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import wtforms + +class CustomizeSubtitlesForm(wtforms.Form): + subtitle = wtforms.TextAreaField( + ('Subtitle'), + [wtforms.validators.Optional()], + description=("")) + +class EditSubtitlesForm(wtforms.Form): + subtitle_language = wtforms.StringField( + 'Language') + subtitle_file = wtforms.FileField( + 'File') \ No newline at end of file From 951013e7f916786da1d153b4d3a2e7fbe5faa722 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:46:44 +0000 Subject: [PATCH 29/49] Creating models.py --- .../plugins/custom_subtitles/models.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/models.py diff --git a/mediagoblin/plugins/custom_subtitles/models.py b/mediagoblin/plugins/custom_subtitles/models.py new file mode 100644 index 00000000..4ff57b8d --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/models.py @@ -0,0 +1,49 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +from sqlalchemy import Column, Integer, Unicode, ForeignKey +from sqlalchemy.orm import relationship + +from mediagoblin.db.models import User +from mediagoblin.db.base import Base,MediaEntry + +class MediaSubtitleFile(Base): + __tablename__ = "core__subtitle_files" + + id = Column(Integer, primary_key=True) + media_entry = Column( + Integer, ForeignKey(MediaEntry.id), + nullable=False) + name = Column(Unicode, nullable=False) + filepath = Column(PathTupleWithSlashes) + created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow) + + @property + def dict_view(self): + """A dict like view on this object""" + return DictReadAttrProxy(self) + + subtitle_files_helper = relationship("MediaSubtitleFile", + cascade="all, delete-orphan", + order_by="MediaSubtitleFile.created" + ) + subtitle_files = association_proxy("subtitle_files_helper", "dict_view", + creator=lambda v: MediaSubtitleFile( + name=v["name"], filepath=v["filepath"]) + ) + +MODELS = [ + MediaSubtitleFile +] \ No newline at end of file From 7ebc001c9bb1b82081c6b7eb682e4e097be4aafa Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:53:17 +0000 Subject: [PATCH 30/49] Creating plugin templates --- .../custom_subtitles/custom_subtitles.html | 43 ++++++++++++ .../subtitle_media_block.html | 50 ++++++++++++++ .../plugins/custom_subtitles/subtitles.html | 69 +++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html create mode 100644 mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html create mode 100644 mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitles.html diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html new file mode 100644 index 00000000..177ae728 --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html @@ -0,0 +1,43 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block title -%} +{%- endblock %} + + +{% block mediagoblin_content %} + + +
    +
    + {{ wtforms_util.render_divs(form) }} +
    + + {{ csrf_token }} +
    +
    +
    +{% endblock %} diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html new file mode 100644 index 00000000..3e6bf886 --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html @@ -0,0 +1,50 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} + +{% block subtitle_block %} +{% if "video.html" in media.media_manager.display_template or "audio.html" in media.media_manager.display_template %} + {%- if media.subtitle_files|count %} +

    {% trans %}Subtitles{% endtrans %}

    +
    + {%- endif %} + {%- if request.user + and (media.actor == request.user.id + or request.user.has_privilege('admin')) %} + {%- if not media.subtitle_files|count %} +

    {% trans %}Subtitles{% endtrans %}

    + {%- endif %} +

    + + {%- trans %}Add subtitle {% endtrans -%} + +

    + {%- endif %} + {% endif %} +{% endblock %} diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitles.html b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitles.html new file mode 100644 index 00000000..daf05c11 --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitles.html @@ -0,0 +1,69 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{%- extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block title -%} + {% trans media_title=media.title -%} + Editing subtitles for {{ media_title }} + {%- endtrans %} — {{ super() }} +{%- endblock %} + +{% block mediagoblin_content %} +
    +
    +

    + {%- trans media_title=media.title -%} + Editing subtitles for {{ media_title }} + {%- endtrans -%} +

    +
    + +
    + + {% if media.subtitle_files|count %} +

    {% trans %}subtitles{% endtrans %}

    + + {% endif %} + +

    {% trans %}Add subtitle{% endtrans %}

    + {{- wtforms_util.render_divs(form) }} + +
    +
    +{% endblock %} From 9535599c21812e974bd6682157a88ce331e32ac4 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:54:05 +0000 Subject: [PATCH 31/49] Creating plugin tools.py --- mediagoblin/plugins/custom_subtitles/tools.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/tools.py diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py new file mode 100644 index 00000000..efafbeec --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/tools.py @@ -0,0 +1,20 @@ +import os + +def get_path(path): + temp = ['user_dev','media','public'] + path = list(eval(path)) + file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary + subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file + subtitle_path = "/" + os.path.join(*subtitle_path) + return subtitle_path + +def open_subtitle(path): + subtitle_path = get_path(path) + subtitle = open(subtitle_path,"r") # Opening the file using the absolute path + text = subtitle.read() + return text + +def save_subtitle(path,text): + subtitle_path = get_path(path) + subtitle = open(subtitle_path,"w") # Opening the file using the absolute path + subtitle.write(text) \ No newline at end of file From 945d0937a92e8377175badc948d80903ea755b17 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Fri, 15 Jul 2016 23:58:33 +0000 Subject: [PATCH 32/49] Creating plugins views.py --- mediagoblin/plugins/custom_subtitles/views.py | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 mediagoblin/plugins/custom_subtitles/views.py diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py new file mode 100644 index 00000000..ce540af0 --- /dev/null +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -0,0 +1,162 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import six + +from datetime import datetime + +from itsdangerous import BadSignature +from werkzeug.exceptions import Forbidden +from werkzeug.utils import secure_filename + +from mediagoblin import messages +from mediagoblin import mg_globals + +from mediagoblin.plugins.custom_subtitles import forms +from mediagoblin.decorators import (require_active_login, active_user_from_url, + get_media_entry_by_id, path_subtitle, user_may_delete_media) +from mediagoblin.tools.metadata import (compact_and_validate, DEFAULT_CHECKER, + DEFAULT_SCHEMA) +from mediagoblin.tools.response import (render_to_response, + redirect, redirect_obj, render_404) + +import mimetypes + +from mediagoblin.plugins.custom_subtitles.tools import open_subtitle,save_subtitle + +UNSAFE_MIMETYPES = [ + 'text/html', + 'text/svg+xml'] + +@get_media_entry_by_id +@user_may_delete_media +@require_active_login +def edit_subtitles(request, media): + form = forms.EditSubtitlesForm(request.form) + + # Add any subtitles + if 'subtitle_file' in request.files \ + and request.files['subtitle_file']: + if mimetypes.guess_type( + request.files['subtitle_file'].filename)[0] in \ + UNSAFE_MIMETYPES: + public_filename = secure_filename('{0}.notsafe'.format( + request.files['subtitle_file'].filename)) + else: + public_filename = secure_filename( + request.files['subtitle_file'].filename) + + subtitle_public_filepath \ + = mg_globals.public_store.get_unique_filepath( + ['media_entries', six.text_type(media.id), 'subtitle', + public_filename]) + + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') + + try: + subtitle_public_file.write( + request.files['subtitle_file'].stream.read()) + finally: + request.files['subtitle_file'].stream.close() + + media.subtitle_files.append(dict( + name=form.subtitle_language.data \ + or request.files['subtitle_file'].filename, + filepath=subtitle_public_filepath, + created=datetime.utcnow(), + )) + + media.save() + + messages.add_message( + request, + messages.SUCCESS, + ("You added the subttile %s!") % + (form.subtitle_language.data or + request.files['subtitle_file'].filename)) + + return redirect(request, + location=media.url_for_self(request.urlgen)) + return render_to_response( + request, + 'mediagoblin/plugins/custom_subtitles/subtitles.html', + {'media': media, + 'form': form}) + + +@require_active_login +@get_media_entry_by_id +@user_may_delete_media +@path_subtitle +def custom_subtitles(request,media,path=None): + text="" +# text = open_subtitle(path) + form = forms.CustomizeSubtitlesForm(request.form, + subtitle=text) + if request.method == 'POST' and form.validate(): + subtitle_data = form.subtitle.data +# save_subtitle(path,subtitle_data) + return render_to_response( + request, + "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", + {"path": path, + "media": media, + "form": form }) + + """delete_container = None + index = 0 + for subtitle in media.subtitle_files: + if subtitle["name"] == "Two And A Half Men S02E02.srt": + delete_container = index + index += 1 + print media.subtitle_files.pop(delete_container) + media.save()""" + + return render_to_response( + request, + "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", + {"path": path, + "media": media, + "form": form }) + +@require_active_login +@get_media_entry_by_id +@user_may_delete_media +@path_subtitle +def delete_subtitles(request,media,path=None): + text = open_subtitle(path) + form = forms.CustomizeSubtitlesForm(request.form, + subtitle=text) + if request.method == 'POST' and form.validate(): + subtitle_data = form.subtitle.data + save_subtitle(path,subtitle_data) + + """delete_container = None + index = 0 + for subtitle in media.subtitle_files: + if subtitle["name"] == "Two And A Half Men S02E02.srt": + delete_container = index + index += 1 + print media.subtitle_files.pop(delete_container) + media.save()""" + + return render_to_response( + request, + "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", + {"path": path, + "media": media, + "form": form }) From 3af2d38d29c33de32b7578e4f01197f33b0b20e9 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 00:07:58 +0000 Subject: [PATCH 33/49] Fixed media.html by using plugin hook --- .../mediagoblin/user_pages/media.html | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 2ba561dd..d1f437d1 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -229,37 +229,7 @@

    {%- endif %} - {% if "video.html" in media.media_manager.display_template or "audio.html" in media.media_manager.display_template %} - {%- if media.subtitle_files|count %} -

    {% trans %}Subtitles{% endtrans %}

    - - {%- endif %} - {%- if app_config['allow_subtitles'] - and request.user - and (media.actor == request.user.id - or request.user.has_privilege('admin')) %} - {%- if not media.subtitle_files|count %} -

    {% trans %}Subtitles{% endtrans %}

    - {%- endif %} -

    - - {%- trans %}Add subtitle {% endtrans -%} - -

    - {%- endif %} - {% endif %} + {% template_hook("subtitle_sidebar") %} {% block mediagoblin_sidebar %} {% endblock %} From 6a3fe50e8fde11f952df671446e13091369cebc3 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 00:19:53 +0000 Subject: [PATCH 34/49] Removed almost all of the code from core --- mediagoblin/edit/forms.py | 12 ----- mediagoblin/edit/routing.py | 4 +- mediagoblin/edit/views.py | 82 +------------------------------ mediagoblin/user_pages/routing.py | 12 +---- 4 files changed, 3 insertions(+), 107 deletions(-) diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index 7208593b..83e83c3c 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -78,12 +78,6 @@ class EditProfileForm(wtforms.Form): location = wtforms.StringField(_('Hometown')) -class CustomizeSubtitlesForm(wtforms.Form): - subtitle = wtforms.TextAreaField( - _('Subtitle'), - [wtforms.validators.Optional()], - description=_("")) - class EditAccountForm(wtforms.Form): wants_comment_notification = wtforms.BooleanField( @@ -106,12 +100,6 @@ class EditAttachmentsForm(wtforms.Form): attachment_file = wtforms.FileField( 'File') -class EditSubtitlesForm(wtforms.Form): - subtitle_language = wtforms.StringField( - 'Language') - subtitle_file = wtforms.FileField( - 'File') - class EditCollectionForm(wtforms.Form): title = wtforms.StringField( diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index ec776bd9..d3ae5465 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -29,6 +29,4 @@ add_route('mediagoblin.edit.verify_email', '/edit/verify_email/', add_route('mediagoblin.edit.email', '/edit/email/', 'mediagoblin.edit.views:change_email') add_route('mediagoblin.edit.deauthorize_applications', '/edit/deauthorize/', - 'mediagoblin.edit.views:deauthorize_applications') -add_route('mediagoblin.edit.custom_subtitles', '/c_s//edit/', - 'mediagoblin.edit.views:custom_subtitles') + 'mediagoblin.edit.views:deauthorize_applications') \ No newline at end of file diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index eb9334e9..17e37c50 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -181,65 +181,6 @@ def edit_attachments(request, media): else: raise Forbidden("Attachments are disabled") -@get_media_entry_by_id -@user_may_delete_media -@require_active_login -def edit_subtitles(request, media): - if mg_globals.app_config['allow_subtitles']: - form = forms.EditSubtitlesForm(request.form) - - # Add any subtitles - if 'subtitle_file' in request.files \ - and request.files['subtitle_file']: - if mimetypes.guess_type( - request.files['subtitle_file'].filename)[0] in \ - UNSAFE_MIMETYPES: - public_filename = secure_filename('{0}.notsafe'.format( - request.files['subtitle_file'].filename)) - else: - public_filename = secure_filename( - request.files['subtitle_file'].filename) - - subtitle_public_filepath \ - = mg_globals.public_store.get_unique_filepath( - ['media_entries', six.text_type(media.id), 'subtitle', - public_filename]) - - subtitle_public_file = mg_globals.public_store.get_file( - subtitle_public_filepath, 'wb') - - try: - subtitle_public_file.write( - request.files['subtitle_file'].stream.read()) - finally: - request.files['subtitle_file'].stream.close() - - media.subtitle_files.append(dict( - name=form.subtitle_language.data \ - or request.files['subtitle_file'].filename, - filepath=subtitle_public_filepath, - created=datetime.utcnow(), - )) - - media.save() - - messages.add_message( - request, - messages.SUCCESS, - _("You added the subttile %s!") % - (form.subtitle_language.data or - request.files['subtitle_file'].filename)) - - return redirect(request, - location=media.url_for_self(request.urlgen)) - return render_to_response( - request, - 'mediagoblin/edit/subtitles.html', - {'media': media, - 'form': form}) - else: - raise Forbidden("Subtitles are disabled") - @require_active_login def legacy_edit_profile(request): """redirect the old /edit/profile/?username=USER to /u/USER/edit/""" @@ -578,25 +519,4 @@ def edit_metadata(request, media): request, 'mediagoblin/edit/metadata.html', {'form':form, - 'media':media}) - - -from mediagoblin.tools.subtitles import open_subtitle,save_subtitle - -@require_active_login -@get_media_entry_by_id -@user_may_delete_media -@path_subtitle -def custom_subtitles(request,media,path=None): - text = open_subtitle(path) - form = forms.CustomizeSubtitlesForm(request.form, - subtitle=text) - if request.method == 'POST' and form.validate(): - subtitle_data = form.subtitle.data - save_subtitle(path,subtitle_data) - - return render_to_response( - request, - "mediagoblin/edit/custom_subtitles.html", - {"path": path, - "form": form }) \ No newline at end of file + 'media':media}) \ No newline at end of file diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index beb16a0f..73371b6d 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -111,16 +111,6 @@ add_route('mediagoblin.edit.attachments', '/u//m//attachments/', 'mediagoblin.edit.views:edit_attachments') -add_route('mediagoblin.edit.subtitles', - '/u//m//subtitles/', - 'mediagoblin.edit.views:edit_subtitles') - - add_route('mediagoblin.edit.metadata', '/u//m//metadata/', - 'mediagoblin.edit.views:edit_metadata') - - -add_route('mediagoblin.edit.custom_subtitles', - '/u//m//c_s/', - 'mediagoblin.edit.views:custom_subtitles') \ No newline at end of file + 'mediagoblin.edit.views:edit_metadata') \ No newline at end of file From 443a8e18c82591975e85b597c3d07c86d047f7c2 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 00:27:46 +0000 Subject: [PATCH 35/49] Deleted old templates files --- .../mediagoblin/edit/custom_subtitles.html | 40 ----------- .../templates/mediagoblin/edit/subtitles.html | 69 ------------------- 2 files changed, 109 deletions(-) delete mode 100644 mediagoblin/templates/mediagoblin/edit/custom_subtitles.html delete mode 100644 mediagoblin/templates/mediagoblin/edit/subtitles.html diff --git a/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html b/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html deleted file mode 100644 index 494cffad..00000000 --- a/mediagoblin/templates/mediagoblin/edit/custom_subtitles.html +++ /dev/null @@ -1,40 +0,0 @@ -{# -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -#} -{% extends "mediagoblin/base.html" %} - -{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} - -{% block title -%} -{%- endblock %} - - -{% block mediagoblin_content %} - - -
    -
    - {{ wtforms_util.render_divs(form) }} -
    - - {{ csrf_token }} -
    -
    -
    -{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/edit/subtitles.html b/mediagoblin/templates/mediagoblin/edit/subtitles.html deleted file mode 100644 index 023388f1..00000000 --- a/mediagoblin/templates/mediagoblin/edit/subtitles.html +++ /dev/null @@ -1,69 +0,0 @@ -{# -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -#} -{%- extends "mediagoblin/base.html" %} - -{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} - -{% block title -%} - {% trans media_title=media.title -%} - Editing subtitles for {{ media_title }} - {%- endtrans %} — {{ super() }} -{%- endblock %} - -{% block mediagoblin_content %} -
    -
    -

    - {%- trans media_title=media.title -%} - Editing subtitles for {{ media_title }} - {%- endtrans -%} -

    -
    - -
    - - {% if media.subtitle_files|count %} -

    {% trans %}subtitles{% endtrans %}

    - - {% endif %} - -

    {% trans %}Add subtitle{% endtrans %}

    - {{- wtforms_util.render_divs(form) }} - -
    -
    -{% endblock %} From 5b42f9341a92344245dd503d2c128670d8097e22 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 09:44:21 +0000 Subject: [PATCH 36/49] Removed dependence on absolute path for editing --- mediagoblin/plugins/custom_subtitles/tools.py | 47 ++++++++++++++----- mediagoblin/plugins/custom_subtitles/views.py | 40 ++++------------ 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py index efafbeec..2cc5157f 100644 --- a/mediagoblin/plugins/custom_subtitles/tools.py +++ b/mediagoblin/plugins/custom_subtitles/tools.py @@ -1,20 +1,41 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from mediagoblin import mg_globals import os def get_path(path): - temp = ['user_dev','media','public'] - path = list(eval(path)) - file_path = os.path.abspath(__file__).split('/') # Path of current file as dictionary - subtitle_path = file_path[:-3] + temp + path # Creating the absolute path for the subtitle file - subtitle_path = "/" + os.path.join(*subtitle_path) - return subtitle_path + path = eval(path) # Converting string to a tuple + return path def open_subtitle(path): - subtitle_path = get_path(path) - subtitle = open(subtitle_path,"r") # Opening the file using the absolute path - text = subtitle.read() - return text + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'rb') + try: + text = subtitle_public_file.read().decode('utf-8') + return text + finally: + subtitle_public_file.close() def save_subtitle(path,text): - subtitle_path = get_path(path) - subtitle = open(subtitle_path,"w") # Opening the file using the absolute path - subtitle.write(text) \ No newline at end of file + subtitle_public_filepath = get_path(path) + subtitle_public_file = mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') + try: + subtitle_public_file.write(text) + finally: + subtitle_public_file.close() \ No newline at end of file diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index ce540af0..e647df59 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -104,12 +104,16 @@ def edit_subtitles(request, media): @path_subtitle def custom_subtitles(request,media,path=None): text="" -# text = open_subtitle(path) + text = open_subtitle(path) form = forms.CustomizeSubtitlesForm(request.form, subtitle=text) if request.method == 'POST' and form.validate(): subtitle_data = form.subtitle.data -# save_subtitle(path,subtitle_data) + save_subtitle(path,subtitle_data) + messages.add_message( + request, + messages.SUCCESS, + ("Subtitle file changed!!!")) return render_to_response( request, "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", @@ -125,38 +129,10 @@ def custom_subtitles(request,media,path=None): index += 1 print media.subtitle_files.pop(delete_container) media.save()""" - + return render_to_response( request, "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", {"path": path, "media": media, - "form": form }) - -@require_active_login -@get_media_entry_by_id -@user_may_delete_media -@path_subtitle -def delete_subtitles(request,media,path=None): - text = open_subtitle(path) - form = forms.CustomizeSubtitlesForm(request.form, - subtitle=text) - if request.method == 'POST' and form.validate(): - subtitle_data = form.subtitle.data - save_subtitle(path,subtitle_data) - - """delete_container = None - index = 0 - for subtitle in media.subtitle_files: - if subtitle["name"] == "Two And A Half Men S02E02.srt": - delete_container = index - index += 1 - print media.subtitle_files.pop(delete_container) - media.save()""" - - return render_to_response( - request, - "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", - {"path": path, - "media": media, - "form": form }) + "form": form }) \ No newline at end of file From eaeed602d3db4eac75c5e0cf92f338e3c991001a Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 16 Jul 2016 18:24:31 +0000 Subject: [PATCH 37/49] Added the feature for deleting the subtitle --- .../plugins/custom_subtitles/__init__.py | 5 ++- .../custom_subtitles/custom_subtitles.html | 7 +++- mediagoblin/plugins/custom_subtitles/views.py | 40 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/mediagoblin/plugins/custom_subtitles/__init__.py b/mediagoblin/plugins/custom_subtitles/__init__.py index c50e1762..f2adc47b 100644 --- a/mediagoblin/plugins/custom_subtitles/__init__.py +++ b/mediagoblin/plugins/custom_subtitles/__init__.py @@ -28,7 +28,10 @@ def setup_plugin(): 'mediagoblin.plugins.custom_subtitles.views:custom_subtitles'), ('mediagoblin.plugins.custom_subtitles.subtitles', '/u//m//subtitles/', - 'mediagoblin.plugins.custom_subtitles.views:edit_subtitles')] + 'mediagoblin.plugins.custom_subtitles.views:edit_subtitles'), + ('mediagoblin.plugins.custom_subtitles.delete_subtitles', + '/u//m//delete/', + 'mediagoblin.plugins.custom_subtitles.views:delete_subtitles')] pluginapi.register_routes(routes) diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html index 177ae728..e1975c75 100644 --- a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html +++ b/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html @@ -35,9 +35,14 @@
    {{ wtforms_util.render_divs(form) }}
    + {% set delete_url = request.urlgen('mediagoblin.plugins.custom_subtitles.delete_subtitles', + user= media.get_actor.username, + media_id=media.id, + path=path) %} + {% trans %}Delete Subtitle{% endtrans %} {{ csrf_token }}
    -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index e647df59..fdda5b37 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -35,7 +35,7 @@ from mediagoblin.tools.response import (render_to_response, import mimetypes -from mediagoblin.plugins.custom_subtitles.tools import open_subtitle,save_subtitle +from mediagoblin.plugins.custom_subtitles.tools import open_subtitle,save_subtitle,get_path UNSAFE_MIMETYPES = [ 'text/html', @@ -121,18 +121,36 @@ def custom_subtitles(request,media,path=None): "media": media, "form": form }) - """delete_container = None - index = 0 - for subtitle in media.subtitle_files: - if subtitle["name"] == "Two And A Half Men S02E02.srt": - delete_container = index - index += 1 - print media.subtitle_files.pop(delete_container) - media.save()""" - return render_to_response( request, "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", {"path": path, "media": media, - "form": form }) \ No newline at end of file + "form": form }) + + +@require_active_login +@get_media_entry_by_id +@user_may_delete_media +@path_subtitle +def delete_subtitles(request,media,path=None): + + path = get_path(path) + mg_globals.public_store.delete_file(path) + delete_container = None + index = 0 + for subtitle in media.subtitle_files: + if str(subtitle["filepath"]) == str(path): + delete_container = index + index += 1 + media.subtitle_files.pop(delete_container) + media.save() + break + + messages.add_message( + request, + messages.SUCCESS, + ("Subtitle file deleted!!!")) + + return redirect(request, + location=media.url_for_self(request.urlgen)) \ No newline at end of file From c36c6833046b6d1f6aa1b0f274585a1b23b9a5ad Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Tue, 19 Jul 2016 18:15:36 +0000 Subject: [PATCH 38/49] Removed path_subtitle as a decorator --- mediagoblin/decorators.py | 24 ------------------- mediagoblin/plugins/custom_subtitles/views.py | 9 ++++--- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index 30916f14..daeddb3f 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -120,30 +120,6 @@ def active_user_from_url(controller): return wrapper -def path_subtitle(controller): - """Retrieve URL pattern and pass in as path=...""" - - - @wraps(controller) - def wrapper(request, *args, **kwargs): - path_sub = request.matchdict['path'] - - return controller(request, *args, path=path_sub, **kwargs) - - return wrapper - -def path_subtitle(controller): - """Retrieve URL pattern and pass in as path=...""" - - - @wraps(controller) - def wrapper(request, *args, **kwargs): - path_sub = request.matchdict['path'] - - return controller(request, *args, path=path_sub, **kwargs) - - return wrapper - def user_may_delete_media(controller): """ diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index fdda5b37..5ea9cf35 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -27,7 +27,7 @@ from mediagoblin import mg_globals from mediagoblin.plugins.custom_subtitles import forms from mediagoblin.decorators import (require_active_login, active_user_from_url, - get_media_entry_by_id, path_subtitle, user_may_delete_media) + get_media_entry_by_id, user_may_delete_media) from mediagoblin.tools.metadata import (compact_and_validate, DEFAULT_CHECKER, DEFAULT_SCHEMA) from mediagoblin.tools.response import (render_to_response, @@ -101,8 +101,8 @@ def edit_subtitles(request, media): @require_active_login @get_media_entry_by_id @user_may_delete_media -@path_subtitle def custom_subtitles(request,media,path=None): + path = request.matchdict['path'] text="" text = open_subtitle(path) form = forms.CustomizeSubtitlesForm(request.form, @@ -132,9 +132,8 @@ def custom_subtitles(request,media,path=None): @require_active_login @get_media_entry_by_id @user_may_delete_media -@path_subtitle -def delete_subtitles(request,media,path=None): - +def delete_subtitles(request,media): + path = request.matchdict['path'] path = get_path(path) mg_globals.public_store.delete_file(path) delete_container = None From 13422829838bbf3c5a33e88ba90e47d91f55e455 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Mon, 25 Jul 2016 19:23:31 +0000 Subject: [PATCH 39/49] Using with statement for editing files --- mediagoblin/plugins/custom_subtitles/tools.py | 24 +++++++------------ mediagoblin/plugins/custom_subtitles/views.py | 19 +++++---------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/mediagoblin/plugins/custom_subtitles/tools.py b/mediagoblin/plugins/custom_subtitles/tools.py index 2cc5157f..f947ba92 100644 --- a/mediagoblin/plugins/custom_subtitles/tools.py +++ b/mediagoblin/plugins/custom_subtitles/tools.py @@ -18,24 +18,18 @@ from mediagoblin import mg_globals import os def get_path(path): - path = eval(path) # Converting string to a tuple - return path + path = eval(path) # Converting string to a tuple + return path def open_subtitle(path): - subtitle_public_filepath = get_path(path) - subtitle_public_file = mg_globals.public_store.get_file( - subtitle_public_filepath, 'rb') - try: + subtitle_public_filepath = get_path(path) + with mg_globals.public_store.get_file( + subtitle_public_filepath, 'rb') as subtitle_public_file: text = subtitle_public_file.read().decode('utf-8') return text - finally: - subtitle_public_file.close() def save_subtitle(path,text): - subtitle_public_filepath = get_path(path) - subtitle_public_file = mg_globals.public_store.get_file( - subtitle_public_filepath, 'wb') - try: - subtitle_public_file.write(text) - finally: - subtitle_public_file.close() \ No newline at end of file + subtitle_public_filepath = get_path(path) + with mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') as subtitle_public_file: + subtitle_public_file.write(text) \ No newline at end of file diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index 5ea9cf35..3d75b0ae 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -64,14 +64,11 @@ def edit_subtitles(request, media): ['media_entries', six.text_type(media.id), 'subtitle', public_filename]) - subtitle_public_file = mg_globals.public_store.get_file( - subtitle_public_filepath, 'wb') - - try: + with mg_globals.public_store.get_file( + subtitle_public_filepath, 'wb') as subtitle_public_file: subtitle_public_file.write( request.files['subtitle_file'].stream.read()) - finally: - request.files['subtitle_file'].stream.close() + request.files['subtitle_file'].stream.close() media.subtitle_files.append(dict( name=form.subtitle_language.data \ @@ -85,7 +82,7 @@ def edit_subtitles(request, media): messages.add_message( request, messages.SUCCESS, - ("You added the subttile %s!") % + ("You added the subtitle %s!") % (form.subtitle_language.data or request.files['subtitle_file'].filename)) @@ -114,12 +111,8 @@ def custom_subtitles(request,media,path=None): request, messages.SUCCESS, ("Subtitle file changed!!!")) - return render_to_response( - request, - "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", - {"path": path, - "media": media, - "form": form }) + return redirect(request, + location=media.url_for_self(request.urlgen)) return render_to_response( request, From 8efafec5518f1c603700398449c65be0c7c11d3f Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Tue, 26 Jul 2016 01:50:02 +0000 Subject: [PATCH 40/49] Removed path_subtitle from edit/views.py --- mediagoblin/edit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 17e37c50..69f69da5 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -34,7 +34,7 @@ from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import (require_active_login, active_user_from_url, get_media_entry_by_id, user_may_alter_collection, get_user_collection, user_has_privilege, - user_not_banned, path_subtitle, user_may_delete_media) + user_not_banned, user_may_delete_media) from mediagoblin.tools.crypto import get_timed_signer_url from mediagoblin.tools.metadata import (compact_and_validate, DEFAULT_CHECKER, DEFAULT_SCHEMA) From 05a39583198734b1cc9f6f4d3cba1f7c39fb1410 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Wed, 27 Jul 2016 17:28:56 +0000 Subject: [PATCH 41/49] Checking filename and extension of subtitle uploaded --- mediagoblin/plugins/custom_subtitles/views.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mediagoblin/plugins/custom_subtitles/views.py b/mediagoblin/plugins/custom_subtitles/views.py index 3d75b0ae..36db2e8b 100644 --- a/mediagoblin/plugins/custom_subtitles/views.py +++ b/mediagoblin/plugins/custom_subtitles/views.py @@ -45,6 +45,8 @@ UNSAFE_MIMETYPES = [ @user_may_delete_media @require_active_login def edit_subtitles(request, media): + allowed_extensions = ['aqt','gsub','jss','sub','ttxt','pjs','psb', + 'rt','smi','stl','ssf','srt','ssa','ass','usf','vtt','lrc'] form = forms.EditSubtitlesForm(request.form) # Add any subtitles @@ -58,7 +60,23 @@ def edit_subtitles(request, media): else: public_filename = secure_filename( request.files['subtitle_file'].filename) + filepath = request.files['subtitle_file'].filename + if filepath.count('.') != 1: # Not allowing double extensions or no extensions + messages.add_message( + request, + messages.ERROR, + ("Check the filename")) + return redirect(request, + location=media.url_for_self(request.urlgen)) + elif filepath.split('.')[:-1] not in allowed_extensions : + messages.add_message( + request, + messages.ERROR, + ("Invalid subtitle file")) + + return redirect(request, + location=media.url_for_self(request.urlgen)) subtitle_public_filepath \ = mg_globals.public_store.get_unique_filepath( ['media_entries', six.text_type(media.id), 'subtitle', From 067b1b071abd05a095ec184308cbace4dbab5a47 Mon Sep 17 00:00:00 2001 From: saksham1115 Date: Sat, 30 Jul 2016 18:48:24 +0000 Subject: [PATCH 42/49] Renamed plugin from custom_subtitles to subtitles --- .../__init__.py | 20 +++++++++---------- .../{custom_subtitles => subtitles}/forms.py | 0 .../{custom_subtitles => subtitles}/models.py | 0 .../plugins/subtitles}/custom_subtitles.html | 4 ++-- .../subtitles}/subtitle_media_block.html | 6 +++--- .../plugins/subtitles}/subtitles.html | 2 +- .../{custom_subtitles => subtitles}/tools.py | 0 .../{custom_subtitles => subtitles}/views.py | 8 ++++---- 8 files changed, 20 insertions(+), 20 deletions(-) rename mediagoblin/plugins/{custom_subtitles => subtitles}/__init__.py (64%) rename mediagoblin/plugins/{custom_subtitles => subtitles}/forms.py (100%) rename mediagoblin/plugins/{custom_subtitles => subtitles}/models.py (100%) rename mediagoblin/plugins/{custom_subtitles/templates/mediagoblin/plugins/custom_subtitles => subtitles/templates/mediagoblin/plugins/subtitles}/custom_subtitles.html (94%) rename mediagoblin/plugins/{custom_subtitles/templates/mediagoblin/plugins/custom_subtitles => subtitles/templates/mediagoblin/plugins/subtitles}/subtitle_media_block.html (93%) rename mediagoblin/plugins/{custom_subtitles/templates/mediagoblin/plugins/custom_subtitles => subtitles/templates/mediagoblin/plugins/subtitles}/subtitles.html (96%) rename mediagoblin/plugins/{custom_subtitles => subtitles}/tools.py (100%) rename mediagoblin/plugins/{custom_subtitles => subtitles}/views.py (95%) diff --git a/mediagoblin/plugins/custom_subtitles/__init__.py b/mediagoblin/plugins/subtitles/__init__.py similarity index 64% rename from mediagoblin/plugins/custom_subtitles/__init__.py rename to mediagoblin/plugins/subtitles/__init__.py index f2adc47b..75b0dbc4 100644 --- a/mediagoblin/plugins/custom_subtitles/__init__.py +++ b/mediagoblin/plugins/subtitles/__init__.py @@ -20,18 +20,18 @@ import os PLUGIN_DIR = os.path.dirname(__file__) def setup_plugin(): - config = pluginapi.get_config('mediagoblin.plugins.custom_subtitles') + config = pluginapi.get_config('mediagoblin.plugins.subtitles') routes = [ - ('mediagoblin.plugins.custom_subtitles.customize', + ('mediagoblin.plugins.subtitles.customize', '/u//m//customize/', - 'mediagoblin.plugins.custom_subtitles.views:custom_subtitles'), - ('mediagoblin.plugins.custom_subtitles.subtitles', + 'mediagoblin.plugins.subtitles.views:custom_subtitles'), + ('mediagoblin.plugins.subtitles.subtitles', '/u//m//subtitles/', - 'mediagoblin.plugins.custom_subtitles.views:edit_subtitles'), - ('mediagoblin.plugins.custom_subtitles.delete_subtitles', + 'mediagoblin.plugins.subtitles.views:edit_subtitles'), + ('mediagoblin.plugins.subtitles.delete_subtitles', '/u//m//delete/', - 'mediagoblin.plugins.custom_subtitles.views:delete_subtitles')] + 'mediagoblin.plugins.subtitles.views:delete_subtitles')] pluginapi.register_routes(routes) @@ -39,9 +39,9 @@ def setup_plugin(): pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) pluginapi.register_template_hooks( - {"customize_subtitles": "mediagoblin/plugins/custom_subtitles/custom_subtitles.html", - "add_subtitles": "mediagoblin/plugins/custom_subtitles/subtitles.html", - "subtitle_sidebar": "mediagoblin/plugins/custom_subtitles/subtitle_media_block.html"}) + {"customize_subtitles": "mediagoblin/plugins/subtitles/custom_subtitles.html", + "add_subtitles": "mediagoblin/plugins/subtitles/subtitles.html", + "subtitle_sidebar": "mediagoblin/plugins/subtitles/subtitle_media_block.html"}) diff --git a/mediagoblin/plugins/custom_subtitles/forms.py b/mediagoblin/plugins/subtitles/forms.py similarity index 100% rename from mediagoblin/plugins/custom_subtitles/forms.py rename to mediagoblin/plugins/subtitles/forms.py diff --git a/mediagoblin/plugins/custom_subtitles/models.py b/mediagoblin/plugins/subtitles/models.py similarity index 100% rename from mediagoblin/plugins/custom_subtitles/models.py rename to mediagoblin/plugins/subtitles/models.py diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html similarity index 94% rename from mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html rename to mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html index e1975c75..2184b85e 100644 --- a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/custom_subtitles.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/custom_subtitles.html @@ -28,14 +28,14 @@ request.staticdirect('/css/subtitles.css') }}" rel="stylesheet"> -
    {{ wtforms_util.render_divs(form) }}
    - {% set delete_url = request.urlgen('mediagoblin.plugins.custom_subtitles.delete_subtitles', + {% set delete_url = request.urlgen('mediagoblin.plugins.subtitles.delete_subtitles', user= media.get_actor.username, media_id=media.id, path=path) %} diff --git a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html similarity index 93% rename from mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html rename to mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html index 3e6bf886..b516655a 100644 --- a/mediagoblin/plugins/custom_subtitles/templates/mediagoblin/plugins/custom_subtitles/subtitle_media_block.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html @@ -23,7 +23,7 @@
    -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html index fd0fd24e..34c9c16f 100644 --- a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitle_media_block.html @@ -1,6 +1,6 @@ {# # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2016 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -47,4 +47,4 @@

    {%- endif %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitles.html b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitles.html index cf689eed..5b249403 100644 --- a/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitles.html +++ b/mediagoblin/plugins/subtitles/templates/mediagoblin/plugins/subtitles/subtitles.html @@ -1,6 +1,6 @@ {# # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2016 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by diff --git a/mediagoblin/plugins/subtitles/tools.py b/mediagoblin/plugins/subtitles/tools.py index 735c89b2..43f5bd6a 100644 --- a/mediagoblin/plugins/subtitles/tools.py +++ b/mediagoblin/plugins/subtitles/tools.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2016 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by diff --git a/mediagoblin/plugins/subtitles/views.py b/mediagoblin/plugins/subtitles/views.py index 338ba859..7d41a36d 100644 --- a/mediagoblin/plugins/subtitles/views.py +++ b/mediagoblin/plugins/subtitles/views.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2016 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by