+# 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 <http://www.gnu.org/licenses/>.
+
+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
@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",
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