Changeset 2393bc1b52479317efc5baadc25a513cd7a23e25
- 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
| r047584c |
r2393bc1 |
|
| 4 | 4 | from cgi import parse_qs |
|---|
| 5 | 5 | from Cheetah.Template import Template |
|---|
| 6 | | from transcode import output_video |
|---|
| | 6 | import transcode |
|---|
| 7 | 7 | |
|---|
| 8 | 8 | class TivoHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): |
|---|
| … | … | |
| 63 | 63 | path = container['path'] |
|---|
| 64 | 64 | for folder in folders[1:]: |
|---|
| | 65 | if folder == '..': |
|---|
| | 66 | return |
|---|
| 65 | 67 | path = path + '/' + folder |
|---|
| 66 | 68 | |
|---|
| | 69 | def isdir(file): |
|---|
| | 70 | path = container['path'] + '/' + file |
|---|
| | 71 | return os.path.isdir(path) |
|---|
| | 72 | |
|---|
| 67 | 73 | files = os.listdir(path) |
|---|
| | 74 | |
|---|
| | 75 | files = filter(lambda f: os.path.isdir(path+'/'+f) or transcode.suported_format(path+'/'+f), files) |
|---|
| | 76 | |
|---|
| 68 | 77 | totalFiles = len(files) |
|---|
| 69 | | |
|---|
| | 78 | |
|---|
| | 79 | index = 0 |
|---|
| 70 | 80 | if query.has_key('ItemCount'): |
|---|
| 71 | 81 | count = int(query['ItemCount'] [0]) |
|---|
| 72 | | index = 0 |
|---|
| 73 | 82 | |
|---|
| 74 | 83 | if query.has_key('AnchorItem'): |
|---|
| 75 | 84 | anchor = query['AnchorItem'] [0] |
|---|
| 76 | 85 | 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] |
|---|
| 78 | 91 | if file_url == anchor: |
|---|
| 79 | 92 | index = i + 1 |
|---|
| … | … | |
| 107 | 120 | self.send_response(200) |
|---|
| 108 | 121 | 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) |
|---|
| 112 | 123 | |
|---|
| 113 | 124 | def infopage(self): |
|---|
| r047584c |
r2393bc1 |
|
| 27 | 27 | <Item> |
|---|
| 28 | 28 | <Details> |
|---|
| 29 | | <Title>$file</Title> |
|---|
| | 29 | <Title>#echo '.'.join(file.split('.')[:-1]) #</Title> |
|---|
| 30 | 30 | <ContentType>video/x-tivo-mpeg</ContentType> |
|---|
| 31 | 31 | <SourceFormat>video/x-tivo-mpeg</SourceFormat> |
|---|
| r94b3427 |
r2393bc1 |
|
| 12 | 12 | |
|---|
| 13 | 13 | 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 |
|---|
| 15 | 14 | ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
|---|
| 16 | 15 | try: |
|---|
| … | … | |
| 21 | 20 | def select_aspect(inFile): |
|---|
| 22 | 21 | type, height, width, fps = video_info(inFile) |
|---|
| 23 | | print type, height, width, fps |
|---|
| 24 | 22 | |
|---|
| 25 | 23 | d = gcd(height,width) |
|---|
| 26 | 24 | |
|---|
| 27 | 25 | rheight, rwidth = height/d, width/d |
|---|
| 28 | | print height, width |
|---|
| 29 | 26 | |
|---|
| 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)]: |
|---|
| 31 | 28 | 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)]: |
|---|
| 33 | 30 | return '-aspect 16:9 -s 720x480' |
|---|
| 34 | 31 | else: |
|---|
| … | … | |
| 39 | 36 | if endHeight % 2: |
|---|
| 40 | 37 | endHeight -= 1 |
|---|
| 41 | | print endHeight |
|---|
| 42 | 38 | |
|---|
| 43 | 39 | settings.append('-s 720x' + str(endHeight)) |
|---|
| … | … | |
| 70 | 66 | def video_info(inFile): |
|---|
| 71 | 67 | 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) |
|---|
| 73 | 70 | output = ffmpeg.stderr.read() |
|---|
| | 71 | print ffmpeg.stdout.read() |
|---|
| 74 | 72 | |
|---|
| 75 | 73 | rezre = re.compile(r'.*Video: (.+), (\d+)x(\d+), (.+) fps.*') |
|---|
| … | … | |
| 79 | 77 | else: |
|---|
| 80 | 78 | return None, None, None, None |
|---|
| 81 | | |
|---|
| | 79 | |
|---|
| | 80 | def suported_format(inFile): |
|---|
| | 81 | if video_info(inFile)[0]: |
|---|
| | 82 | return True |
|---|
| | 83 | else: |
|---|
| | 84 | return False |
|---|
| | 85 | |
|---|
| 82 | 86 | def win32kill(pid): |
|---|
| 83 | 87 | import ctypes |
|---|