1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 This metadata provider, looks if there is might a Cover (file) in the
19 directory of the file.
20 """
21
22
23 __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>'
24
25 import os, glob
26
27 from twisted.internet import threads
28
29 from elisa.core import common
30 from elisa.base_components.metadata_provider import MetadataProvider
31 from elisa.core.media_uri import MediaUri
32
33
35 """
36 This CoverInDir Metadata Provider just looks if there are might covers in
37 the directory of the URI. If there are more than one found, it uses the
38 best suited one.
39
40 @ivar list_of_extentions: a list of extentions our cover could have.
41 @type list_of_extentions: list
42
43 @ivar list_of_names: a list of good names for our cover sorted by
44 priority. if there is none found, which is
45 exactly spelled this way, we'll look for one,
46 which contains any of this names...
47
48 @type list_of_names: list
49 """
50
51
52 list_of_extentions = ['png', 'jpg', 'xpm', 'jpeg']
53
54
55 list_of_names = ['cover', 'front', 'cd', 'dvd']
56
57
58
59
63
65 able = False
66 content_type = metadata.get('content-type')
67 file_type = metadata.get('file_type')
68
69 if metadata.has_key('uri'):
70 uri = metadata['uri']
71 cover = metadata.get('cover')
72 default_image = metadata.get('default_image')
73 self.debug("file_type=%r, content_type=%r, uri.scheme=%r",
74 file_type, content_type, uri.scheme)
75 if not cover and not default_image:
76 able = ((file_type == 'audio') or (content_type in ('artist',
77 'album',
78 'audio'))) \
79 and uri.scheme in ('file', 'elisa')
80
81 return able
82
86
88 found = False
89
90 for item in match_list:
91 if data.find(item) != -1:
92 found = True
93 break
94 return found
95
97 uri = metadata['uri']
98 if uri.scheme == 'file':
99 result = self._files_scan(metadata)
100 else:
101 result = self._elisa_db_scan(metadata)
102 return result
103
147
149 uri = metadata['uri']
150 self.debug("Retrieving cover of %r from db", uri)
151
152 def got_children(children):
153 if len(children) > 0:
154 child_metadata = children[0][1]
155 default_image = child_metadata.get('default_image')
156 if default_image:
157 return self._set_cover(metadata, default_image)
158
159 media_manager = common.application.media_manager
160 dfr = media_manager.get_direct_children(uri, [])
161 dfr.addCallback(got_children)
162 return metadata
163
165 if metadata.get('cover') == None:
166 metadata['cover'] = cover_path
167
168
169 if metadata.get('default_image') == None:
170 self.debug("Setting default_image to %r", cover_path)
171 metadata['default_image'] = cover_path
172
173 return metadata
174
175
176
177 if __name__ == "__main__":
178
179 from twisted.internet import reactor
180
181 c = CoverInDir()
182 uri = MediaUri("file:///tmp/covers/momo.mp3")
183
184 print "rank:",c.get_rank()
185 print "Should be able to handle:", c.able_to_handle({'uri':uri})
186 print "Should not be able to handle:", c.able_to_handle({'uri' : uri,
187 'cover': 'blalbal'})
188
190
191 def print_it(metadata):
192 print "metadata is", metadata
193
194
195 df = c.get_metadata({'uri' : uri})
196 df.addCallback(print_it)
197
198
199 reactor.callWhenRunning(start)
200
201 reactor.run()
202