return open(filename)
src = _urlopen(url)
- dst = open(filename, "w")
+ dst = open(filename, "wb")
try:
shutil.copyfileobj(src, dst)
except Exception, e:
return False
-def avconv_remux(infile, outfile):
+def check_command_exists(cmd):
+ try:
+ subprocess.check_output(cmd)
+ return True
+ except Exception:
+ return False
+
+def generate_remux_cmd(infile, outfile):
+ if check_command_exists(["avconv", "--help"]):
+ return [
+ "avconv",
+ "-i", infile,
+ "-bsf:a", "aac_adtstoasc",
+ "-acodec", "copy",
+ "-vcodec", "copy",
+ outfile,
+ ]
+
+ if check_command_exists(["ffmpeg", "--help"]):
+ return [
+ "ffmpeg",
+ "-i", infile,
+ "-bsf:a", "aac_adtstoasc",
+ "-acodec", "copy",
+ "-vcodec", "copy",
+ outfile,
+ ]
+
+ raise Exception("You must install ffmpeg or libav-tools")
+
+def remux(infile, outfile):
print "Converting %s to mp4" % infile
- cmd = [
- "avconv",
- "-i", infile,
- "-acodec", "copy",
- "-vcodec", "copy",
- outfile,
- ]
+ cmd = generate_remux_cmd(infile, outfile)
if not exec_subprocess(cmd):
# failed, error has already been logged
return False
if ext in (".flv", ".ts"):
filename_mp4 = basename + ".mp4"
- return avconv_remux(filename, filename_mp4)
+ return remux(filename, filename_mp4)
return ext == ".mp4"
print "Downloading: %s" % filename
try:
src = _urlopen(url, referrer)
- dst = open(filename, "w")
+ dst = open(filename, "wb")
while True:
buf = src.read(1024*1024)
if not buf:
pass
def download_hls(filename, m3u8_master_url, hack_url_func=None):
+ filename = sanify_filename(filename)
+ print "Downloading: %s" % filename
+
if hack_url_func is None:
hack_url_func = lambda url: url
tmpdir = tempfile.mkdtemp(prefix="webdl-hls")
- print "Downloading: %s" % filename
-
try:
best_stream_url = download_hls_get_stream(hack_url_func(m3u8_master_url))
- ts_file = open(filename, "w")
+ ts_file = open(filename, "wb")
download_hls_segments(ts_file, hack_url_func(best_stream_url))
except KeyboardInterrupt:
print "\nCancelled", m3u8_master_url