-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_video.py
executable file
·84 lines (70 loc) · 2.3 KB
/
get_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
"""
* File: get_video.py - Retrieves streaming video from videolectures.net URLs
*
* Copyright (c) 2009 Uldis Bojars <[email protected]>
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RTMPDump; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
"""
import os
import re
import sys
import urllib2
def get_params(in_url):
html = urllib2.urlopen(in_url).read()
re_rtmp = re.search( r'streamer: "([^"]+)"', html ).groups()[0]
path = re.search( r'file: "([^"]+)"', html ).groups()[0]
if path.endswith(".flv"):
re_path = path[:-4]
re_file = path.split("/")[-1]
re_param = re.search( r'swfobject.embedSWF\(([^\)]+)\)', html).groups()[0]
return { 'rtmp': re_rtmp, 'path': re_path, 'file': re_file} #, 'param': re_param}
def gen_command(p):
tpl = """rtmpdump/rtmpdump \\
-r %(rtmp)s/%(path)s \\
-t %(rtmp)s \\
-o %(file)s \\
-s http://media.videolectures.net/jw-player/player.swf \\
-f "MAC 9,0,151,0" \\
-g %(path)s \\
-a video
"""
return tpl % p
def exec_command(cmd):
print ">>> Executing:"
print cmd
print
try:
ret = os.system(cmd)
print
print "Rtmpdump finished.\nResult code:", ret
except OSError, e:
print >>sys.stderr, "Execution failed:", e
def main(in_url):
cmd = gen_command(get_params(in_url))
exec_command(cmd)
usage = """
get_video.py - Retrieve streaming video from videolectures.net URLs
Usage: ./get_video.py http://url
Parameters:
- http://url - a URL to a videolectures.net page containing the video
"""
if __name__ == "__main__":
if len(sys.argv) > 1:
main(sys.argv[1])
else:
print usage