Changeset 01d36f1d8ba93dd875ad8e0c75fe1152ac8a0832
- Timestamp:
- 01/29/08 20:45:03
(1 year ago)
- Author:
- William McBrine <wmcbrine@gmail.com>
- git-committer:
- William McBrine <wmcbrine@gmail.com> 1201661103 -0500
- git-parent:
[0d34c7504737dd88e191455ffe995144a9158ea1]
- git-author:
- William McBrine <wmcbrine@gmail.com> 1201661103 -0500
- Message:
Cosmetic changes.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r0d34c75 |
r01d36f1 |
|
| 21 | 21 | |
|---|
| 22 | 22 | class Video(Plugin): |
|---|
| 23 | | |
|---|
| | 23 | |
|---|
| 24 | 24 | CONTENT_TYPE = 'x-container/tivo-videos' |
|---|
| 25 | 25 | |
|---|
| 26 | 26 | def send_file(self, handler, container, name): |
|---|
| 27 | | |
|---|
| 28 | | #No longer a 'cheep' hack :p |
|---|
| 29 | | if handler.headers.getheader('Range') and not handler.headers.getheader('Range') == 'bytes=0-': |
|---|
| | 27 | if handler.headers.getheader('Range') and \ |
|---|
| | 28 | handler.headers.getheader('Range') != 'bytes=0-': |
|---|
| 30 | 29 | handler.send_response(206) |
|---|
| 31 | 30 | handler.send_header('Connection', 'close') |
|---|
| … | … | |
| 42 | 41 | handler.send_response(200) |
|---|
| 43 | 42 | handler.end_headers() |
|---|
| 44 | | transcode.output_video(container['path'] + path[len(name)+1:], handler.wfile, tsn) |
|---|
| 45 | | |
|---|
| | 43 | transcode.output_video(container['path'] + path[len(name) + 1:], |
|---|
| | 44 | handler.wfile, tsn) |
|---|
| 46 | 45 | |
|---|
| 47 | 46 | def __isdir(self, full_path): |
|---|
| … | … | |
| 52 | 51 | |
|---|
| 53 | 52 | def __est_size(self, full_path, tsn = ''): |
|---|
| 54 | | #Size is estimated by taking audio and video bit rate adding 2% |
|---|
| 55 | | |
|---|
| 56 | | if transcode.tivo_compatable(full_path, tsn): # Is TiVo compatible mpeg2 |
|---|
| | 53 | # Size is estimated by taking audio and video bit rate adding 2% |
|---|
| | 54 | |
|---|
| | 55 | if transcode.tivo_compatable(full_path, tsn): |
|---|
| | 56 | # Is TiVo-compatible mpeg2 |
|---|
| 57 | 57 | return int(os.stat(full_path).st_size) |
|---|
| 58 | | else: # Must be re-encoded |
|---|
| | 58 | else: |
|---|
| | 59 | # Must be re-encoded |
|---|
| 59 | 60 | audioBPS = config.strtod(config.getAudioBR(tsn)) |
|---|
| 60 | 61 | videoBPS = config.strtod(config.getVideoBR(tsn)) |
|---|
| 61 | 62 | bitrate = audioBPS + videoBPS |
|---|
| 62 | | return int((self.__duration(full_path)/1000)*(bitrate * 1.02 / 8)) |
|---|
| 63 | | |
|---|
| | 63 | return int((self.__duration(full_path) / 1000) * |
|---|
| | 64 | (bitrate * 1.02 / 8)) |
|---|
| | 65 | |
|---|
| 64 | 66 | def __getMetadataFromTxt(self, full_path): |
|---|
| 65 | 67 | metadata = {} |
|---|
| … | … | |
| 98 | 100 | |
|---|
| 99 | 101 | def __metadata(self, full_path, tsn =''): |
|---|
| 100 | | |
|---|
| 101 | 102 | metadata = {} |
|---|
| 102 | 103 | |
|---|
| … | … | |
| 106 | 107 | duration = self.__duration(full_path) |
|---|
| 107 | 108 | duration_delta = timedelta(milliseconds = duration) |
|---|
| 108 | | |
|---|
| | 109 | |
|---|
| 109 | 110 | metadata['title'] = '.'.join(title.split('.')[:-1]) |
|---|
| 110 | 111 | metadata['seriesTitle'] = metadata['title'] # default to the filename |
|---|
| … | … | |
| 115 | 116 | |
|---|
| 116 | 117 | metadata.update( self.__getMetadataFromTxt(full_path) ) |
|---|
| 117 | | |
|---|
| | 118 | |
|---|
| 118 | 119 | metadata['size'] = self.__est_size(full_path, tsn) |
|---|
| 119 | 120 | metadata['duration'] = duration |
|---|
| … | … | |
| 123 | 124 | hours = min / 60 |
|---|
| 124 | 125 | min = min % 60 |
|---|
| 125 | | metadata['iso_duration'] = 'P' + str(duration_delta.days) + 'DT' + str(hours) + 'H' + str(min) + 'M' + str(sec) + 'S' |
|---|
| 126 | | |
|---|
| | 126 | metadata['iso_duration'] = 'P' + str(duration_delta.days) + \ |
|---|
| | 127 | 'DT' + str(hours) + 'H' + str(min) + \ |
|---|
| | 128 | 'M' + str(sec) + 'S' |
|---|
| 127 | 129 | return metadata |
|---|
| 128 | 130 | |
|---|
| 129 | 131 | def QueryContainer(self, handler, query): |
|---|
| 130 | | |
|---|
| 131 | 132 | tsn = handler.headers.getheader('tsn', '') |
|---|
| 132 | 133 | subcname = query['Container'][0] |
|---|
| 133 | 134 | cname = subcname.split('/')[0] |
|---|
| 134 | | |
|---|
| 135 | | if not handler.server.containers.has_key(cname) or not self.get_local_path(handler, query): |
|---|
| | 135 | |
|---|
| | 136 | if not handler.server.containers.has_key(cname) or \ |
|---|
| | 137 | not self.get_local_path(handler, query): |
|---|
| 136 | 138 | handler.send_response(404) |
|---|
| 137 | 139 | handler.end_headers() |
|---|
| 138 | 140 | return |
|---|
| 139 | | |
|---|
| | 141 | |
|---|
| 140 | 142 | def video_file_filter(full_path, type = None): |
|---|
| 141 | 143 | if os.path.isdir(full_path): |
|---|
| … | … | |
| 154 | 156 | video['title'] = os.path.split(file)[1] |
|---|
| 155 | 157 | video['is_dir'] = self.__isdir(file) |
|---|
| 156 | | if not video['is_dir']: |
|---|
| | 158 | if not video['is_dir']: |
|---|
| 157 | 159 | video.update(self.__metadata(file, tsn)) |
|---|
| 158 | 160 | |
|---|
| … | … | |
| 172 | 174 | |
|---|
| 173 | 175 | def TVBusQuery(self, handler, query): |
|---|
| 174 | | |
|---|
| 175 | 176 | tsn = handler.headers.getheader('tsn', '') |
|---|
| 176 | 177 | file = query['File'][0] |
|---|
| … | … | |
| 187 | 188 | t.escape = escape |
|---|
| 188 | 189 | handler.wfile.write(t) |
|---|
| 189 | | |
|---|
| | 190 | |
|---|
| 190 | 191 | class VideoDetails(DictMixin): |
|---|
| 191 | | |
|---|
| 192 | | def __init__(self, d = None): |
|---|
| | 192 | |
|---|
| | 193 | def __init__(self, d=None): |
|---|
| 193 | 194 | if d: |
|---|
| 194 | 195 | self.d = d |
|---|
| … | … | |
| 209 | 210 | def __delitem__(self): |
|---|
| 210 | 211 | del self.d[key] |
|---|
| 211 | | |
|---|
| | 212 | |
|---|
| 212 | 213 | def keys(self): |
|---|
| 213 | 214 | return self.d.keys() |
|---|
| 214 | | |
|---|
| | 215 | |
|---|
| 215 | 216 | def __iter__(self): |
|---|
| 216 | 217 | return self.d.__iter__() |
|---|
| … | … | |
| 228 | 229 | 'colorCode' : ('COLOR', '4'), |
|---|
| 229 | 230 | 'showType' : ('SERIES', '5'), |
|---|
| 230 | | 'tvRating' : ('NR', '7'), |
|---|
| | 231 | 'tvRating' : ('NR', '7') |
|---|
| 231 | 232 | } |
|---|
| 232 | 233 | if key in defaults: |
|---|