converted video media_type to plugin
This commit is contained in:
parent
239296b004
commit
cbac4a7fc9
@ -17,20 +17,40 @@
|
|||||||
from mediagoblin.media_types import MediaManagerBase
|
from mediagoblin.media_types import MediaManagerBase
|
||||||
from mediagoblin.media_types.video.processing import process_video, \
|
from mediagoblin.media_types.video.processing import process_video, \
|
||||||
sniff_handler
|
sniff_handler
|
||||||
|
from mediagoblin.tools import pluginapi
|
||||||
|
|
||||||
|
MEDIA_TYPE = 'mediagoblin.media_types.video'
|
||||||
|
ACCEPTED_EXTENSIONS = [
|
||||||
|
"mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"]
|
||||||
|
|
||||||
|
|
||||||
|
def setup_plugin():
|
||||||
|
config = pluginapi.get_config(MEDIA_TYPE)
|
||||||
|
|
||||||
|
|
||||||
class VideoMediaManager(MediaManagerBase):
|
class VideoMediaManager(MediaManagerBase):
|
||||||
human_readable = "Video"
|
human_readable = "Video"
|
||||||
processor = staticmethod(process_video)
|
processor = staticmethod(process_video)
|
||||||
sniff_handler = staticmethod(sniff_handler)
|
|
||||||
display_template = "mediagoblin/media_displays/video.html"
|
display_template = "mediagoblin/media_displays/video.html"
|
||||||
default_thumb = "images/media_thumbs/video.jpg"
|
default_thumb = "images/media_thumbs/video.jpg"
|
||||||
accepted_extensions = [
|
|
||||||
"mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"]
|
|
||||||
|
|
||||||
# Used by the media_entry.get_display_media method
|
# Used by the media_entry.get_display_media method
|
||||||
media_fetch_order = [u'webm_640', u'original']
|
media_fetch_order = [u'webm_640', u'original']
|
||||||
default_webm_type = 'video/webm; codecs="vp8, vorbis"'
|
default_webm_type = 'video/webm; codecs="vp8, vorbis"'
|
||||||
|
|
||||||
|
|
||||||
MEDIA_MANAGER = VideoMediaManager
|
def get_media_manager(media_type):
|
||||||
|
if media_type == MEDIA_TYPE:
|
||||||
|
return VideoMediaManager
|
||||||
|
|
||||||
|
|
||||||
|
def get_media_type_and_manager(ext):
|
||||||
|
if ext in ACCEPTED_EXTENSIONS:
|
||||||
|
return MEDIA_TYPE, VideoMediaManager
|
||||||
|
|
||||||
|
hooks = {
|
||||||
|
'setup': setup_plugin,
|
||||||
|
'get_media_type_and_manager': get_media_type_and_manager,
|
||||||
|
'sniff_handler': sniff_handler,
|
||||||
|
'get_media_manager': get_media_manager,
|
||||||
|
}
|
||||||
|
@ -29,6 +29,8 @@ from .util import skip_transcode
|
|||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
_log.setLevel(logging.DEBUG)
|
_log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
MEDIA_TYPE = 'mediagoblin.media_types.video'
|
||||||
|
|
||||||
|
|
||||||
class VideoTranscodingFail(BaseProcessingFail):
|
class VideoTranscodingFail(BaseProcessingFail):
|
||||||
'''
|
'''
|
||||||
@ -41,17 +43,18 @@ def sniff_handler(media_file, **kw):
|
|||||||
transcoder = transcoders.VideoTranscoder()
|
transcoder = transcoders.VideoTranscoder()
|
||||||
data = transcoder.discover(media_file.name)
|
data = transcoder.discover(media_file.name)
|
||||||
|
|
||||||
|
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
|
||||||
_log.debug('Discovered: {0}'.format(data))
|
_log.debug('Discovered: {0}'.format(data))
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
_log.error('Could not discover {0}'.format(
|
_log.error('Could not discover {0}'.format(
|
||||||
kw.get('media')))
|
kw.get('media')))
|
||||||
return False
|
return None
|
||||||
|
|
||||||
if data['is_video'] == True:
|
if data['is_video'] == True:
|
||||||
return True
|
return MEDIA_TYPE
|
||||||
|
|
||||||
return False
|
return None
|
||||||
|
|
||||||
|
|
||||||
def process_video(proc_state):
|
def process_video(proc_state):
|
||||||
@ -186,7 +189,7 @@ def store_metadata(media_entry, metadata):
|
|||||||
[(key, tags_metadata[key])
|
[(key, tags_metadata[key])
|
||||||
for key in [
|
for key in [
|
||||||
"application-name", "artist", "audio-codec", "bitrate",
|
"application-name", "artist", "audio-codec", "bitrate",
|
||||||
"container-format", "copyright", "encoder",
|
"container-format", "copyright", "encoder",
|
||||||
"encoder-version", "license", "nominal-bitrate", "title",
|
"encoder-version", "license", "nominal-bitrate", "title",
|
||||||
"video-codec"]
|
"video-codec"]
|
||||||
if key in tags_metadata])
|
if key in tags_metadata])
|
||||||
@ -203,7 +206,7 @@ def store_metadata(media_entry, metadata):
|
|||||||
dt.get_year(), dt.get_month(), dt.get_day(), dt.get_hour(),
|
dt.get_year(), dt.get_month(), dt.get_day(), dt.get_hour(),
|
||||||
dt.get_minute(), dt.get_second(),
|
dt.get_minute(), dt.get_second(),
|
||||||
dt.get_microsecond()).isoformat()
|
dt.get_microsecond()).isoformat()
|
||||||
|
|
||||||
metadata['tags'] = tags
|
metadata['tags'] = tags
|
||||||
|
|
||||||
# Only save this field if there's something to save
|
# Only save this field if there's something to save
|
||||||
|
Loading…
x
Reference in New Issue
Block a user