aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/media_types
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2012-02-18 10:01:47 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2012-02-18 10:01:47 -0600
commit63352aaf70d97a37b6277fab0f9b957d34dcb9df (patch)
treeacdedffc204d89f1f71f09696270e5719f5e3123 /mediagoblin/media_types
parent7f3ec607a34e727324397c2bf240f771b12a0455 (diff)
parentfeba5c5287a7cb4c0ed8f5124ad60a8a291770ad (diff)
downloadmediagoblin-63352aaf70d97a37b6277fab0f9b957d34dcb9df.tar.lz
mediagoblin-63352aaf70d97a37b6277fab0f9b957d34dcb9df.tar.xz
mediagoblin-63352aaf70d97a37b6277fab0f9b957d34dcb9df.zip
Merge branch 'master' into sqlmigrate
Conflicts: mediagoblin/db/sql/models.py
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r--mediagoblin/media_types/__init__.py2
-rw-r--r--mediagoblin/media_types/ascii/__init__.py4
-rw-r--r--mediagoblin/media_types/ascii/asciitoimage.py39
-rw-r--r--mediagoblin/media_types/ascii/processing.py27
-rw-r--r--mediagoblin/media_types/image/__init__.py2
-rw-r--r--mediagoblin/media_types/image/processing.py2
-rw-r--r--mediagoblin/media_types/video/__init__.py2
-rw-r--r--mediagoblin/media_types/video/processing.py2
-rw-r--r--mediagoblin/media_types/video/transcoders.py2
9 files changed, 43 insertions, 39 deletions
diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py
index e7eb1dde..5128826b 100644
--- a/mediagoblin/media_types/__init__.py
+++ b/mediagoblin/media_types/__init__.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
diff --git a/mediagoblin/media_types/ascii/__init__.py b/mediagoblin/media_types/ascii/__init__.py
index 21b31d0e..1c8ca562 100644
--- a/mediagoblin/media_types/ascii/__init__.py
+++ b/mediagoblin/media_types/ascii/__init__.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
@@ -24,4 +24,4 @@ MEDIA_MANAGER = {
"display_template": "mediagoblin/media_displays/ascii.html",
"default_thumb": "images/media_thumbs/ascii.jpg",
"accepted_extensions": [
- "txt"]}
+ "txt", "asc", "nfo"]}
diff --git a/mediagoblin/media_types/ascii/asciitoimage.py b/mediagoblin/media_types/ascii/asciitoimage.py
index 39c75a19..e1c4fb44 100644
--- a/mediagoblin/media_types/ascii/asciitoimage.py
+++ b/mediagoblin/media_types/ascii/asciitoimage.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
@@ -59,13 +59,14 @@ class AsciiToImage(object):
if kw.get('font_size'):
self._font_size = kw.get('font_size')
- _log.info('Setting font to {0}, size {1}'.format(
- self._font,
- self._font_size))
-
self._if = ImageFont.truetype(
self._font,
- self._font_size)
+ self._font_size,
+ encoding='unic')
+
+ _log.info('Font set to {0}, size {1}'.format(
+ self._font,
+ self._font_size))
# ,-,-^-'-^'^-^'^-'^-.
# ( I am a wall socket )Oo, ___
@@ -91,6 +92,10 @@ class AsciiToImage(object):
- Character set detection and decoding,
http://pypi.python.org/pypi/chardet
'''
+ _log.debug('Drawing image')
+ # Convert the input from str to unicode
+ text = text.decode('utf-8')
+
# TODO: Account for alternative line endings
lines = text.split('\n')
@@ -123,8 +128,8 @@ class AsciiToImage(object):
px_pos = self._px_pos(char_pos)
- _log.debug('Writing character "{0}" at {1} (px pos {2}'.format(
- char,
+ _log.debug('Writing character "{0}" at {1} (px pos {2})'.format(
+ char.encode('ascii', 'replace'),
char_pos,
px_pos))
@@ -152,21 +157,3 @@ class AsciiToImage(object):
px_pos[index] = char_pos[index] * self._if_dims[index]
return px_pos
-
-
-if __name__ == "__main__":
- import urllib
- txt = urllib.urlopen('file:///home/joar/Dropbox/ascii/install-all-the-dependencies.txt')
-
- _log.setLevel(logging.DEBUG)
- logging.basicConfig()
-
- converter = AsciiToImage()
-
- converter.convert(txt.read(), '/tmp/test.png')
-
- '''
- im, x, y, duration = renderImage(h, 10)
- print "Rendered image in %.5f seconds" % duration
- im.save('tldr.png', "PNG")
- '''
diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py
index a74690c1..7ece866e 100644
--- a/mediagoblin/media_types/ascii/processing.py
+++ b/mediagoblin/media_types/ascii/processing.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
@@ -13,14 +13,16 @@
#
# 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/>.
-import asciitoimage
import chardet
import os
import Image
+import logging
from mediagoblin import mg_globals as mgg
from mediagoblin.processing import create_pub_filepath, THUMB_SIZE
+from mediagoblin.media_types.ascii import asciitoimage
+_log = logging.getLogger(__name__)
def process_ascii(entry):
'''
@@ -42,6 +44,17 @@ def process_ascii(entry):
with queued_file:
queued_file_charset = chardet.detect(queued_file.read())
+ # Only select a non-utf-8 charset if chardet is *really* sure
+ # Tested with "Feli\x0109an superjaron", which was detecte
+ if queued_file_charset['confidence'] < 0.9:
+ interpreted_charset = 'utf-8'
+ else:
+ interpreted_charset = queued_file_charset['encoding']
+
+ _log.info('Charset detected: {0}\nWill interpret as: {1}'.format(
+ queued_file_charset,
+ interpreted_charset))
+
queued_file.seek(0) # Rewind the queued file
thumb_filepath = create_pub_filepath(
@@ -59,6 +72,7 @@ def process_ascii(entry):
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
thumb.save(thumb_file)
+ _log.debug('Copying local file to public storage')
mgg.public_store.copy_local_to_storage(
tmp_thumb_filename, thumb_filepath)
@@ -73,13 +87,16 @@ def process_ascii(entry):
queued_file.seek(0) # Rewind *again*
- unicode_filepath = create_pub_filepath(entry, 'unicode.txt')
+ unicode_filepath = create_pub_filepath(entry, 'ascii-portable.txt')
with mgg.public_store.get_file(unicode_filepath, 'wb') \
as unicode_file:
+ # Decode the original file from its detected charset (or UTF8)
+ # Encode the unicode instance to ASCII and replace any non-ASCII
+ # with an HTML entity (&#
unicode_file.write(
- unicode(queued_file.read().decode(
- queued_file_charset['encoding'])).encode(
+ unicode(queued_file.read().decode(
+ interpreted_charset)).encode(
'ascii',
'xmlcharrefreplace'))
diff --git a/mediagoblin/media_types/image/__init__.py b/mediagoblin/media_types/image/__init__.py
index 3b63d8eb..98e0c32a 100644
--- a/mediagoblin/media_types/image/__init__.py
+++ b/mediagoblin/media_types/image/__init__.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py
index 78f64be0..769de89b 100644
--- a/mediagoblin/media_types/image/processing.py
+++ b/mediagoblin/media_types/image/processing.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
diff --git a/mediagoblin/media_types/video/__init__.py b/mediagoblin/media_types/video/__init__.py
index a970ab01..ed542f16 100644
--- a/mediagoblin/media_types/video/__init__.py
+++ b/mediagoblin/media_types/video/__init__.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py
index 49a50647..9dc23c55 100644
--- a/mediagoblin/media_types/video/processing.py
+++ b/mediagoblin/media_types/video/processing.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py
index 7071b887..6137c3bf 100644
--- a/mediagoblin/media_types/video/transcoders.py
+++ b/mediagoblin/media_types/video/transcoders.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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