From 9552d0d626e4b3d98ef9d359d36ab2564e2a6839 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Tue, 23 Dec 2008 01:16:52 -0500 Subject: [PATCH] More fiddly bits that probably no one else cares about. --- config.py | 49 +++++++++++----------- plugins/admin/admin.py | 98 +++++++++++++++++++++----------------------- plugins/video/transcode.py | 98 ++++++++++++++++++++++---------------------- plugins/video/video.py | 8 ++-- plugins/webvideo/webvideo.py | 2 +- pyTivoService.py | 1 - 6 files changed, 126 insertions(+), 130 deletions(-) diff --git a/config.py b/config.py index 064a470..77c4903 100644 --- a/config.py +++ b/config.py @@ -21,8 +21,8 @@ for config_file in config_files: if os.path.exists(config_file): config_exists = True if not config_exists: - print 'ERROR: pyTivo.conf does not exist.\n' + \ - 'You must create this file before running pyTivo.' + print ('ERROR: pyTivo.conf does not exist.\n' + + 'You must create this file before running pyTivo.') sys.exit(1) config.read(config_files) @@ -58,16 +58,17 @@ def get169Blacklist(tsn): # tivo does not pad 16:9 video return tsn and not isHDtivo(tsn) and not get169Letterbox(tsn) def get169Letterbox(tsn): # tivo pads 16:9 video for 4:3 display - return tsn and tsn[:3] in ('649') + return tsn and tsn[:3] in ['649'] def get169Setting(tsn): if not tsn: return True - if config.has_section('_tivo_' + tsn): - if config.has_option('_tivo_' + tsn, 'aspect169'): + tsnsect = '_tivo_' + tsn + if config.has_section(tsnsect): + if config.has_option(tsnsect, 'aspect169'): try: - return config.getboolean('_tivo_' + tsn, 'aspect169') + return config.getboolean(tsnsect, 'aspect169') except ValueError: pass @@ -105,7 +106,7 @@ def getDebug(): except NoOptionError, ValueError: return False -def getOptres(tsn = None): +def getOptres(tsn=None): if tsn and config.has_section('_tivo_' + tsn): try: return config.getboolean('_tivo_' + tsn, 'optres') @@ -213,9 +214,9 @@ def getTivoWidth(tsn): def _trunc64(i): return max(int(strtod(i)) / 64000, 1) * 64 -def getAudioBR(tsn = None): - #convert to non-zero multiple of 64 to ensure ffmpeg compatibility - #compare audio_br to max_audio_br and return lowest +def getAudioBR(tsn=None): + # convert to non-zero multiple of 64 to ensure ffmpeg compatibility + # compare audio_br to max_audio_br and return lowest if tsn and config.has_section('_tivo_' + tsn): try: audiobr = _trunc64(config.get('_tivo_' + tsn, 'audio_br')) @@ -231,7 +232,7 @@ def getAudioBR(tsn = None): def _k(i): return str(int(strtod(i)) / 1000) + 'k' -def getVideoBR(tsn = None): +def getVideoBR(tsn=None): if tsn and config.has_section('_tivo_' + tsn): try: return _k(config.get('_tivo_' + tsn, 'video_br')) @@ -257,11 +258,12 @@ def getVideoPCT(): except NoOptionError: return 70 -def getBuffSize(tsn = None): - if tsn and config.has_section('_tivo_' + tsn): - if config.has_option('_tivo_' + tsn, 'bufsize'): +def getBuffSize(tsn=None): + tsnsect = '_tivo_' + tsn + if tsn and config.has_section(tsnsect): + if config.has_option(tsnsect, 'bufsize'): try: - return _k(config.get('_tivo_' + tsn, 'bufsize')) + return _k(config.get(tsnsect, 'bufsize')) except NoOptionError: pass if config.has_option('Server', 'bufsize'): @@ -274,8 +276,8 @@ def getBuffSize(tsn = None): else: return '1024k' -def getMaxAudioBR(tsn = None): - #convert to non-zero multiple of 64 for ffmpeg compatibility +def getMaxAudioBR(tsn=None): + # convert to non-zero multiple of 64 for ffmpeg compatibility if tsn and config.has_section('_tivo_' + tsn): try: return _trunc64(config.get('_tivo_' + tsn, 'max_audio_br')) @@ -309,11 +311,12 @@ def getAudioFR(tsn=None): def getAudioLang(tsn=None): return get_tsn('audio_lang', tsn) -def getCopyTS(tsn = None): - if tsn and config.has_section('_tivo_' + tsn): - if config.has_option('_tivo_' + tsn, 'copy_ts'): +def getCopyTS(tsn=None): + tsnsect = '_tivo_' + tsn + if tsn and config.has_section(tsnsect): + if config.has_option(tsnsect, 'copy_ts'): try: - return config.get('_tivo_' + tsn, 'copy_ts') + return config.get(tsnsect, 'copy_ts') except NoOptionError, ValueError: pass if config.has_option('Server', 'copy_ts'): @@ -329,7 +332,7 @@ def getVideoFPS(tsn=None): def getVideoCodec(tsn=None): return get_tsn('video_codec', tsn) -def getFormat(tsn = None): +def getFormat(tsn=None): return get_tsn('format', tsn) # Parse a bitrate using the SI/IEEE suffix values as if by ffmpeg @@ -342,7 +345,7 @@ def strtod(value): 'T': 12, 'P': 15, 'E': 18, 'Z': 21, 'Y': 24} p = re.compile(r'^(\d+)(?:([yzafpnumcdhkKMGTPEZY])(i)?)?([Bb])?$') m = p.match(value) - if m is None: + if not m: raise SyntaxError('Invalid bit value syntax') (coef, prefix, power, byte) = m.groups() if prefix is None: diff --git a/plugins/admin/admin.py b/plugins/admin/admin.py index 9467576..5bcd911 100644 --- a/plugins/admin/admin.py +++ b/plugins/admin/admin.py @@ -85,8 +85,8 @@ p.pop() p = os.path.sep.join(p) config_file_path = os.path.join(p, 'pyTivo.conf') -status = {} #Global variable to control download threads -tivo_cache = {} #Cache of TiVo NPL +status = {} # Global variable to control download threads +tivo_cache = {} # Cache of TiVo NPL def tag_data(element, tag): for name in tag.split('/'): @@ -109,18 +109,18 @@ class Admin(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.container = cname t.time = '3' t.url = '/TiVoConnect?Command='+ last_page +'&Container=' + quote(cname) t.text = RESET_MSG % (quote(last_page), quote(cname)) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) logging.getLogger('pyTivo.admin').info('pyTivo has been soft reset.') def Admin(self, handler, query): - #Read config file new each time in case there was any outside edits + # Read config file new each time in case there was any outside edits config = ConfigParser.ConfigParser() config.read(config_file_path) @@ -134,8 +134,6 @@ class Admin(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] - handler.send_response(200) - handler.end_headers() t = Template(SETTINGS_TEMPLATE) t.container = cname t.quote = quote @@ -148,6 +146,8 @@ class Admin(Plugin): if section.startswith('_tivo_')] t.tivos_known = buildhelp.getknown('tivos') t.help_list = buildhelp.gethelp() + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) def UpdateSettings(self, handler, query): @@ -168,7 +168,7 @@ class Admin(Plugin): config.set('Server', new_setting, new_value) sections = query['Section_Map'][0].split(']') - sections.pop() #last item is junk + sections.pop() # last item is junk for section in sections: ID, name = section.split('|') if query[ID][0] == "Delete_Me": @@ -198,22 +198,22 @@ class Admin(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.container = cname t.time = '10' t.url = '/TiVoConnect?Command=Admin&Container=' + quote(cname) t.text = SETTINGS1 % quote(cname) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) def NPL(self, handler, query): - shows_per_page = 50 #Change this to alter the number of shows returned + shows_per_page = 50 # Change this to alter the number of shows returned subcname = query['Container'][0] cname = subcname.split('/')[0] folder = '' AnchorItem = '' - AnchorOffset= '' + AnchorOffset = '' for name, data in config.getShares(): if cname == name: tivo_mak = data.get('tivo_mak', '') @@ -243,33 +243,33 @@ class Admin(Plugin): if theurl in tivo_cache: #check if we've accessed this page before if (tivo_cache[theurl]['thepage'] == '' or (time.time() - tivo_cache[theurl]['thepage_time']) >= 60): - #if page is empty or old then retreive it + # if page is empty or old then retreive it try: handle = urllib2.urlopen(r) except IOError, e: - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.container = cname t.time = '20' t.url = ('/TiVoConnect?Command=NPL&Container=' + quote(cname)) t.text = UNABLE % (tivoIP, quote(cname)) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) return tivo_cache[theurl]['thepage'] = handle.read() tivo_cache[theurl]['thepage_time'] = time.time() - else: #not in cache + else: # not in cache try: handle = urllib2.urlopen(r) except IOError, e: - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.container = cname t.time = '20' t.url = '/TiVoConnect?Command=NPL&Container=' + quote(cname) t.text = UNABLE % (tivoIP, quote(cname)) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) return tivo_cache[theurl] = {} @@ -337,9 +337,6 @@ class Admin(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] - handler.send_response(200) - handler.send_header('Content-Type', 'text/html; charset=UTF-8') - handler.end_headers() t = Template(NPL_TEMPLATE) t.quote = quote t.folder = folder @@ -358,13 +355,16 @@ class Admin(Plugin): t.ItemCount = int(ItemCount) t.FirstAnchor = quote(FirstAnchor) t.shows_per_page = shows_per_page + handler.send_response(200) + handler.send_header('Content-Type', 'text/html; charset=UTF-8') + handler.end_headers() handler.wfile.write(unicode(t).encode('utf-8')) def get_tivo_file(self, url, mak, tivoIP, outfile): - #global status + # global status cj = cookielib.LWPCookieJar() - r=urllib2.Request(url) + r = urllib2.Request(url) auth_handler = urllib2.HTTPDigestAuthHandler() auth_handler.add_password('TiVo DVR', tivoIP, 'tivo', mak) opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), @@ -374,9 +374,9 @@ class Admin(Plugin): try: handle = urllib2.urlopen(r) except IOError, e: - #If we get "Too many transfers error" try a second time. - #For some reason urllib2 does not properly close connections - #when a transfer is canceled. + # If we get "Too many transfers error" try a second time. + # For some reason urllib2 does not properly close + # connections when a transfer is canceled. if e.code == 503: try: handle = urllib2.urlopen(r) @@ -393,18 +393,19 @@ class Admin(Plugin): kilobytes = 0 start_time = time.time() output = handle.read(1024) - while status[url]['running'] and output != '': + while status[url]['running'] and output: kilobytes += 1 f.write(output) - if ((time.time() - start_time) >= 5): - status[url]['rate'] = int(kilobytes/(time.time() - start_time)) + now = time.time() + elapsed = now - start_time + if elapsed >= 5: + status[url]['rate'] = int(kilobytes / elapsed) kilobytes = 0 - start_time = time.time() + start_time = now output = handle.read(1024) status[url]['running'] = False handle.close() f.close() - return def ToGo(self, handler, query): subcname = query['Container'][0] @@ -414,6 +415,9 @@ class Admin(Plugin): if cname == name: tivo_mak = data.get('tivo_mak', '') togo_path = data.get('togo_path', '') + t = Template(REDIRECT_TEMPLATE) + command = query['Redirect'][0] + params = (command, quote(cname), tivoIP) if tivo_mak and togo_path: parse_url = urlparse(str(query['Url'][0])) theurl = 'http://%s%s?%s' % (parse_url[1].split(':')[0], @@ -428,25 +432,16 @@ class Admin(Plugin): thread.start_new_thread(Admin.get_tivo_file, (self, theurl, tivo_mak, tivoIP, outfile)) - handler.send_response(200) - handler.end_headers() - t = Template(REDIRECT_TEMPLATE) - command = query['Redirect'][0] t.time = '3' - t.url = ('/TiVoConnect?Command=' + command + '&Container=' + - quote(cname) + '&TiVo=' + tivoIP) - t.text = TRANS_INIT % (command, quote(cname), tivoIP) - handler.wfile.write(t) + t.text = TRANS_INIT % params else: - handler.send_response(200) - handler.end_headers() - t = Template(REDIRECT_TEMPLATE) - command = query['Redirect'][0] t.time = '10' - t.url = ('/TiVoConnect?Command=' + command + '&Container=' + - quote(cname) + '&TiVo=' + tivoIP) - t.text = MISSING % (command, quote(cname), tivoIP) - handler.wfile.write(t) + t.text = MISSING % params + t.url = ('/TiVoConnect?Command=' + command + '&Container=' + + quote(cname) + '&TiVo=' + tivoIP) + handler.send_response(200) + handler.end_headers() + handler.wfile.write(t) def ToGoStop(self, handler, query): parse_url = urlparse(str(query['Url'][0])) @@ -459,16 +454,15 @@ class Admin(Plugin): cname = subcname.split('/')[0] tivoIP = query['TiVo'][0] command = query['Redirect'][0] - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.time = '3' t.url = ('/TiVoConnect?Command=' + command + '&Container=' + quote(cname) + '&TiVo=' + tivoIP) t.text = TRANS_STOP % (command, quote(cname), tivoIP) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) - def SaveNPL(self, handler, query): config = ConfigParser.ConfigParser() config.read(config_file_path) @@ -484,12 +478,12 @@ class Admin(Plugin): subcname = query['Container'][0] cname = subcname.split('/')[0] - handler.send_response(200) - handler.end_headers() t = Template(REDIRECT_TEMPLATE) t.container = cname t.time = '2' t.url = ('/TiVoConnect?last_page=NPL&Command=Reset&Container=' + quote(cname)) t.text = SETTINGS2 % quote(cname) + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index a8df235..ec75225 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -78,10 +78,10 @@ def transcode(isQuery, inFile, outFile, tsn=''): except: kill(ffmpeg.pid) -def select_audiocodec(isQuery, inFile, tsn = ''): +def select_audiocodec(isQuery, inFile, tsn=''): # Default, compatible with all TiVo's codec = 'ac3' - vInfo = video_info(inFile) + vInfo = video_info(inFile) codectype = vInfo['vCodec'] if config.getAudioCodec(tsn) == None: if vInfo['aCodec'] in ('ac3', 'liba52', 'mp2'): @@ -110,17 +110,18 @@ def select_audiocodec(isQuery, inFile, tsn = ''): def select_audiofr(inFile, tsn): freq = '48000' #default - vInfo = video_info(inFile) + vInfo = video_info(inFile) if not vInfo['aFreq'] == None and vInfo['aFreq'] in ('44100', '48000'): # compatible frequency freq = vInfo['aFreq'] if config.getAudioFR(tsn) != None: freq = config.getAudioFR(tsn) - return '-ar '+freq + return '-ar ' + freq def select_audioch(tsn): - if config.getAudioCH(tsn) != None: - return '-ac '+config.getAudioCH(tsn) + ch = config.getAudioCH(tsn) + if ch: + return '-ac ' + ch return '' def select_audiolang(inFile, tsn): @@ -141,18 +142,18 @@ def select_audiolang(inFile, tsn): def select_videofps(inFile, tsn): vInfo = video_info(inFile) - fps = '-r 29.97' #default + fps = '-r 29.97' # default if config.isHDtivo(tsn) and vInfo['vFps'] not in BAD_MPEG_FPS: fps = ' ' if config.getVideoFPS(tsn) != None: - fps = '-r '+config.getVideoFPS(tsn) + fps = '-r ' + config.getVideoFPS(tsn) return fps def select_videocodec(tsn): - codec = 'mpeg2video' #default - if config.getVideoCodec(tsn) != None: - codec = config.getVideoCodec(tsn) - return '-vcodec '+codec + codec = config.getVideoCodec(tsn) + if not codec: + codec = 'mpeg2video' # default + return '-vcodec ' + codec def select_videobr(inFile, tsn): return '-b ' + str(select_videostr(inFile, tsn) / 1000) + 'k' @@ -178,15 +179,16 @@ def select_buffsize(tsn): return '-bufsize ' + config.getBuffSize(tsn) def select_ffmpegprams(tsn): - if config.getFFmpegPrams(tsn) != None: - return config.getFFmpegPrams(tsn) - return '' + params = config.getFFmpegPrams(tsn) + if not params: + params = '' + return params def select_format(tsn): - fmt = 'vob' - if config.getFormat(tsn) != None: - fmt = config.getFormat(tsn) - return '-f ' + fmt + ' -' + fmt = config.getFormat(tsn) + if not fmt: + fmt = 'vob' + return '-f %s -' % fmt def select_aspect(inFile, tsn = ''): TIVO_WIDTH = config.getTivoWidth(tsn) @@ -198,11 +200,11 @@ def select_aspect(inFile, tsn = ''): aspect169 = config.get169Setting(tsn) - logging.debug('aspect169:%s' % aspect169) + logging.debug('aspect169: %s' % aspect169) optres = config.getOptres(tsn) - logging.debug('optres:%s' % optres) + logging.debug('optres: %s' % optres) if optres: optHeight = config.nearestTivoHeight(vInfo['vHeight']) @@ -213,7 +215,7 @@ def select_aspect(inFile, tsn = ''): TIVO_WIDTH = optWidth d = gcd(vInfo['vHeight'], vInfo['vWidth']) - ratio = (vInfo['vWidth'] * 100) / vInfo['vHeight'] + ratio = vInfo['vWidth'] * 100 / vInfo['vHeight'] rheight, rwidth = vInfo['vHeight'] / d, vInfo['vWidth'] / d logger.debug(('File=%s vCodec=%s vWidth=%s vHeight=%s vFps=%s ' + @@ -278,13 +280,13 @@ def select_aspect(inFile, tsn = ''): # If video is wider than 4:3 add top and bottom padding - if (ratio > 133): # Might be 16:9 file, or just need padding on - # top and bottom + if ratio > 133: # Might be 16:9 file, or just need padding on + # top and bottom - if aspect169 and (ratio > 135): # If file would fall in 4:3 - # assume it is supposed to be 4:3 + if aspect169 and ratio > 135: # If file would fall in 4:3 + # assume it is supposed to be 4:3 - if (ratio > 177): # too short needs padding top and bottom + if ratio > 177: # too short needs padding top and bottom endHeight = int(((TIVO_WIDTH * vInfo['vHeight']) / vInfo['vWidth']) * multiplier16by9) settings.append('-aspect') @@ -416,10 +418,10 @@ def select_aspect(inFile, tsn = ''): return settings -def tivo_compatible(inFile, tsn = ''): - supportedModes = [[720, 480], [704, 480], [544, 480], [528, 480], - [480, 480], [352, 480]] - vInfo = video_info(inFile) +def tivo_compatible(inFile, tsn=''): + supportedModes = [(720, 480), (704, 480), (544, 480), + (528, 480), (480, 480), (352, 480)] + vInfo = video_info(inFile) while True: if (inFile[-5:]).lower() == '.tivo': @@ -462,7 +464,7 @@ def tivo_compatible(inFile, tsn = ''): vInfo['kbps']) break - if config.getAudioLang(tsn) is not None: + if config.getAudioLang(tsn): if vInfo['mapAudio'][0][0] != select_audiolang(inFile, tsn)[-3:]: message = (False, ('TRANSCODE=YES, %s preferred audio ' + 'track exists.') % config.getAudioLang(tsn)) @@ -493,7 +495,7 @@ def tivo_compatible(inFile, tsn = ''): break for mode in supportedModes: - if (mode[0], mode[1]) == (vInfo['vWidth'], vInfo['vHeight']): + if mode == (vInfo['vWidth'], vInfo['vHeight']): message = (True, 'TRANSCODE=NO, %s x %s is valid.' % (vInfo['vWidth'], vInfo['vHeight'])) break @@ -521,8 +523,8 @@ def video_info(inFile): info_cache[inFile] = (mtime, vInfo) logger.debug('VALID, ends in .tivo. %s' % inFile) return vInfo - - cmd = [ffmpeg_path(), '-i', inFile ] + + cmd = [ffmpeg_path(), '-i', inFile] # Windows and other OS buffer 4096 and ffmpeg can output more than that. err_tmp = tempfile.TemporaryFile() ffmpeg = subprocess.Popen(cmd, stderr=err_tmp, stdout=subprocess.PIPE, @@ -573,10 +575,10 @@ def video_info(inFile): # Allow override only if it is mpeg2 and frame rate was doubled # to 59.94 - if (not vInfo['vFps'] == '29.97') and (vInfo['vCodec'] == 'mpeg2video'): + if vInfo['vCodec'] == 'mpeg2video' and vInfo['vFps'] != '29.97': # First look for the build 7215 version rezre = re.compile(r'.*film source: 29.97.*') - x = rezre.search(output.lower() ) + x = rezre.search(output.lower()) if x: logger.debug('film source: 29.97 setting vFps to 29.97') vInfo['vFps'] = '29.97' @@ -585,7 +587,7 @@ def video_info(inFile): rezre = re.compile(r'.*frame rate differs from container ' + r'frame rate: 29.97.*') logger.debug('Bug in VideoReDo') - x = rezre.search(output.lower() ) + x = rezre.search(output.lower()) if x: vInfo['vFps'] = '29.97' else: @@ -604,7 +606,7 @@ def video_info(inFile): else: vInfo['millisecs'] = 0 - #get bitrate of source for tivo compatibility test. + # get bitrate of source for tivo compatibility test. rezre = re.compile(r'.*bitrate: (.+) (?:kb/s).*') x = rezre.search(output) if x: @@ -613,7 +615,7 @@ def video_info(inFile): vInfo['kbps'] = None logger.debug('failed at kbps') - #get audio bitrate of source for tivo compatibility test. + # get audio bitrate of source for tivo compatibility test. rezre = re.compile(r'.*Audio: .+, (.+) (?:kb/s).*') x = rezre.search(output) if x: @@ -622,7 +624,7 @@ def video_info(inFile): vInfo['aKbps'] = None logger.debug('failed at aKbps') - #get audio codec of source for tivo compatibility test. + # get audio codec of source for tivo compatibility test. rezre = re.compile(r'.*Audio: ([^,]+),.*') x = rezre.search(output) if x: @@ -631,7 +633,7 @@ def video_info(inFile): vInfo['aCodec'] = None logger.debug('failed at aCodec') - #get audio frequency of source for tivo compatibility test. + # get audio frequency of source for tivo compatibility test. rezre = re.compile(r'.*Audio: .+, (.+) (?:Hz).*') x = rezre.search(output) if x: @@ -640,7 +642,7 @@ def video_info(inFile): vInfo['aFreq'] = None logger.debug('failed at aFreq') - #get par. + # get par. rezre = re.compile(r'.*Video: .+PAR ([0-9]+):([0-9]+) DAR [0-9:]+.*') x = rezre.search(output) if x and x.group(1) != "0" and x.group(2) != "0": @@ -649,7 +651,7 @@ def video_info(inFile): else: vInfo['par1'], vInfo['par2'] = None, None - #get dar. + # get dar. rezre = re.compile(r'.*Video: .+DAR ([0-9]+):([0-9]+).*') x = rezre.search(output) if x and x.group(1) != "0" and x.group(2) != "0": @@ -658,7 +660,7 @@ def video_info(inFile): else: vInfo['dar1'], vInfo['dar2'] = None, None - #get Video Stream mapping. + # get Video Stream mapping. rezre = re.compile(r'([0-9]+\.[0-9]+).*: Video:.*') x = rezre.search(output) if x: @@ -667,8 +669,7 @@ def video_info(inFile): vInfo['mapVideo'] = None logger.debug('failed at mapVideo') - - #get Audio Stream mapping. + # get Audio Stream mapping. rezre = re.compile(r'([0-9]+\.[0-9]+)(.*): Audio:.*') x = rezre.search(output) amap = [] @@ -680,7 +681,6 @@ def video_info(inFile): logger.debug('failed at mapAudio') vInfo['mapAudio'] = amap - videoPlugin = GetPlugin('video') metadata = videoPlugin.getMetadataFromTxt(inFile) @@ -735,7 +735,7 @@ def win32kill(pid): ctypes.windll.kernel32.TerminateProcess(handle, -1) ctypes.windll.kernel32.CloseHandle(handle) -def gcd(a,b): +def gcd(a, b): while b: a, b = b, a % b return a diff --git a/plugins/video/video.py b/plugins/video/video.py index 6c59b75..5d9b7d4 100644 --- a/plugins/video/video.py +++ b/plugins/video/video.py @@ -251,8 +251,6 @@ class Video(Plugin): videos.append(video) - handler.send_response(200) - handler.end_headers() t = Template(CONTAINER_TEMPLATE) t.container = cname t.name = subcname @@ -265,6 +263,8 @@ class Video(Plugin): t.guid = config.getGUID() t.tivos = handler.tivos t.tivo_names = handler.tivo_names + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) def TVBusQuery(self, handler, query): @@ -278,11 +278,11 @@ class Video(Plugin): if file_info['valid']: file_info.update(self.metadata_full(file_path, tsn)) - handler.send_response(200) - handler.end_headers() t = Template(TVBUS_TEMPLATE) t.video = file_info t.escape = escape + handler.send_response(200) + handler.end_headers() handler.wfile.write(t) def XSL(self, handler, query): diff --git a/plugins/webvideo/webvideo.py b/plugins/webvideo/webvideo.py index 8aa5f67..34ccf50 100644 --- a/plugins/webvideo/webvideo.py +++ b/plugins/webvideo/webvideo.py @@ -61,7 +61,7 @@ class WebVideo(Video): for user_name in xmpp_info['presence_list']: self.__logger.debug('Sending presence to %s' % user_name) - jid=xmpp.protocol.JID(user_name) + jid = xmpp.protocol.JID(user_name) cl.sendPresence(jid) t = threading.Thread(target=self.processXMPP, args=(cl,)) diff --git a/pyTivoService.py b/pyTivoService.py index 761176b..058c253 100644 --- a/pyTivoService.py +++ b/pyTivoService.py @@ -27,7 +27,6 @@ class PyTivoService(win32serviceutil.ServiceFramework): f = open(os.path.join(p, 'log.txt'), 'w') sys.stdout = f sys.stderr = f - port = config.getPort() -- 2.11.4.GIT