1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

Adding resume support for RTMP streams.

This commit is contained in:
Johan Andersson 2011-12-18 20:50:42 +01:00
parent cd89d851b2
commit 1e88439f0c

View File

@ -52,7 +52,7 @@ class Common(object):
if byte >= total:
sys.stdout.write('\n')
def getrtmp(self, url, output, live, other):
def getrtmp(self, url, output, live, other, resume):
""" Get the stream from RTMP """
encrypted = ""
@ -62,7 +62,11 @@ class Common(object):
if live:
live = "-v"
rtmpdump = "rtmpdump -r %s -o %s %s %s %s" % (url, output, encrypted, other, live)
if resume:
resume = "-e"
rtmpdump = "rtmpdump -r %s -o %s %s %s %s %s" % (url, output, encrypted, other, live, resume)
print(rtmpdump)
command = shlex.split(str(rtmpdump))
subprocess.call(command)
@ -87,11 +91,12 @@ class Common(object):
file_d.close()
class Sr(Common):
def __init__(self, output, quality, live, other):
def __init__(self, output, quality, live, other, resume):
self.output = output
self.quality = quality
self.live = live
self.other = other
self.resume = resume
def get(self, url):
url = url + self.other
@ -106,10 +111,11 @@ class Sr(Common):
self.gethttp(url, self.output)
class Urplay(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url):
other = "-a ondemand"
@ -123,14 +129,15 @@ class Urplay(Common):
self.output = os.path.basename(path)
print("Outfile: ", self.output)
self.getrtmp("rtmp://streaming.ur.se/", self.output, self.live, other)
self.getrtmp("rtmp://streaming.ur.se/", self.output, self.live, other, self.resume)
class Qbrick(Common):
def __init__(self, output, quality, live, other):
def __init__(self, output, quality, live, other, resume):
self.output = output
self.quality = quality
self.live = live
self.other = other
self.resume = resume
def get(self, url):
host = url + "/rest/v3/getsingleplayer/" + self.other
@ -181,14 +188,15 @@ class Qbrick(Common):
print("Outfile: ", self.output)
other = "-y %s" % path
self.getrtmp(server, self.output, self.live, other)
self.getrtmp(server, self.output, self.live, other, self.resume)
class Kanal5(Common):
def __init__(self, output, quality, live, other):
def __init__(self, output, quality, live, other, resume):
self.output = output
self.quality = quality
self.live = live
self.other = other
self.resume = resume
def get(self, url):
try:
@ -237,13 +245,14 @@ class Kanal5(Common):
filename = streams[int(self.quality)]["uri"]
match = re.search("(rtmp[e]{0,1}://.*)\&(.*)$", filename)
other = "-y %s -W %s" % (match.group(2), "http://admin.brightcove.com/viewer/us1.25.04.01.2011-05-24182704/connection/ExternalConnection_2.swf")
self.getrtmp(match.group(1), self.output, self.live, other)
self.getrtmp(match.group(1), self.output, self.live, other, self.resume)
class Expressen(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url):
other = ""
@ -285,13 +294,14 @@ class Expressen(Common):
filename = "rtmp://%s" % match.group(1)
other = "-y %s" % match.group(2)
self.getrtmp(filename, self.output, self.live, other)
self.getrtmp(filename, self.output, self.live, other, self.resume)
class Aftonbladet(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url, start):
data = self.getdata(url)
@ -312,16 +322,17 @@ class Aftonbladet(Common):
print("Outfile: ", self.output)
if url[0:4] == "rtmp":
self.getrtmp(url, self.output, self.live, other)
self.getrtmp(url, self.output, self.live, other, self.resume)
else:
filename = url + path
self.gethttp(filename, self.output)
class Viaplay(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url):
other = ""
@ -339,13 +350,14 @@ class Viaplay(Common):
print("Outfile: ", self.output)
other = "-W http://flvplayer.viastream.viasat.tv/play/swf/player110516.swf?rnd=1315434062"
self.getrtmp(filename, self.output, self.live, other)
self.getrtmp(filename, self.output, self.live, other, self.resume)
class Tv4play(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url):
data = self.getdata(url)
@ -386,13 +398,14 @@ class Tv4play(Common):
self.output = os.path.basename(streams[str(self.quality)]["path"])
print("Outfile: ", self.output)
self.getrtmp(streams[str(self.quality)]["uri"], self.output, self.live, other)
self.getrtmp(streams[str(self.quality)]["uri"], self.output, self.live, other, self.resume)
class Svtplay(Common):
def __init__(self, output, quality, live):
def __init__(self, output, quality, live, resume):
self.output = output
self.quality = quality
self.live = live
self.resume = resume
def get(self, url):
other = "-W http://svtplay.se/flash/svtplayer-2011.18.swf"
@ -425,7 +438,7 @@ class Svtplay(Common):
print("Outfile: ", self.output)
if filename[0:4] == "rtmp":
self.getrtmp(filename, self.output, self.live, other)
self.getrtmp(filename, self.output, self.live, other, self.resume)
else:
self.gethttp(filename, self.output)
@ -435,6 +448,9 @@ def main():
parser = OptionParser(usage=usage)
parser.add_option("-o", "--output",
metavar="OUTPUT", help="Outputs to the given filename.")
parser.add_option("-r", "--resume",
action="store_true", dest="resume", default=False,
help="Resume a download")
parser.add_option("-l", "--live",
action="store_true", dest="live", default=False,
help="Enable for live streams")
@ -446,6 +462,7 @@ def main():
output = options.output
live = options.live
quality = options.quality
resume = options .resume
url = args[0]
if re.findall("tv4play", url):
@ -456,7 +473,7 @@ def main():
print("Something wrong with that url")
sys.exit(2)
url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid
tv4play = Tv4play(output, quality, live)
tv4play = Tv4play(output, quality, live, resume)
tv4play.get(url)
elif re.findall("(tv3play|tv6play|tv8play)", url):
@ -466,7 +483,7 @@ def main():
print("Something wrong with that url")
sys.exit(2)
url = "http://viastream.viasat.tv/PlayProduct/%s" % match.group(1)
viaplay = Viaplay(output, quality, live)
viaplay = Viaplay(output, quality, live, resume)
viaplay.get(url)
elif re.findall("viaplay", url):
@ -482,7 +499,7 @@ def main():
if not match:
print("Something wrong with that url")
url = "http://viastream.viasat.tv/PlayProduct/%s" % match.group(1)
viaplay = Viaplay(output, quality, live)
viaplay = Viaplay(output, quality, live, resume)
viaplay.get(url)
elif re.findall("aftonbladet", url):
@ -498,7 +515,7 @@ def main():
except KeyError:
start = 0
url = "http://www.aftonbladet.se/resource/webbtv/article/%s/player" % match.group(1)
aftonbladet = Aftonbladet(output, quality, live)
aftonbladet = Aftonbladet(output, quality, live, resume)
aftonbladet.get(url, start)
elif re.findall("expressen", url):
@ -508,7 +525,7 @@ def main():
print("Something wrong with that url")
sys.exit(2)
url = "http://tv.expressen.se/%s/?standAlone=true&output=xml" % quote_plus(match.group(1))
expressen = Expressen(output, quality, live)
expressen = Expressen(output, quality, live, resume)
expressen.get(url)
elif re.findall("(kanal5play|kanal9play)", url):
@ -528,7 +545,7 @@ def main():
if not match:
print("Something wrong with that url")
sys.exit(2)
qbrick = Qbrick(output, quality, live, match.group(1))
qbrick = Qbrick(output, quality, live, match.group(1), resume)
qbrick.get("http://vms.api.qbrick.com")
elif re.findall("di.se", url):
@ -538,7 +555,7 @@ def main():
if not match:
print("Something wrong with that url")
sys.exit(2)
qbrick = Qbrick(output, quality, live, match.group(1))
qbrick = Qbrick(output, quality, live, match.group(1), resume)
qbrick.get("http://vms.api.qbrick.com")
elif re.findall("svd.se", url):
@ -555,7 +572,7 @@ def main():
print("Something wrong with that url")
sys.exit(2)
qbrick = Qbrick(output, quality, live, match.group(1))
qbrick = Qbrick(output, quality, live, match.group(1), resume)
qbrick.get("http://vms.api.qbrick.com")
elif re.findall("urplay.se", url):
@ -570,11 +587,11 @@ def main():
print("Something wrong with that url")
sys.exit(2)
sr = Sr(output, quality, live, unquote_plus(match.group(1)))
sr = Sr(output, quality, live, unquote_plus(match.group(1)), resume)
sr.get("http://sverigesradio.se")
else:
svtplay = Svtplay(output, quality, live)
svtplay = Svtplay(output, quality, live, resume)
svtplay.get(url)