From 18a7c798e8e0f4534229496f284ce3f275ab35ae Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Wed, 21 Mar 2007 04:09:04 +0000 Subject: [PATCH] - pyTivo * Added 16:9 blacklist * Added per tivo 16:9 settings --- Config.py | 31 +++++++++++++++++++++++++++++++ plugins/video/transcode.py | 38 +++++++++++++++----------------------- plugins/video/video.py | 6 ++++-- pyTivo.conf | 9 +++++---- pyTivo.py | 10 +++++----- pyTivoService.py | 10 +++++----- 6 files changed, 65 insertions(+), 39 deletions(-) diff --git a/Config.py b/Config.py index dfaecf7..ab9c278 100644 --- a/Config.py +++ b/Config.py @@ -1,5 +1,36 @@ import ConfigParser, os +BLACKLIST_169 = ('540', '649') + config = ConfigParser.ConfigParser() p = os.path.dirname(__file__) config.read(os.path.join(p, 'pyTivo.conf')) + +def get169Setting(tsn): + if not tsn: + return True + + if config.has_section('_tivo_' + tsn): + if config.has_option('_tivo_' + tsn, 'aspect169'): + if config.get('_tivo_' + tsn, 'aspect169').lower() == 'true': + return True + else: + return False + + if tsn[:3] in BLACKLIST_169: + return False + + return True + +def getShares(): + return filter( lambda x: not(x.startswith('_tivo_') or x == 'Server'), config.sections()) + +def getDebug(): + try: + debug = config.get('Server', 'debug') + if debug.lower() == 'true': + return True + else: + return False + except NoOptionError: + return False diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index 59e3307..56b0987 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -1,26 +1,12 @@ import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache from ConfigParser import ConfigParser, NoOptionError from Config import config +import Config info_cache = lrucache.LRUCache(1000) -try: - debug = config.get('Server', 'debug') - if debug.lower() == 'true': - debug = True - else: - debug = False -except NoOptionError: - debug = False - -try: - aspect169 = config.get('Server', 'aspect169') - if aspect169.lower() == 'true': - aspect169 = True - else: - aspect169 = False -except NoOptionError: #default to 4:3 unless specified in config - aspect169 = False + +debug = Config.getDebug() FFMPEG = config.get('Server', 'ffmpeg') @@ -47,7 +33,7 @@ mswindows = (sys.platform == "win32") if mswindows: patchSubprocess() -def output_video(inFile, outFile): +def output_video(inFile, outFile, tsn=''): if tivo_compatable(inFile): debug_write(['output_video: ', inFile, ' is tivo compatible\n']) f = file(inFile, 'rb') @@ -55,10 +41,10 @@ def output_video(inFile, outFile): f.close() else: debug_write(['output_video: ', inFile, ' is not tivo compatible\n']) - transcode(inFile, outFile) + transcode(inFile, outFile, tsn) -def transcode(inFile, outFile): - cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile) + ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192','-ar', '44100', '-f', 'vob', '-' ] +def transcode(inFile, outFile, tsn=''): + cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile, tsn) + ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192','-ar', '44100', '-f', 'vob', '-' ] debug_write(['transcode: ffmpeg command is ', ''.join(cmd), '\n']) ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) try: @@ -66,9 +52,15 @@ def transcode(inFile, outFile): except: kill(ffmpeg.pid) -def select_aspect(inFile): +def select_aspect(inFile, tsn = ''): type, width, height, fps, millisecs = video_info(inFile) - + + debug_write(['tsn:', tsn, '\n']) + + aspect169 = Config.get169Setting(tsn) + + debug_write(['aspect169:', aspect169, '\n']) + d = gcd(height,width) ratio = (width*100)/height rheight, rwidth = height/d, width/d diff --git a/plugins/video/video.py b/plugins/video/video.py index 13706cb..8d08fc4 100644 --- a/plugins/video/video.py +++ b/plugins/video/video.py @@ -26,12 +26,14 @@ class video(Plugin): handler.end_headers() handler.wfile.write("\x30\x0D\x0A") return - + + tsn = handler.headers.getheader('tsn', '') + o = urlparse("http://fake.host" + handler.path) path = unquote_plus(o[2]) handler.send_response(200) handler.end_headers() - transcode.output_video(container['path'] + path[len(name)+1:], handler.wfile) + transcode.output_video(container['path'] + path[len(name)+1:], handler.wfile, tsn) diff --git a/pyTivo.conf b/pyTivo.conf index be34caa..6285f17 100644 --- a/pyTivo.conf +++ b/pyTivo.conf @@ -1,5 +1,4 @@ [Server] -#You probably don't need to change this port=9032 #Full path to ffmpeg including filename @@ -11,10 +10,12 @@ ffmpeg=C:\Documents and Settings\Armooo\Desktop\pyTivoSrc\plugins\video\ffmpeg_m #transcode.py right now. debug=false -#Is your TV and TiVo set to 16:9 aspect ratio? -#If so enable 16:9 aspect ratio -aspect169=false +##Per tivo options +# section named _tivo_TSN with the tsn in all caps +#[_tivo_2400000DEADBEEF] +#If you want to use 16:9 or 4:3 on this tivo +#aspect169=true [MyMovies] #Type can be either 'video' or 'audio' diff --git a/pyTivo.py b/pyTivo.py index 3d9ca8f..0afaa51 100644 --- a/pyTivo.py +++ b/pyTivo.py @@ -4,16 +4,16 @@ import beacon, httpserver, os, sys from Config import config +import Config port = config.get('Server', 'Port') httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler) -for section in config.sections(): - if not section == 'Server': - settings = {} - settings.update(config.items(section)) - httpd.add_container(section, settings) +for section in Config.getShares(): + settings = {} + settings.update(config.items(section)) + httpd.add_container(section, settings) b = beacon.Beacon() b.add_service('TiVoMediaServer:' + str(port) + '/http') diff --git a/pyTivoService.py b/pyTivoService.py index 1a7dce9..2f9f6be 100644 --- a/pyTivoService.py +++ b/pyTivoService.py @@ -3,6 +3,7 @@ import win32serviceutil import win32service import win32event import select, sys +import Config class PyTivoService(win32serviceutil.ServiceFramework): _svc_name_ = 'pyTivo' @@ -29,11 +30,10 @@ class PyTivoService(win32serviceutil.ServiceFramework): httpd = httpserver.TivoHTTPServer(('', int(port)), httpserver.TivoHTTPHandler) - for section in config.sections(): - if not section == 'Server': - settings = {} - settings.update(config.items(section)) - httpd.add_container(section, settings) + for section in Config.getShares(): + settings = {} + settings.update(config.items(section)) + httpd.add_container(section, settings) b = beacon.Beacon() b.add_service('TiVoMediaServer:' + str(port) + '/http') -- 2.11.4.GIT