Changeset 01d36f1d8ba93dd875ad8e0c75fe1152ac8a0832

Show
Ignore:
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
  • plugins/video/video.py

    r0d34c75 r01d36f1  
    2121 
    2222class Video(Plugin): 
    23      
     23 
    2424    CONTENT_TYPE = 'x-container/tivo-videos' 
    2525 
    2626    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-': 
    3029            handler.send_response(206) 
    3130            handler.send_header('Connection', 'close') 
     
    4241        handler.send_response(200) 
    4342        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) 
    4645 
    4746    def __isdir(self, full_path): 
     
    5251 
    5352    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 
    5757            return int(os.stat(full_path).st_size) 
    58         else:  # Must be re-encoded 
     58        else: 
     59            # Must be re-encoded 
    5960            audioBPS = config.strtod(config.getAudioBR(tsn)) 
    6061            videoBPS = config.strtod(config.getVideoBR(tsn)) 
    6162            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 
    6466    def __getMetadataFromTxt(self, full_path): 
    6567        metadata = {} 
     
    98100 
    99101    def __metadata(self, full_path, tsn =''): 
    100  
    101102        metadata = {} 
    102103 
     
    106107        duration = self.__duration(full_path) 
    107108        duration_delta = timedelta(milliseconds = duration) 
    108          
     109 
    109110        metadata['title'] = '.'.join(title.split('.')[:-1]) 
    110111        metadata['seriesTitle'] = metadata['title'] # default to the filename 
     
    115116 
    116117        metadata.update( self.__getMetadataFromTxt(full_path) ) 
    117          
     118 
    118119        metadata['size'] = self.__est_size(full_path, tsn) 
    119120        metadata['duration'] = duration 
     
    123124        hours = min / 60 
    124125        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' 
    127129        return metadata 
    128130 
    129131    def QueryContainer(self, handler, query): 
    130          
    131132        tsn = handler.headers.getheader('tsn', '') 
    132133        subcname = query['Container'][0] 
    133134        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): 
    136138            handler.send_response(404) 
    137139            handler.end_headers() 
    138140            return 
    139          
     141 
    140142        def video_file_filter(full_path, type = None): 
    141143            if os.path.isdir(full_path): 
     
    154156            video['title'] = os.path.split(file)[1] 
    155157            video['is_dir'] = self.__isdir(file) 
    156             if not video['is_dir']: 
     158            if not video['is_dir']: 
    157159                video.update(self.__metadata(file, tsn)) 
    158160 
     
    172174 
    173175    def TVBusQuery(self, handler, query): 
    174  
    175176        tsn = handler.headers.getheader('tsn', '')        
    176177        file = query['File'][0] 
     
    187188        t.escape = escape 
    188189        handler.wfile.write(t) 
    189      
     190 
    190191class VideoDetails(DictMixin): 
    191     
    192     def __init__(self, d = None): 
     192 
     193    def __init__(self, d=None): 
    193194        if d: 
    194195            self.d = d 
     
    209210    def __delitem__(self): 
    210211        del self.d[key] 
    211      
     212 
    212213    def keys(self): 
    213214        return self.d.keys() 
    214      
     215 
    215216    def __iter__(self): 
    216217        return self.d.__iter__() 
     
    228229            'colorCode' : ('COLOR', '4'), 
    229230            'showType' : ('SERIES', '5'), 
    230             'tvRating' : ('NR', '7'), 
     231            'tvRating' : ('NR', '7') 
    231232        } 
    232233        if key in defaults: