Commit | Line | Data |
---|---|---|
5c754fda JW |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. | |
3 | # | |
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. | |
8 | # | |
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. | |
13 | # | |
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/>. | |
16 | ||
17 | import logging | |
18 | ||
19 | from mediagoblin import mg_globals as mgg | |
20 | ||
f7e1bfea | 21 | ACCEPTED_RESOLUTIONS = { |
22 | '144p' : (256, 144), | |
23 | '240p' : (352, 240), | |
24 | '360p' : (480, 360), | |
25 | '480p' : (858, 480), | |
26 | '720p' : (1280, 720), | |
27 | '1080p' : (1920, 1080), | |
28 | } | |
29 | ||
5c754fda JW |
30 | _log = logging.getLogger(__name__) |
31 | ||
32 | ||
8bb0df62 | 33 | def skip_transcode(metadata, size): |
5c754fda JW |
34 | ''' |
35 | Checks video metadata against configuration values for skip_transcode. | |
36 | ||
37 | Returns True if the video matches the requirements in the configuration. | |
38 | ''' | |
9a6741d7 | 39 | config = mgg.global_config['plugins']['mediagoblin.media_types.video']\ |
5c754fda JW |
40 | ['skip_transcode'] |
41 | ||
fec916df | 42 | # XXX: how were we supposed to use it? |
5c754fda JW |
43 | medium_config = mgg.global_config['media:medium'] |
44 | ||
45 | _log.debug('skip_transcode config: {0}'.format(config)) | |
fec916df | 46 | |
86dc32bc BB |
47 | metadata_tags = metadata.get_tags() |
48 | if not metadata_tags: | |
fec916df BB |
49 | return False |
50 | ||
86dc32bc BB |
51 | if config['mime_types'] and metadata_tags.get_string('mimetype')[0]: |
52 | if not metadata_tags.get_string('mimetype')[1] in config['mime_types']: | |
5c754fda JW |
53 | return False |
54 | ||
86dc32bc BB |
55 | if (config['container_formats'] and |
56 | metadata_tags.get_string('container-format')[0]): | |
57 | if not (metadata_tags.get_string('container-format')[1] in | |
91f5f5e7 | 58 | config['container_formats']): |
5c754fda JW |
59 | return False |
60 | ||
2d1e8905 BB |
61 | if config['video_codecs']: |
62 | for video_info in metadata.get_video_streams(): | |
86dc32bc BB |
63 | video_tags = video_info.get_tags() |
64 | if not video_tags: | |
65 | return False | |
66 | if not (video_tags.get_string('video-codec')[1] in | |
2d1e8905 BB |
67 | config['video_codecs']): |
68 | return False | |
5c754fda | 69 | |
2d1e8905 BB |
70 | if config['audio_codecs']: |
71 | for audio_info in metadata.get_audio_streams(): | |
86dc32bc BB |
72 | audio_tags = audio_info.get_tags() |
73 | if not audio_tags: | |
74 | return False | |
75 | if not (audio_tags.get_string('audio-codec')[1] in | |
2d1e8905 BB |
76 | config['audio_codecs']): |
77 | return False | |
5c754fda JW |
78 | |
79 | if config['dimensions_match']: | |
2d1e8905 BB |
80 | for video_info in metadata.get_video_streams(): |
81 | if not video_info.get_height() <= size[1]: | |
82 | return False | |
83 | if not video_info.get_width() <= size[0]: | |
84 | return False | |
5c754fda JW |
85 | |
86 | return True |