From c3d52f8e7eb0219b3f52b7c3e87e286aba872664 Mon Sep 17 00:00:00 2001 From: wgw Date: Sat, 1 Mar 2008 00:22:19 -0600 Subject: [PATCH] \n added to function and removed from debug_write statements --- debug.py | 8 +++--- httpserver.py | 4 +-- plugins/video/transcode.py | 72 +++++++++++++++++++++++----------------------- plugins/video/video.py | 42 +++++++++++++-------------- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/debug.py b/debug.py index e22fc66..ea934e5 100644 --- a/debug.py +++ b/debug.py @@ -10,7 +10,7 @@ def debug_write(srcMod, fnAttr, data): for x in data: debug_out.append(str(x)) fdebug = open('debug.txt', 'a') - fdebug.write(' '.join(debug_out)) + fdebug.write(' '.join(debug_out)+'\n') print ' '.join(debug_out) fdebug.close() @@ -20,12 +20,12 @@ def fn_attr(): def print_conf(srcMod, fnAttr): if config.getDebug(): - debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----\n']) + debug_write(srcMod, fnAttr, ['----- begin pyTivo.conf -----']) conf = open(os.path.join(p, 'pyTivo.conf')) for line in conf.readlines(): if line.strip().startswith('#'): continue if len(line.strip()) != 0: - debug_write(srcMod, fnAttr, [line.strip(), '\n']) + debug_write(srcMod, fnAttr, [line.strip()]) conf.close() - debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----\n']) + debug_write(srcMod, fnAttr, ['------- end pyTivo.conf -----']) diff --git a/httpserver.py b/httpserver.py index adacb5d..86d4eb5 100644 --- a/httpserver.py +++ b/httpserver.py @@ -114,14 +114,14 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): def unsupported(self, query): if hack83 and 'Command' in query and 'Filter' in query: debug_write(__name__, fn_attr(), ['Unsupported request,', - 'checking to see if it is video.\n']) + 'checking to see if it is video.']) command = query['Command'][0] plugin = GetPlugin('video') if ''.join(query['Filter']).find('video') >= 0 and \ hasattr(plugin, command): debug_write(__name__, fn_attr(), ['Unsupported request,', 'yup it is video', - 'send to video plugin for it to sort out.\n']) + 'send to video plugin for it to sort out.']) method = getattr(plugin, command) method(self, query) return diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index 54b4792..a7008c7 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -24,12 +24,12 @@ if mswindows: def output_video(inFile, outFile, tsn=''): if tivo_compatable(inFile, tsn): - debug_write(__name__, fn_attr(), [inFile, ' is tivo compatible\n']) + debug_write(__name__, fn_attr(), [inFile, ' is tivo compatible']) f = file(inFile, 'rb') shutil.copyfileobj(f, outFile) f.close() else: - debug_write(__name__, fn_attr(), [inFile, ' is not tivo compatible\n']) + debug_write(__name__, fn_attr(), [inFile, ' is not tivo compatible']) transcode(inFile, outFile, tsn) def transcode(inFile, outFile, tsn=''): @@ -48,7 +48,7 @@ def transcode(inFile, outFile, tsn=''): cmd = [FFMPEG, '-i', inFile] + cmd_string.split() print 'transcoding to tivo model '+tsn[:3]+' using ffmpeg command:' print cmd - debug_write(__name__, fn_attr(), ['ffmpeg command is ', ' '.join(cmd), '\n']) + debug_write(__name__, fn_attr(), ['ffmpeg command is ', ' '.join(cmd)]) ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) try: shutil.copyfileobj(ffmpeg.stdout, outFile) @@ -90,15 +90,15 @@ def select_aspect(inFile, tsn = ''): type, width, height, fps, millisecs, kbps, akbps, acodec, afreq = video_info(inFile) - debug_write(__name__, fn_attr(), ['tsn:', tsn, '\n']) + debug_write(__name__, fn_attr(), ['tsn:', tsn]) aspect169 = config.get169Setting(tsn) - debug_write(__name__, fn_attr(), ['aspect169:', aspect169, '\n']) + debug_write(__name__, fn_attr(), ['aspect169:', aspect169]) optres = config.getOptres() - debug_write(__name__, fn_attr(), ['optres:', optres, '\n']) + debug_write(__name__, fn_attr(), ['optres:', optres]) if optres: optHeight = config.nearestTivoHeight(height) @@ -112,7 +112,7 @@ def select_aspect(inFile, tsn = ''): ratio = (width*100)/height rheight, rwidth = height/d, width/d - debug_write(__name__, fn_attr(), ['File=', inFile, ' Type=', type, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' ratio=', ratio, ' rheight=', rheight, ' rwidth=', rwidth, ' TIVO_HEIGHT=', TIVO_HEIGHT, 'TIVO_WIDTH=', TIVO_WIDTH, '\n']) + debug_write(__name__, fn_attr(), ['File=', inFile, ' Type=', type, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' ratio=', ratio, ' rheight=', rheight, ' rwidth=', rwidth, ' TIVO_HEIGHT=', TIVO_HEIGHT, 'TIVO_WIDTH=', TIVO_WIDTH]) multiplier16by9 = (16.0 * TIVO_HEIGHT) / (9.0 * TIVO_WIDTH) multiplier4by3 = (4.0 * TIVO_HEIGHT) / (3.0 * TIVO_WIDTH) @@ -121,10 +121,10 @@ def select_aspect(inFile, tsn = ''): return [] #pass all resolutions to S3/HD, except heights greater than conf height # else, optres is enabled and resizes SD video to the "S2" standard on S3/HD. elif (rwidth, rheight) in [(4, 3), (10, 11), (15, 11), (59, 54), (59, 72), (59, 36), (59, 54)]: - debug_write(__name__, fn_attr(), ['File is within 4:3 list.\n']) + debug_write(__name__, fn_attr(), ['File is within 4:3 list.']) return ['-aspect', '4:3', '-s', str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)] elif ((rwidth, rheight) in [(16, 9), (20, 11), (40, 33), (118, 81), (59, 27)]) and aspect169: - debug_write(__name__, fn_attr(), ['File is within 16:9 list and 16:9 allowed.\n']) + debug_write(__name__, fn_attr(), ['File is within 16:9 list and 16:9 allowed.']) return ['-aspect', '16:9', '-s', str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)] else: settings = [] @@ -153,7 +153,7 @@ def select_aspect(inFile, tsn = ''): else: #if only very small amount of padding needed, then just stretch it settings.append('-s') settings.append(str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)) - debug_write(__name__, fn_attr(), ['16:9 aspect allowed, file is wider than 16:9 padding top and bottom\n', ' '.join(settings), '\n']) + debug_write(__name__, fn_attr(), ['16:9 aspect allowed, file is wider than 16:9 padding top and bottom', ' '.join(settings)]) else: #too skinny needs padding on left and right. endWidth = int((TIVO_HEIGHT*width)/(height*multiplier16by9)) settings.append('-aspect') @@ -176,7 +176,7 @@ def select_aspect(inFile, tsn = ''): else: #if only very small amount of padding needed, then just stretch it settings.append('-s') settings.append(str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)) - debug_write(__name__, fn_attr(), ['16:9 aspect allowed, file is narrower than 16:9 padding left and right\n', ' '.join(settings), '\n']) + debug_write(__name__, fn_attr(), ['16:9 aspect allowed, file is narrower than 16:9 padding left and right\n', ' '.join(settings)]) else: #this is a 4:3 file or 16:9 output not allowed settings.append('-aspect') settings.append('4:3') @@ -199,7 +199,7 @@ def select_aspect(inFile, tsn = ''): else: #if only very small amount of padding needed, then just stretch it settings.append('-s') settings.append(str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)) - debug_write(__name__, fn_attr(), ['File is wider than 4:3 padding top and bottom\n', ' '.join(settings), '\n']) + debug_write(__name__, fn_attr(), ['File is wider than 4:3 padding top and bottom\n', ' '.join(settings)]) return settings #If video is taller than 4:3 add left and right padding, this is rare. All of these files will always be sent in @@ -227,7 +227,7 @@ def select_aspect(inFile, tsn = ''): settings.append('-s') settings.append(str(TIVO_WIDTH) + 'x' + str(TIVO_HEIGHT)) - debug_write(__name__, fn_attr(), ['File is taller than 4:3 padding left and right\n', ' '.join(settings), '\n']) + debug_write(__name__, fn_attr(), ['File is taller than 4:3 padding left and right\n', ' '.join(settings)]) return settings @@ -237,39 +237,39 @@ def tivo_compatable(inFile, tsn = ''): #print type, width, height, fps, millisecs, kbps, akbps, acodec if (inFile[-5:]).lower() == '.tivo': - debug_write(__name__, fn_attr(), ['True, ', inFile, ' ends with .tivo\n']) + debug_write(__name__, fn_attr(), ['True, ', inFile, ' ends with .tivo']) return True if not type == 'mpeg2video': #print 'Not Tivo Codec' - debug_write(__name__, fn_attr(), ['False, ', inFile, ' is not mpeg2video it is ', type, '\n']) + debug_write(__name__, fn_attr(), ['False, ', inFile, ' is not mpeg2video it is ', type]) return False if (inFile[-3:]).lower() == '.ts': - debug_write(__name__, fn_attr(), ['False, ', inFile, ' transport stream not supported ', '\n']) + debug_write(__name__, fn_attr(), ['False, ', inFile, ' transport stream not supported']) return False if not akbps or int(akbps) > config.getMaxAudioBR(tsn): - debug_write(__name__, fn_attr(), ['False, ', inFile, ' max audio bitrate exceeded it is ', akbps, '\n']) + debug_write(__name__, fn_attr(), ['False, ', inFile, ' max audio bitrate exceeded it is ', akbps]) return False if not kbps or int(kbps)-int(akbps) > config.strtod(config.getMaxVideoBR())/1000: - debug_write(__name__, fn_attr(), ['False, ', inFile, ' max video bitrate exceeded it is ', kbps, '\n']) + debug_write(__name__, fn_attr(), ['False, ', inFile, ' max video bitrate exceeded it is ', kbps]) return False if config.isHDtivo(tsn): - debug_write(__name__, fn_attr(), ['True, ', inFile, ' you have a S3 skiping the rest of the tests', '\n']) + debug_write(__name__, fn_attr(), ['True, ', inFile, ' you have a S3 skiping the rest of the tests']) return True if not fps == '29.97': #print 'Not Tivo fps' - debug_write(__name__, fn_attr(), ['False, ', inFile, ' is not correct fps it is ', fps, '\n']) + debug_write(__name__, fn_attr(), ['False, ', inFile, ' is not correct fps it is ', fps]) return False for mode in supportedModes: if (mode[0], mode[1]) == (width, height): #print 'Is TiVo!' - debug_write(__name__, fn_attr(), ['True, ', inFile, ' has correct width of ', width, ' and height of ', height, '\n']) + debug_write(__name__, fn_attr(), ['True, ', inFile, ' has correct width of ', width, ' and height of ', height]) return True #print 'Not Tivo dimensions' return False @@ -278,12 +278,12 @@ def video_info(inFile): mtime = os.stat(inFile).st_mtime if inFile != videotest: if inFile in info_cache and info_cache[inFile][0] == mtime: - debug_write(__name__, fn_attr(), [inFile, ' cache hit!', '\n']) + debug_write(__name__, fn_attr(), [inFile, ' cache hit!']) return info_cache[inFile][1] if (inFile[-5:]).lower() == '.tivo': info_cache[inFile] = (mtime, (True, True, True, True, True, True, True, True, True)) - debug_write(__name__, fn_attr(), [inFile, ' ends in .tivo.\n']) + debug_write(__name__, fn_attr(), [inFile, ' ends in .tivo.']) return True, True, True, True, True, True, True, True, True cmd = [FFMPEG, '-i', inFile ] @@ -301,7 +301,7 @@ def video_info(inFile): return None, None, None, None, None, None, None, None, None output = ffmpeg.stderr.read() - debug_write(__name__, fn_attr(), ['ffmpeg output=', output, '\n']) + debug_write(__name__, fn_attr(), ['ffmpeg output=', output]) rezre = re.compile(r'.*Video: ([^,]+),.*') x = rezre.search(output) @@ -309,7 +309,7 @@ def video_info(inFile): codec = x.group(1) else: info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) - debug_write(__name__, fn_attr(), ['failed at codec\n']) + debug_write(__name__, fn_attr(), ['failed at codec']) return None, None, None, None, None, None, None, None, None rezre = re.compile(r'.*Video: .+, (\d+)x(\d+)[, ].*') @@ -319,7 +319,7 @@ def video_info(inFile): height = int(x.group(2)) else: info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) - debug_write(__name__, fn_attr(), ['failed at width/height\n']) + debug_write(__name__, fn_attr(), ['failed at width/height']) return None, None, None, None, None, None, None, None, None rezre = re.compile(r'.*Video: .+, (.+) (?:fps|tb).*') @@ -328,7 +328,7 @@ def video_info(inFile): fps = x.group(1) else: info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) - debug_write(__name__, fn_attr(), ['failed at fps\n']) + debug_write(__name__, fn_attr(), ['failed at fps']) return None, None, None, None, None, None, None, None, None # Allow override only if it is mpeg2 and frame rate was doubled to 59.94 @@ -337,12 +337,12 @@ def video_info(inFile): rezre = re.compile(r'.*film source: 29.97.*') x = rezre.search(output.lower() ) if x: - debug_write(__name__, fn_attr(), ['film source: 29.97 setting fps to 29.97\n']) + debug_write(__name__, fn_attr(), ['film source: 29.97 setting fps to 29.97']) fps = '29.97' else: # for build 8047: rezre = re.compile(r'.*frame rate differs from container frame rate: 29.97.*') - debug_write(__name__, fn_attr(), ['Bug in VideoReDo\n']) + debug_write(__name__, fn_attr(), ['Bug in VideoReDo']) x = rezre.search(output.lower() ) if x: fps = '29.97' @@ -361,7 +361,7 @@ def video_info(inFile): kbps = x.group(1) else: kbps = None - debug_write(__name__, fn_attr(), ['failed at kbps\n']) + debug_write(__name__, fn_attr(), ['failed at kbps']) #get audio bitrate of source for tivo compatibility test. rezre = re.compile(r'.*Audio: .+, (.+) (?:kb/s).*') @@ -370,7 +370,7 @@ def video_info(inFile): akbps = x.group(1) else: akbps = None - debug_write(__name__, fn_attr(), ['failed at akbps\n']) + debug_write(__name__, fn_attr(), ['failed at akbps']) #get audio codec of source for tivo compatibility test. rezre = re.compile(r'.*Audio: ([^,]+),.*') @@ -379,7 +379,7 @@ def video_info(inFile): acodec = x.group(1) else: acodec = None - debug_write(__name__, fn_attr(), ['failed at acodec\n']) + debug_write(__name__, fn_attr(), ['failed at acodec']) #get audio frequency of source for tivo compatibility test. rezre = re.compile(r'.*Audio: .+, (.+) (?:Hz).*') @@ -388,10 +388,10 @@ def video_info(inFile): afreq = x.group(1) else: afreq = None - debug_write(__name__, fn_attr(), ['failed at afreq\n']) + debug_write(__name__, fn_attr(), ['failed at afreq']) info_cache[inFile] = (mtime, (codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq)) - debug_write(__name__, fn_attr(), ['Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, ' acodec=', acodec, ' afreq=', afreq, '\n']) + debug_write(__name__, fn_attr(), ['Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, ' acodec=', acodec, ' afreq=', afreq]) return codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq def video_check(inFile, cmd_string): @@ -408,11 +408,11 @@ def supported_format(inFile): if video_info(inFile)[0]: return True else: - debug_write(__name__, fn_attr(), [inFile, ' is not supported\n']) + debug_write(__name__, fn_attr(), [inFile, ' is not supported']) return False def kill(pid): - debug_write(__name__, fn_attr(), ['killing pid=', str(pid), '\n']) + debug_write(__name__, fn_attr(), ['killing pid=', str(pid)]) if mswindows: win32kill(pid) else: diff --git a/plugins/video/video.py b/plugins/video/video.py index 9ce682f..75ee29d 100644 --- a/plugins/video/video.py +++ b/plugins/video/video.py @@ -23,7 +23,7 @@ except: hack83 = config.getHack83() if hack83: - debug_write(__name__, fn_attr(), ['Hack83 is enabled.\n']) + debug_write(__name__, fn_attr(), ['Hack83 is enabled.']) class Video(Plugin): @@ -46,8 +46,8 @@ class Video(Plugin): return transcode.supported_format(full_path) def hack(self, handler, query, subcname): - debug_write(__name__, fn_attr(), ['new request ------------------------\n']) - debug_write(__name__, fn_attr(), ['TiVo request is: \n', query, '\n']) + debug_write(__name__, fn_attr(), ['new request ------------------------']) + debug_write(__name__, fn_attr(), ['TiVo request is: \n', query]) queryAnchor = '' rightAnchor = '' leftAnchor = '' @@ -56,7 +56,7 @@ class Video(Plugin): # not a tivo if not tsn: debug_write(__name__, fn_attr(), ['this was not a TiVo request.', - 'Using default tsn.\n']) + 'Using default tsn.']) tsn = '123456789' # this breaks up the anchor item request into seperate parts @@ -71,12 +71,12 @@ class Video(Plugin): leftAnchor, rightAnchor = queryAnchor.rsplit('/', 1) debug_write(__name__, fn_attr(), ['queryAnchor: ', queryAnchor, ' leftAnchor: ', leftAnchor, - ' rightAnchor: ', rightAnchor, '\n']) + ' rightAnchor: ', rightAnchor]) try: path, state = self.request_history[tsn] except KeyError: # Never seen this tsn, starting new history - debug_write(__name__, fn_attr(), ['New TSN.\n']) + debug_write(__name__, fn_attr(), ['New TSN.']) path = [] state = {} self.request_history[tsn] = (path, state) @@ -84,7 +84,7 @@ class Video(Plugin): state['page'] = '' state['time'] = int(time.time()) + 1000 - debug_write(__name__, fn_attr(), ['our saved request is: \n', state['query'], '\n']) + debug_write(__name__, fn_attr(), ['our saved request is: \n', state['query']]) current_folder = subcname.split('/')[-1] @@ -94,7 +94,7 @@ class Video(Plugin): # 1. at the root - This request is always accurate if len(subcname.split('/')) == 1: debug_write(__name__, fn_attr(), ['we are at the root.', - 'Saving query, Clearing state[page].\n']) + 'Saving query, Clearing state[page].']) path[:] = [current_folder] state['query'] = query state['page'] = '' @@ -105,7 +105,7 @@ class Video(Plugin): # entering a new folder. if 'AnchorItem' not in query: debug_write(__name__, fn_attr(), ['we are entering a new folder.', - 'Saving query, setting time, setting state[page].\n']) + 'Saving query, setting time, setting state[page].']) path[:] = subcname.split('/') state['query'] = query state['time'] = int(time.time()) @@ -121,12 +121,12 @@ class Video(Plugin): # we know this is the proper page if ''.join(query['AnchorItem']) == 'Hack8.3': debug_write(__name__, fn_attr(), ['requested page from 302 code.', - 'Returning saved query,\n']) + 'Returning saved query.']) return state['query'], path # 4. this is a request for a file if 'ItemCount' in query and int(''.join(query['ItemCount'])) == 1: - debug_write(__name__, fn_attr(), ['requested a file', '\n']) + debug_write(__name__, fn_attr(), ['requested a file']) # Everything in this request is right except the container query['Container'] = ['/'.join(path)] state['page'] = '' @@ -138,7 +138,7 @@ class Video(Plugin): # Sleep just in case the erroneous request came first this # allows a proper request to be processed first - debug_write(__name__, fn_attr(), ['maybe erroneous request, sleeping.\n']) + debug_write(__name__, fn_attr(), ['maybe erroneous request, sleeping.']) time.sleep(.25) # 5. scrolling in a folder @@ -147,18 +147,18 @@ class Video(Plugin): # First we have to figure out if we are scrolling if 'AnchorOffset' in query: debug_write(__name__, fn_attr(), ['Anchor offset was in query.', - 'leftAnchor needs to match ', '/'.join(path), '\n']) + 'leftAnchor needs to match ', '/'.join(path)]) if leftAnchor == str('/'.join(path)): - debug_write(__name__, fn_attr(), ['leftAnchor matched.', '\n']) + debug_write(__name__, fn_attr(), ['leftAnchor matched.']) query['Container'] = ['/'.join(path)] files, total, start = self.get_files(handler, query, self.video_file_filter) debug_write(__name__, fn_attr(), ['saved page is= ', state['page'], - ' top returned file is= ', files[0], '\n']) + ' top returned file is= ', files[0]]) # If the first file returned equals the top of the page # then we haven't scrolled pages if files[0] != str(state['page']): - debug_write(__name__, fn_attr(), ['this is scrolling within a folder.\n']) + debug_write(__name__, fn_attr(), ['this is scrolling within a folder.']) state['page'] = files[0] return query, path @@ -169,14 +169,14 @@ class Video(Plugin): # this came within a second of a valid request; just use that # request. if (int(time.time()) - state['time']) <= 1: - debug_write(__name__, fn_attr(), ['erroneous request, send a 302 error', '\n']) + debug_write(__name__, fn_attr(), ['erroneous request, send a 302 error']) return None, path # 7. this is a request to exit a folder # this request came by itself; it must be to exit a folder else: debug_write(__name__, fn_attr(), ['over 1 second,', - 'must be request to exit folder\n']) + 'must be request to exit folder']) path.pop() state['query'] = {'Command': query['Command'], 'SortOrder': query['SortOrder'], @@ -187,7 +187,7 @@ class Video(Plugin): # just in case we missed something. debug_write(__name__, fn_attr(), ['ERROR, should not have made it here. ', - 'Trying to recover.\n']) + 'Trying to recover.']) return state['query'], path def send_file(self, handler, container, name): @@ -334,11 +334,11 @@ class Video(Plugin): hackPath = '/'.join(hackPath) print 'Tivo said:', subcname, '|| Hack said:', hackPath debug_write(__name__, fn_attr(), ['Tivo said: ', subcname, ' || Hack said: ', - hackPath, '\n']) + hackPath]) subcname = hackPath if not query: - debug_write(__name__, fn_attr(), ['sending 302 redirect page', '\n']) + debug_write(__name__, fn_attr(), ['sending 302 redirect page']) handler.send_response(302) handler.send_header('Location ', 'http://' + handler.headers.getheader('host') + -- 2.11.4.GIT