From ba90f24843c7c942b001b46fb707cbc0d409f90d Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Sat, 1 Dec 2007 13:42:53 -0600 Subject: [PATCH] Updated music plugin to suport the full paths --- plugins/music/music.py | 49 ++++++++++++++++++++++------------ plugins/music/templates/container.tmpl | 10 +++---- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/plugins/music/music.py b/plugins/music/music.py index e28af06..4dd53bd 100644 --- a/plugins/music/music.py +++ b/plugins/music/music.py @@ -13,6 +13,10 @@ CLASS_NAME = 'Music' class Music(Plugin): CONTENT_TYPE = 'x-container/tivo-music' + + AUDIO = 'audio' + DIRECTORY = 'dir' + playable_cache = {} playable_cache = LRUCache(1000) media_data_cache = LRUCache(100) @@ -21,38 +25,49 @@ class Music(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] + local_base_path = self.get_local_base_path(handler, query) if not handler.server.containers.has_key(cname) or not self.get_local_path(handler, query): handler.send_response(404) handler.end_headers() return - path = self.get_local_path(handler, query) - def isdir(file): - return os.path.isdir(os.path.join(path, file)) + def AudioFileFilter(file, filter_type = None): - def AudioFileFilter(file): - full_path = os.path.join(path, file) - - if full_path in self.playable_cache: - return self.playable_cache[full_path] - if os.path.isdir(full_path) or eyeD3.isMp3File(full_path): - self.playable_cache[full_path] = True - return True + if filter_type: + filter_start = filter_type.split('/')[0] else: - self.playable_cache[full_path] = False - return False + filter_start = filter_type + + if file not in self.playable_cache: + if os.path.isdir(file): + self.playable_cache[file] = self.DIRECTORY + + elif eyeD3.isMp3File(file): + self.playable_cache[file] = self.AUDIO + else: + self.playable_cache[file] = False + + if filter_start == self.AUDIO: + if self.playable_cache[file] == self.AUDIO: + return self.playable_cache[file] + else: + return False + else: + return self.playable_cache[file] + def media_data(file): dict = {} dict['path'] = file - - file = os.path.join(path, file) + dict['part_path'] = file.replace(local_base_path, '') + dict['name'] = os.path.split(file)[1] + dict['is_dir'] = os.path.isdir(file) if file in self.media_data_cache: return self.media_data_cache[file] - if isdir(file) or not eyeD3.isMp3File(file): + if os.path.isdir(file) or not eyeD3.isMp3File(file): self.media_data_cache[file] = dict return dict @@ -79,9 +94,9 @@ class Music(Plugin): handler.end_headers() t = Template(file=os.path.join(SCRIPTDIR,'templates', 'container.tmpl')) t.name = subcname + t.container = cname t.files, t.total, t.start = self.get_files(handler, query, AudioFileFilter) t.files = map(media_data, t.files) - t.isdir = isdir t.quote = quote t.escape = escape handler.wfile.write(t) diff --git a/plugins/music/templates/container.tmpl b/plugins/music/templates/container.tmpl index 04ba1ff..0ed3329 100644 --- a/plugins/music/templates/container.tmpl +++ b/plugins/music/templates/container.tmpl @@ -9,16 +9,16 @@ $total #for $file in $files - #if $isdir($file['path']) + #if $file['is_dir']
- $escape($file.path) + $escape($file.name) x-container/folder x-container/folder
- /TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.path) + /TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.name) x-tivo-container/folder @@ -26,7 +26,7 @@ #else
- #echo '.'.join(file['path'].split('.')[:-1]) # + #echo '.'.join(file['name'].split('.')[:-1]) # audio/* audio/mpeg @@ -39,7 +39,7 @@ audio/* No - /$quote($name)/$quote($file.path) + /$quote($container)$quote($file.part_path) -- 2.11.4.GIT