forked from soimort/you-get
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtmpdump.py
More file actions
55 lines (45 loc) · 1.38 KB
/
rtmpdump.py
File metadata and controls
55 lines (45 loc) · 1.38 KB
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
#!/usr/bin/env python
import os.path
import subprocess
def get_usable_rtmpdump(cmd):
try:
p = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
return cmd
except:
return None
RTMPDUMP = get_usable_rtmpdump('rtmpdump')
def has_rtmpdump_installed():
return RTMPDUMP is not None
#
#params ={"-y":"playlist","-q":None,}
#if Only Key ,Value should be None
#-r -o should not be included in params
def download_rtmpdump_stream(url, title, ext,params={},output_dir='.'):
filename = '%s.%s' % (title, ext)
filepath = os.path.join(output_dir, filename)
cmdline = [RTMPDUMP, '-r']
cmdline.append(url)
cmdline.append('-o')
cmdline.append(filepath)
for key in params.keys():
cmdline.append(key)
if params[key]!=None:
cmdline.append(params[key])
# cmdline.append('-y')
# cmdline.append(playpath)
print("Call rtmpdump:\n"+" ".join(cmdline)+"\n")
subprocess.call(cmdline)
return
#
#To be refactor
#
def play_rtmpdump_stream(player, url, params={}):
cmdline="rtmpdump -r '%s' "%url
for key in params.keys():
cmdline+=key+" "+params[key] if params[key]!=None else ""+" "
cmdline+=" -o - | %s -"%player
print(cmdline)
os.system(cmdline)
# os.system("rtmpdump -r '%s' -y '%s' -o - | %s -" % (url, playpath, player))
return