Changeset 6ab8361a61197bb0a951e5f77d4d1c5c25a9702f
- Timestamp:
- 12/23/06 02:56:35
(2 years ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1166864195 +0000
- git-parent:
[96079947dcaa2c493534582190f4a7880b256b1e]
- git-author:
- Jason Michalski <armooo@armooo.net> 1166864195 +0000
- Message:
pyTivo
- ID3 suport for music
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9607994 |
r6ab8361 |
|
| 5 | 5 | from urlparse import urlparse |
|---|
| 6 | 6 | from xml.sax.saxutils import escape |
|---|
| | 7 | import eyeD3 |
|---|
| 7 | 8 | |
|---|
| 8 | 9 | SCRIPTDIR = os.path.dirname(__file__) |
|---|
| … | … | |
| 35 | 36 | path = self.get_local_path(handler, query) |
|---|
| 36 | 37 | def isdir(file): |
|---|
| 37 | | return os.path.isdir(os.path.join(path, file)) |
|---|
| | 38 | return os.path.isdir(os.path.join(path, file)) |
|---|
| 38 | 39 | |
|---|
| | 40 | def media_data(file): |
|---|
| | 41 | dict = {} |
|---|
| | 42 | dict['path'] = file |
|---|
| | 43 | |
|---|
| | 44 | file = os.path.join(path, file) |
|---|
| | 45 | |
|---|
| | 46 | if isdir(file) or not eyeD3.isMp3File(file): |
|---|
| | 47 | return dict |
|---|
| | 48 | |
|---|
| | 49 | audioFile = eyeD3.Mp3AudioFile(file) |
|---|
| | 50 | dict['Duration'] = audioFile.getPlayTime() * 1000 |
|---|
| | 51 | dict['SourceBitRate'] = audioFile.getBitRate()[1] |
|---|
| | 52 | dict['SourceSampleRate'] = audioFile.getSampleFreq() |
|---|
| | 53 | |
|---|
| | 54 | tag = audioFile.getTag() |
|---|
| | 55 | dict['ArtistName'] = str(tag.getArtist()) |
|---|
| | 56 | dict['AlbumTitle'] = str(tag.getAlbum()) |
|---|
| | 57 | dict['SongTitle'] = str(tag.getTitle()) |
|---|
| | 58 | dict['AlbumYear'] = tag.getYear() |
|---|
| | 59 | |
|---|
| | 60 | try: |
|---|
| | 61 | dict['MusicGenre'] = tag.getGenre().getName() |
|---|
| | 62 | except: |
|---|
| | 63 | pass |
|---|
| | 64 | |
|---|
| | 65 | return dict |
|---|
| | 66 | |
|---|
| 39 | 67 | handler.send_response(200) |
|---|
| 40 | 68 | handler.end_headers() |
|---|
| … | … | |
| 42 | 70 | t.name = subcname |
|---|
| 43 | 71 | t.files, t.total, t.start = self.get_files(handler, query) |
|---|
| | 72 | t.files = map(media_data, t.files) |
|---|
| 44 | 73 | t.isdir = isdir |
|---|
| 45 | 74 | t.quote = quote |
|---|
| r9607994 |
r6ab8361 |
|
| 10 | 10 | </Details> |
|---|
| 11 | 11 | #for $file in $files |
|---|
| 12 | | #if $isdir($file) |
|---|
| | 12 | #if $isdir($file['path']) |
|---|
| 13 | 13 | <Item> |
|---|
| 14 | 14 | <Details> |
|---|
| 15 | | <Title>$escape($file)</Title> |
|---|
| | 15 | <Title>$escape($file.path)</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)</Url> |
|---|
| | 21 | <Url>/TiVoConnect?Command=QueryContainer&Container=$quote($name)/$quote($file.path)</Url> |
|---|
| 22 | 22 | <ContentType>x-tivo-container/folder</ContentType> |
|---|
| 23 | 23 | </Content> |
|---|
| … | … | |
| 27 | 27 | <Item> |
|---|
| 28 | 28 | <Details> |
|---|
| 29 | | <Title>#echo '.'.join(file.split('.')[:-1]) #</Title> |
|---|
| | 29 | <Title>#echo '.'.join(file['path'].split('.')[:-1]) #</Title> |
|---|
| 30 | 30 | <ContentType>audio/*</ContentType> |
|---|
| 31 | 31 | <SourceFormat>audio/mpeg</SourceFormat> |
|---|
| | 32 | |
|---|
| | 33 | #for $key in $file |
|---|
| | 34 | <$key>$file[$key]</$key> |
|---|
| | 35 | #end for |
|---|
| | 36 | |
|---|
| 32 | 37 | </Details> |
|---|
| 33 | 38 | <Links> |
|---|
| … | … | |
| 35 | 40 | <ContentType>audio/*</ContentType> |
|---|
| 36 | 41 | <AcceptsParams>No</AcceptsParams> |
|---|
| 37 | | <Url>/$quote($name)/$quote($file)</Url> |
|---|
| | 42 | <Url>/$quote($name)/$quote($file.path)</Url> |
|---|
| 38 | 43 | </Content> |
|---|
| 39 | 44 | </Links> |
|---|