Merge lp:~david4dev/dmedia/constants-from-mimetypes into lp:dmedia

Proposed by David Green
Status: Merged
Merged at revision: 120
Proposed branch: lp:~david4dev/dmedia/constants-from-mimetypes
Merge into: lp:dmedia
Diff against target: 60 lines (+21/-14)
1 file modified
dmedialib/constants.py (+21/-14)
To merge this branch: bzr merge lp:~david4dev/dmedia/constants-from-mimetypes
Reviewer Review Type Date Requested Status
Jason Gerard DeRose Approve
Review via email: mp+42015@code.launchpad.net

Description of the change

This change generates the constants VIDEO, AUDIO and IMAGE using the mimetypes module to get the details.

To post a comment you must log in.
Revision history for this message
Jason Gerard DeRose (jderose) wrote :

Thanks, David, much better than what I was doing.

Down the road we should probably move this out of constants.py as this something dynamically built when the module loads, will affect startup time slightly. I want importing client.py to have as few dependencies/resources as possible, and client.py imports constants.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dmedialib/constants.py'
2--- dmedialib/constants.py 2010-11-27 03:40:39 +0000
3+++ dmedialib/constants.py 2010-11-27 15:36:09 +0000
4@@ -1,5 +1,6 @@
5 # Authors:
6 # Jason Gerard DeRose <jderose@novacut.com>
7+# David Green <david4dev@gmail.com>
8 #
9 # dmedia: distributed media library
10 # Copyright (C) 2010 Jason Gerard DeRose <jderose@novacut.com>
11@@ -23,25 +24,29 @@
12 Various constants conveniently located in one place.
13 """
14
15+import mimetypes
16+mimetypes.init()
17+
18+
19 BUS = 'org.freedesktop.DMedia'
20 INTERFACE = 'org.freedesktop.DMedia'
21
22 TYPE_ERROR = '%s: need a %r; got a %r: %r' # Standard TypeError message
23
24-
25-VIDEO = (
26- 'ogv', # video/ogg
27- 'webm', # video/webm
28- 'mov', 'qt', # video/quicktime
29- 'mp4', # video/mp4
30- 'mpeg', 'mpg', 'mpe', # video/mpeg
31- 'avi', # video/x-msvideo
32- 'mpv', 'mkv', # video/x-matroska
33-)
34-
35-AUDIO = ('wav', 'oga', 'flac', 'spx', 'mp3')
36-
37-IMAGE = ('jpg', 'png', 'cr2', 'crw', 'nef')
38+def get_extensions_for_type(general_type):
39+ """
40+ An iterator that yields the file extensions for files of a general type.
41+ eg. 'image'
42+ """
43+ for ext in mimetypes.types_map:
44+ if mimetypes.types_map[ext].split('/')[0] == general_type:
45+ yield ext.strip('.')
46+
47+VIDEO = tuple(get_extensions_for_type('video'))
48+
49+AUDIO = tuple(get_extensions_for_type('audio'))
50+
51+IMAGE = tuple(get_extensions_for_type('image'))
52
53 EXTENSIONS = VIDEO + AUDIO + IMAGE
54
55@@ -51,3 +56,5 @@
56 'image': IMAGE,
57 'all': EXTENSIONS,
58 }
59+
60+

Subscribers

People subscribed via source and target branches

to all changes: