from mediagoblin.media_types import MediaManagerBase
from mediagoblin.media_types.pdf.processing import process_pdf, \
sniff_handler
+from mediagoblin.tools import pluginapi
+
+ACCEPTED_EXTENSIONS = ['pdf']
+MEDIA_TYPE = 'mediagoblin.media_types.pdf'
+
+
+def setup_plugin():
+ config = pluginapi.get_config(MEDIA_TYPE)
class PDFMediaManager(MediaManagerBase):
human_readable = "PDF"
processor = staticmethod(process_pdf)
- sniff_handler = staticmethod(sniff_handler)
display_template = "mediagoblin/media_displays/pdf.html"
default_thumb = "images/media_thumbs/pdf.jpg"
- accepted_extensions = ["pdf"]
-MEDIA_MANAGER = PDFMediaManager
+def get_media_manager(media_type):
+ if media_type == MEDIA_TYPE:
+ return PDFMediaManager
+
+
+def get_media_type_and_manager(ext):
+ if ext in ACCEPTED_EXTENSIONS:
+ return MEDIA_TYPE, PDFMediaManager
+
+hooks = {
+ 'setup': setup_plugin,
+ 'get_media_type_and_manager': get_media_type_and_manager,
+ 'sniff_handler': sniff_handler,
+ 'get_media_manager': get_media_manager,
+}
_log = logging.getLogger(__name__)
+MEDIA_TYPE = 'mediagoblin.media_types.pdf'
+
# TODO - cache (memoize) util
# This is a list created via uniconv --show and hand removing some types that
return True
def sniff_handler(media_file, **kw):
+ _log.info('Sniffing {0}'.format(MEDIA_TYPE))
if not check_prerequisites():
- return False
+ return None
if kw.get('media') is not None:
name, ext = os.path.splitext(kw['media'].filename)
clean_ext = ext[1:].lower()
if clean_ext in supported_extensions():
- return True
+ return MEDIA_TYPE
- return False
+ return None
def create_pdf_thumb(original, thumb_filename, width, height):
# Note: pdftocairo adds '.png', remove it