Changeset ba90f24843c7c942b001b46fb707cbc0d409f90d
- Timestamp:
- 12/02/07 21:04:02
(1 year ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1196651042 -0600
- git-parent:
[8b942de2822ae69316152244f6c6d807e2bd4bd3]
- git-author:
- Jason Michalski <armooo@armooo.net> 1196538173 -0600
- Message:
Updated music plugin to suport the full paths
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r214a148 |
rba90f24 |
|
| 14 | 14 | |
|---|
| 15 | 15 | CONTENT_TYPE = 'x-container/tivo-music' |
|---|
| | 16 | |
|---|
| | 17 | AUDIO = 'audio' |
|---|
| | 18 | DIRECTORY = 'dir' |
|---|
| | 19 | |
|---|
| 16 | 20 | playable_cache = {} |
|---|
| 17 | 21 | playable_cache = LRUCache(1000) |
|---|
| … | … | |
| 22 | 26 | subcname = query['Container'][0] |
|---|
| 23 | 27 | cname = subcname.split('/')[0] |
|---|
| | 28 | local_base_path = self.get_local_base_path(handler, query) |
|---|
| 24 | 29 | |
|---|
| 25 | 30 | if not handler.server.containers.has_key(cname) or not self.get_local_path(handler, query): |
|---|
| … | … | |
| 28 | 33 | return |
|---|
| 29 | 34 | |
|---|
| 30 | | path = self.get_local_path(handler, query) |
|---|
| 31 | | def isdir(file): |
|---|
| 32 | | return os.path.isdir(os.path.join(path, file)) |
|---|
| | 35 | def AudioFileFilter(file, filter_type = None): |
|---|
| 33 | 36 | |
|---|
| 34 | | def AudioFileFilter(file): |
|---|
| 35 | | full_path = os.path.join(path, file) |
|---|
| | 37 | if filter_type: |
|---|
| | 38 | filter_start = filter_type.split('/')[0] |
|---|
| | 39 | else: |
|---|
| | 40 | filter_start = filter_type |
|---|
| 36 | 41 | |
|---|
| 37 | | if full_path in self.playable_cache: |
|---|
| 38 | | return self.playable_cache[full_path] |
|---|
| 39 | | if os.path.isdir(full_path) or eyeD3.isMp3File(full_path): |
|---|
| 40 | | self.playable_cache[full_path] = True |
|---|
| 41 | | return True |
|---|
| 42 | | else: |
|---|
| 43 | | self.playable_cache[full_path] = False |
|---|
| 44 | | return False |
|---|
| | 42 | if file not in self.playable_cache: |
|---|
| | 43 | if os.path.isdir(file): |
|---|
| | 44 | self.playable_cache[file] = self.DIRECTORY |
|---|
| | 45 | |
|---|
| | 46 | elif eyeD3.isMp3File(file): |
|---|
| | 47 | self.playable_cache[file] = self.AUDIO |
|---|
| | 48 | else: |
|---|
| | 49 | self.playable_cache[file] = False |
|---|
| | 50 | |
|---|
| | 51 | if filter_start == self.AUDIO: |
|---|
| | 52 | if self.playable_cache[file] == self.AUDIO: |
|---|
| | 53 | return self.playable_cache[file] |
|---|
| | 54 | else: |
|---|
| | 55 | return False |
|---|
| | 56 | else: |
|---|
| | 57 | return self.playable_cache[file] |
|---|
| | 58 | |
|---|
| 45 | 59 | |
|---|
| 46 | 60 | def media_data(file): |
|---|
| 47 | 61 | dict = {} |
|---|
| 48 | 62 | dict['path'] = file |
|---|
| 49 | | |
|---|
| 50 | | file = os.path.join(path, file) |
|---|
| | 63 | dict['part_path'] = file.replace(local_base_path, '') |
|---|
| | 64 | dict['name'] = os.path.split(file)[1] |
|---|
| | 65 | dict['is_dir'] = os.path.isdir(file) |
|---|
| 51 | 66 | |
|---|
| 52 | 67 | if file in self.media_data_cache: |
|---|
| 53 | 68 | return self.media_data_cache[file] |
|---|
| 54 | 69 | |
|---|
| 55 | | if isdir(file) or not eyeD3.isMp3File(file): |
|---|
| | 70 | if os.path.isdir(file) or not eyeD3.isMp3File(file): |
|---|
| 56 | 71 | self.media_data_cache[file] = dict |
|---|
| 57 | 72 | return dict |
|---|
| … | … | |
| 80 | 95 | t = Template(file=os.path.join(SCRIPTDIR,'templates', 'container.tmpl')) |
|---|
| 81 | 96 | t.name = subcname |
|---|
| | 97 | t.container = cname |
|---|
| 82 | 98 | t.files, t.total, t.start = self.get_files(handler, query, AudioFileFilter) |
|---|
| 83 | 99 | t.files = map(media_data, t.files) |
|---|
| 84 | | t.isdir = isdir |
|---|
| 85 | 100 | t.quote = quote |
|---|
| 86 | 101 | t.escape = escape |
|---|
| r6ab8361 |
rba90f24 |
|
| 10 | 10 | </Details> |
|---|
| 11 | 11 | #for $file in $files |
|---|
| 12 | | #if $isdir($file['path']) |
|---|
| | 12 | #if $file['is_dir'] |
|---|
| 13 | 13 | <Item> |
|---|
| 14 | 14 | <Details> |
|---|
| 15 | | <Title>$escape($file.path)</Title> |
|---|
| | 15 | <Title>$escape($file.name)</Title> |
|---|
| 16 | 16 | <ContentType>x-container/folder</ContentType> |
|---|
| 17 | 17 | <SourceFormat>x-container/folder</SourceFormat> |
|---|
| … | … | |
| 19 | 19 | <Links> |
|---|
| 20 | 20 | <Content> |
|---|
| 21 | | <Url>/TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.path)</Url> |
|---|
| | 21 | <Url>/TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.name)</Url> |
|---|
| 22 | 22 | <ContentType>x-tivo-container/folder</ContentType> |
|---|
| 23 | 23 | </Content> |
|---|
| … | … | |
| 27 | 27 | <Item> |
|---|
| 28 | 28 | <Details> |
|---|
| 29 | | <Title>#echo '.'.join(file['path'].split('.')[:-1]) #</Title> |
|---|
| | 29 | <Title>#echo '.'.join(file['name'].split('.')[:-1]) #</Title> |
|---|
| 30 | 30 | <ContentType>audio/*</ContentType> |
|---|
| 31 | 31 | <SourceFormat>audio/mpeg</SourceFormat> |
|---|
| … | … | |
| 40 | 40 | <ContentType>audio/*</ContentType> |
|---|
| 41 | 41 | <AcceptsParams>No</AcceptsParams> |
|---|
| 42 | | <Url>/$quote($name)/$quote($file.path)</Url> |
|---|
| | 42 | <Url>/$quote($container)$quote($file.part_path)</Url> |
|---|
| 43 | 43 | </Content> |
|---|
| 44 | 44 | </Links> |
|---|