Setting 0.8.2.dev in configure.ac as well
[larjonas-mediagoblin.git] / mediagoblin / media_types / video / util.py
blobd3d292794369be9c8ba3d0b8fe02b61069f9eee3
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 import logging
19 from mediagoblin import mg_globals as mgg
21 _log = logging.getLogger(__name__)
24 def skip_transcode(metadata, size):
25 '''
26 Checks video metadata against configuration values for skip_transcode.
28 Returns True if the video matches the requirements in the configuration.
29 '''
30 config = mgg.global_config['plugins']['mediagoblin.media_types.video']\
31 ['skip_transcode']
33 medium_config = mgg.global_config['media:medium']
35 _log.debug('skip_transcode config: {0}'.format(config))
36 tags = metadata.get_tags()
37 if config['mime_types'] and tags.get_string('mimetype')[0]:
38 if not tags.get_string('mimetype')[1] in config['mime_types']:
39 return False
41 if config['container_formats'] and tags.get_string('container-format')[0]:
42 if not (tags.get_string('container-format')[1] in
43 config['container_formats']):
44 return False
46 if config['video_codecs']:
47 for video_info in metadata.get_video_streams():
48 if not (video_info.get_tags().get_string('video-codec')[1] in
49 config['video_codecs']):
50 return False
52 if config['audio_codecs']:
53 for audio_info in metadata.get_audio_streams():
54 if not (audio_info.get_tags().get_string('audio-codec')[1] in
55 config['audio_codecs']):
56 return False
58 if config['dimensions_match']:
59 for video_info in metadata.get_video_streams():
60 if not video_info.get_height() <= size[1]:
61 return False
62 if not video_info.get_width() <= size[0]:
63 return False
65 return True