From cf29e8a824e0ef4612f1144f079c80c1d20b89e5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 2 Feb 2012 09:44:13 -0600 Subject: It's 2012 all up in here --- mediagoblin/media_types/__init__.py | 2 +- mediagoblin/media_types/ascii/__init__.py | 2 +- mediagoblin/media_types/ascii/asciitoimage.py | 2 +- mediagoblin/media_types/ascii/processing.py | 2 +- mediagoblin/media_types/image/__init__.py | 2 +- mediagoblin/media_types/image/processing.py | 2 +- mediagoblin/media_types/video/__init__.py | 2 +- mediagoblin/media_types/video/processing.py | 2 +- mediagoblin/media_types/video/transcoders.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'mediagoblin/media_types') 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..e54427b1 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 diff --git a/mediagoblin/media_types/ascii/asciitoimage.py b/mediagoblin/media_types/ascii/asciitoimage.py index 39c75a19..da1a3bcc 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 diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index a74690c1..ec530df6 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 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 -- cgit v1.2.3 From 3f1dc64ed15a8f1f9141338561028efc6758bdf2 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 2 Feb 2012 19:54:47 +0100 Subject: Added extensions 'asc' and 'nfo' to ASCII media type --- mediagoblin/media_types/ascii/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/media_types') diff --git a/mediagoblin/media_types/ascii/__init__.py b/mediagoblin/media_types/ascii/__init__.py index e54427b1..1c8ca562 100644 --- a/mediagoblin/media_types/ascii/__init__.py +++ b/mediagoblin/media_types/ascii/__init__.py @@ -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"]} -- cgit v1.2.3 From 010d28b4f0a39103949692209106a1b47fceeaf2 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 2 Feb 2012 21:28:21 +0100 Subject: ASCII art support - Fixes - Improved(?) character set detection, chardet will not win over UTF-8 unless it is >= 90% sure. - Changed the unicode.txt to ascii-portable.txt, since there is no unicode in the file. - etc. --- mediagoblin/media_types/ascii/asciitoimage.py | 26 ++++++-------------------- mediagoblin/media_types/ascii/processing.py | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 23 deletions(-) (limited to 'mediagoblin/media_types') diff --git a/mediagoblin/media_types/ascii/asciitoimage.py b/mediagoblin/media_types/ascii/asciitoimage.py index da1a3bcc..186d8066 100644 --- a/mediagoblin/media_types/ascii/asciitoimage.py +++ b/mediagoblin/media_types/ascii/asciitoimage.py @@ -65,7 +65,8 @@ class AsciiToImage(object): self._if = ImageFont.truetype( self._font, - self._font_size) + self._font_size, + encoding='unic') # ,-,-^-'-^'^-^'^-'^-. # ( I am a wall socket )Oo, ___ @@ -91,6 +92,9 @@ class AsciiToImage(object): - Character set detection and decoding, http://pypi.python.org/pypi/chardet ''' + # Convert the input from str to unicode + text = text.decode('utf-8') + # TODO: Account for alternative line endings lines = text.split('\n') @@ -123,7 +127,7 @@ class AsciiToImage(object): px_pos = self._px_pos(char_pos) - _log.debug('Writing character "{0}" at {1} (px pos {2}'.format( + _log.debug('Writing character "{0}" at {1} (px pos {2})'.format( char, char_pos, px_pos)) @@ -152,21 +156,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 ec530df6..96dfce80 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -17,10 +17,12 @@ 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 +_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( @@ -73,13 +86,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')) -- cgit v1.2.3 From 64da09e86a755e49832e3c324582c65d352632d4 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Sat, 4 Feb 2012 20:51:05 +0100 Subject: ASCII media support - Fixes - Added debug logging in - mediagoblin.processing - mediagoblin.media_types.ascii.processing - mediagoblin.media_types.ascii.asciitoimage --- mediagoblin/media_types/ascii/asciitoimage.py | 11 ++++++----- mediagoblin/media_types/ascii/processing.py | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'mediagoblin/media_types') diff --git a/mediagoblin/media_types/ascii/asciitoimage.py b/mediagoblin/media_types/ascii/asciitoimage.py index 186d8066..e1c4fb44 100644 --- a/mediagoblin/media_types/ascii/asciitoimage.py +++ b/mediagoblin/media_types/ascii/asciitoimage.py @@ -59,15 +59,15 @@ 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, encoding='unic') + _log.info('Font set to {0}, size {1}'.format( + self._font, + self._font_size)) + # ,-,-^-'-^'^-^'^-'^-. # ( I am a wall socket )Oo, ___ # `-.,.-.,.-.-.,.-.--' ' ` @@ -92,6 +92,7 @@ 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') @@ -128,7 +129,7 @@ class AsciiToImage(object): px_pos = self._px_pos(char_pos) _log.debug('Writing character "{0}" at {1} (px pos {2})'.format( - char, + char.encode('ascii', 'replace'), char_pos, px_pos)) diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index 96dfce80..837b9830 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -72,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) -- cgit v1.2.3 From c2dfe1dd4090ef40eeb615d09c4607e6d5853994 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 8 Feb 2012 09:29:24 -0600 Subject: Fully qualify the import of asciitoimage --- mediagoblin/media_types/ascii/processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/media_types') diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index 837b9830..7ece866e 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -13,7 +13,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import asciitoimage import chardet import os import Image @@ -21,6 +20,7 @@ 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__) -- cgit v1.2.3