aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r--mediagoblin/tools/exif.py25
-rw-r--r--mediagoblin/tools/files.py7
-rw-r--r--mediagoblin/tools/licenses.py37
-rw-r--r--mediagoblin/tools/subtitles.py20
-rw-r--r--mediagoblin/tools/validator.py26
5 files changed, 76 insertions, 39 deletions
diff --git a/mediagoblin/tools/exif.py b/mediagoblin/tools/exif.py
index fafd987d..2215fb0c 100644
--- a/mediagoblin/tools/exif.py
+++ b/mediagoblin/tools/exif.py
@@ -19,6 +19,11 @@ import six
from exifread import process_file
from exifread.utils import Ratio
+try:
+ from PIL import Image
+except ImportError:
+ import Image
+
from mediagoblin.processing import BadMediaFail
from mediagoblin.tools.translate import pass_to_ugettext as _
@@ -61,12 +66,12 @@ def exif_fix_image_orientation(im, exif_tags):
# Rotate image
if 'Image Orientation' in exif_tags:
rotation_map = {
- 3: 180,
- 6: 270,
- 8: 90}
+ 3: Image.ROTATE_180,
+ 6: Image.ROTATE_270,
+ 8: Image.ROTATE_90}
orientation = exif_tags['Image Orientation'].values[0]
if orientation in rotation_map:
- im = im.rotate(
+ im = im.transpose(
rotation_map[orientation])
return im
@@ -175,18 +180,14 @@ def get_gps_data(tags):
pass
try:
- gps_data['direction'] = (
- lambda d:
- float(d.num) / float(d.den)
- )(tags['GPS GPSImgDirection'].values[0])
+ direction = tags['GPS GPSImgDirection'].values[0]
+ gps_data['direction'] = safe_gps_ratio_divide(direction)
except KeyError:
pass
try:
- gps_data['altitude'] = (
- lambda a:
- float(a.num) / float(a.den)
- )(tags['GPS GPSAltitude'].values[0])
+ altitude = tags['GPS GPSAltitude'].values[0]
+ gps_data['altitude'] = safe_gps_ratio_divide(altitude)
except KeyError:
pass
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/tools/licenses.py b/mediagoblin/tools/licenses.py
index a964980e..2aff7f20 100644
--- a/mediagoblin/tools/licenses.py
+++ b/mediagoblin/tools/licenses.py
@@ -20,28 +20,45 @@ License = namedtuple("License", ["abbreviation", "name", "uri"])
SORTED_LICENSES = [
License("All rights reserved", "No license specified", ""),
+ License("CC BY 4.0", "Creative Commons Attribution 4.0 International",
+ "https://creativecommons.org/licenses/by/4.0/"),
+ License("CC BY-SA 4.0",
+ "Creative Commons Attribution-ShareAlike 4.0 International",
+ "https://creativecommons.org/licenses/by-sa/4.0/"),
+ License("CC BY-ND 4.0",
+ "Creative Commons Attribution-NoDerivs 4.0 International",
+ "https://creativecommons.org/licenses/by-nd/4.0/"),
+ License("CC BY-NC 4.0",
+ "Creative Commons Attribution-NonCommercial 4.0 International",
+ "https://creativecommons.org/licenses/by-nc/4.0/"),
+ License("CC BY-NC-SA 4.0",
+ "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International",
+ "https://creativecommons.org/licenses/by-nc-sa/4.0/"),
+ License("CC BY-NC-ND 4.0",
+ "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International",
+ "https://creativecommons.org/licenses/by-nc-nd/4.0/"),
License("CC BY 3.0", "Creative Commons Attribution Unported 3.0",
- "http://creativecommons.org/licenses/by/3.0/"),
+ "https://creativecommons.org/licenses/by/3.0/"),
License("CC BY-SA 3.0",
- "Creative Commons Attribution-ShareAlike Unported 3.0",
- "http://creativecommons.org/licenses/by-sa/3.0/"),
+ "Creative Commons Attribution-ShareAlike 3.0 Unported",
+ "https://creativecommons.org/licenses/by-sa/3.0/"),
License("CC BY-ND 3.0",
"Creative Commons Attribution-NoDerivs 3.0 Unported",
- "http://creativecommons.org/licenses/by-nd/3.0/"),
+ "https://creativecommons.org/licenses/by-nd/3.0/"),
License("CC BY-NC 3.0",
- "Creative Commons Attribution-NonCommercial Unported 3.0",
- "http://creativecommons.org/licenses/by-nc/3.0/"),
+ "Creative Commons Attribution-NonCommercial 3.0 Unported",
+ "https://creativecommons.org/licenses/by-nc/3.0/"),
License("CC BY-NC-SA 3.0",
"Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported",
- "http://creativecommons.org/licenses/by-nc-sa/3.0/"),
+ "https://creativecommons.org/licenses/by-nc-sa/3.0/"),
License("CC BY-NC-ND 3.0",
"Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported",
- "http://creativecommons.org/licenses/by-nc-nd/3.0/"),
+ "https://creativecommons.org/licenses/by-nc-nd/3.0/"),
License("CC0 1.0",
"Creative Commons CC0 1.0 Universal",
- "http://creativecommons.org/publicdomain/zero/1.0/"),
+ "https://creativecommons.org/publicdomain/zero/1.0/"),
License("Public Domain","Public Domain",
- "http://creativecommons.org/publicdomain/mark/1.0/"),
+ "https://creativecommons.org/publicdomain/mark/1.0/"),
]
# dict {uri: License,...} to enable fast license lookup by uri. Ideally,
diff --git a/mediagoblin/tools/subtitles.py b/mediagoblin/tools/subtitles.py
new file mode 100644
index 00000000..efafbeec
--- /dev/null
+++ b/mediagoblin/tools/subtitles.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
diff --git a/mediagoblin/tools/validator.py b/mediagoblin/tools/validator.py
index 03598f9c..93296eab 100644
--- a/mediagoblin/tools/validator.py
+++ b/mediagoblin/tools/validator.py
@@ -14,21 +14,15 @@
# 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 wtforms.validators import Email, URL
+from six.moves.urllib.parse import urlparse
def validate_email(email):
- """
- Validates an email
-
- Returns True if valid and False if invalid
"""
+ Validates an email
- email_re = Email().regex
- result = email_re.match(email)
- if result is None:
- return False
- else:
- return result.string
+ Returns True if valid and False if invalid
+ """
+ return '@' in email
def validate_url(url):
"""
@@ -36,11 +30,9 @@ def validate_url(url):
Returns True if valid and False if invalid
"""
-
- url_re = URL().regex
- result = url_re.match(url)
- if result is None:
+ try:
+ urlparse(url)
+ return True
+ except Exception as e:
return False
- else:
- return result.string