Changeset 2393bc1b52479317efc5baadc25a513cd7a23e25

Show
Ignore:
Timestamp:
11/24/06 22:20:46 (2 years ago)
Author:
Jason Michalski <armooo@armooo.net>
git-committer:
Jason Michalski <armooo@armooo.net> 1164428446 +0000
git-parent:

[1bb86933f01f106d5db2b4026280627e35bef3cd]

git-author:
Jason Michalski <armooo@armooo.net> 1164428446 +0000
Message:

pyTivo
- Fixed AnchorItem? when a folder
- Should do a better job picking an aspect ratio

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • httpserver.py

    r047584c r2393bc1  
    44from cgi import parse_qs 
    55from Cheetah.Template import Template 
    6 from transcode import output_video 
     6import transcode 
    77 
    88class TivoHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): 
     
    6363            path = container['path'] 
    6464            for folder in folders[1:]: 
     65                if folder == '..': 
     66                    return 
    6567                path = path + '/' + folder 
    6668            
     69            def isdir(file): 
     70                path = container['path'] + '/' + file 
     71                return os.path.isdir(path) 
     72            
    6773            files = os.listdir(path) 
     74 
     75            files = filter(lambda f: os.path.isdir(path+'/'+f) or transcode.suported_format(path+'/'+f), files) 
     76             
    6877            totalFiles = len(files) 
    69              
     78            
     79            index = 0 
    7080            if query.has_key('ItemCount'): 
    7181                count = int(query['ItemCount'] [0]) 
    72                 index = 0 
    7382                 
    7483                if query.has_key('AnchorItem'): 
    7584                    anchor = query['AnchorItem'] [0] 
    7685                    for i in range(len(files)): 
    77                         file_url = '/' + subcname + '/' + files[i] 
     86                         
     87                        if isdir(files[i]): 
     88                            file_url = '/TiVoConnect?Command=QueryContainer&Container=' + subcname + '/' + files[i] 
     89                        else:                                 
     90                            file_url = '/' + subcname + '/' + files[i] 
    7891                        if file_url == anchor: 
    7992                            index = i + 1 
     
    107120        self.send_response(200) 
    108121        self.end_headers() 
    109         #rfile = open(container['path'] + path[len(name)+1:], 'rb') 
    110         #shutil.copyfileobj(rfile, self.wfile) 
    111         output_video(container['path'] + path[len(name)+1:], self.wfile) 
     122        transcode.output_video(container['path'] + path[len(name)+1:], self.wfile) 
    112123     
    113124    def infopage(self): 
  • templates/container.tmpl

    r047584c r2393bc1  
    2727    <Item> 
    2828        <Details> 
    29             <Title>$file</Title> 
     29            <Title>#echo '.'.join(file.split('.')[:-1]) #</Title> 
    3030            <ContentType>video/x-tivo-mpeg</ContentType> 
    3131            <SourceFormat>video/x-tivo-mpeg</SourceFormat> 
  • transcode.py

    r94b3427 r2393bc1  
    1212 
    1313    cmd = "ffmpeg_mp2.exe -i \"%s\" -vcodec mpeg2video -r 29.97 -b 4096 %s -ac 2 -ab 192 -f vob -" % (inFile, select_aspect(inFile)) 
    14     print cmd 
    1514    ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) 
    1615    try: 
     
    2120def select_aspect(inFile): 
    2221    type, height, width, fps =  video_info(inFile) 
    23     print type, height, width, fps 
    2422     
    2523    d = gcd(height,width) 
    2624 
    2725    rheight, rwidth = height/d, width/d 
    28     print height, width 
    2926 
    30     if (rheight, rwidth) == (4, 3)
     27    if (rheight, rwidth) in [(4, 3), (10, 11), (15, 11), (59, 54), (59, 72), (59, 36), (59, 54)]
    3128        return '-aspect 4:3 -s 720x480' 
    32     elif (rheight, rwidth) == (16, 9)
     29    elif (rheight, rwidth) in [(16, 9), (20, 11), (40, 33), (118, 81), (59, 27)]
    3330        return '-aspect 16:9 -s 720x480' 
    3431    else: 
     
    3936        if endHeight % 2: 
    4037            endHeight -= 1 
    41         print endHeight 
    4238 
    4339        settings.append('-s 720x' + str(endHeight)) 
     
    7066def video_info(inFile): 
    7167    cmd = "ffmpeg_mp2.exe -i \"%s\"" % inFile 
    72     ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE) 
     68    print cmd 
     69    ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) 
    7370    output = ffmpeg.stderr.read() 
     71    print ffmpeg.stdout.read() 
    7472     
    7573    rezre = re.compile(r'.*Video: (.+), (\d+)x(\d+), (.+) fps.*') 
     
    7977    else: 
    8078        return None, None, None, None 
    81          
     79        
     80def suported_format(inFile): 
     81    if video_info(inFile)[0]: 
     82        return True 
     83    else: 
     84        return False 
     85 
    8286def win32kill(pid): 
    8387        import ctypes