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
=== modified file 'dmedialib/constants.py'
--- dmedialib/constants.py 2010-11-27 03:40:39 +0000
+++ dmedialib/constants.py 2010-11-27 15:36:09 +0000
@@ -1,5 +1,6 @@
1# Authors:1# Authors:
2# Jason Gerard DeRose <jderose@novacut.com>2# Jason Gerard DeRose <jderose@novacut.com>
3# David Green <david4dev@gmail.com>
3#4#
4# dmedia: distributed media library5# dmedia: distributed media library
5# Copyright (C) 2010 Jason Gerard DeRose <jderose@novacut.com>6# Copyright (C) 2010 Jason Gerard DeRose <jderose@novacut.com>
@@ -23,25 +24,29 @@
23Various constants conveniently located in one place.24Various constants conveniently located in one place.
24"""25"""
2526
27import mimetypes
28mimetypes.init()
29
30
26BUS = 'org.freedesktop.DMedia'31BUS = 'org.freedesktop.DMedia'
27INTERFACE = 'org.freedesktop.DMedia'32INTERFACE = 'org.freedesktop.DMedia'
2833
29TYPE_ERROR = '%s: need a %r; got a %r: %r' # Standard TypeError message34TYPE_ERROR = '%s: need a %r; got a %r: %r' # Standard TypeError message
3035
3136def get_extensions_for_type(general_type):
32VIDEO = (37 """
33 'ogv', # video/ogg38 An iterator that yields the file extensions for files of a general type.
34 'webm', # video/webm39 eg. 'image'
35 'mov', 'qt', # video/quicktime40 """
36 'mp4', # video/mp441 for ext in mimetypes.types_map:
37 'mpeg', 'mpg', 'mpe', # video/mpeg42 if mimetypes.types_map[ext].split('/')[0] == general_type:
38 'avi', # video/x-msvideo43 yield ext.strip('.')
39 'mpv', 'mkv', # video/x-matroska44
40)45VIDEO = tuple(get_extensions_for_type('video'))
4146
42AUDIO = ('wav', 'oga', 'flac', 'spx', 'mp3')47AUDIO = tuple(get_extensions_for_type('audio'))
4348
44IMAGE = ('jpg', 'png', 'cr2', 'crw', 'nef')49IMAGE = tuple(get_extensions_for_type('image'))
4550
46EXTENSIONS = VIDEO + AUDIO + IMAGE51EXTENSIONS = VIDEO + AUDIO + IMAGE
4752
@@ -51,3 +56,5 @@
51 'image': IMAGE,56 'image': IMAGE,
52 'all': EXTENSIONS,57 'all': EXTENSIONS,
53}58}
59
60

Subscribers

People subscribed via source and target branches

to all changes: