From: Antonio Ospite Date: Fri, 15 Jan 2016 10:29:05 +0000 (+0100) Subject: smooth-dl.py: add support for downloading chunks with the 'd' attribute X-Git-Url: https://git.ao2.it/smooth-dl.git/commitdiff_plain/1437199b7a501d9052e0be91f9834a4b609499f2?ds=inline smooth-dl.py: add support for downloading chunks with the 'd' attribute --- diff --git a/smooth-dl.py b/smooth-dl.py index 41dfc4c..4fdbca1 100755 --- a/smooth-dl.py +++ b/smooth-dl.py @@ -199,10 +199,9 @@ def get_chunk_quality_string(stream, quality_level): return chunks_quality -def get_chunk_name_string(stream, chunk): - t = chunk.attrib["t"] +def get_chunk_name_string(stream, chunk_time): url = stream.attrib["Url"] - chunk_name = url.split('/')[1].replace("{start time}", t) + chunk_name = url.split('/')[1].replace("{start time}", str(chunk_time)) return chunk_name @@ -225,9 +224,17 @@ def download_chunks(base_url, manifest, stream_index, quality_level, dest_dir): print "\nDownloading Stream %d" % stream_index print "\tChunks %10d/%-10d" % (0, len(chunks)), "\r", sys.stdout.flush() - for i, c in enumerate(chunks): - chunk_name = get_chunk_name_string(stream, c) + stream_duration = 0 + for i, chunk in enumerate(chunks): + + if "t" in chunk.attrib: + chunk_time = chunk.attrib["t"] + elif "d" in chunk.attrib: + chunk_time = stream_duration + stream_duration = chunk_time + int(chunk.attrib["d"]) + + chunk_name = get_chunk_name_string(stream, chunk_time) chunk_file = os.path.join(dest_dir, chunks_quality, chunk_name) if not os.path.exists(chunk_file): @@ -263,9 +270,17 @@ def rebuild_stream(manifest, stream_index, quality_level, src_dir, print "\nRebuilding Stream %d" % stream_index print "\tChunks %10d/%-10d" % (0, len(chunks)), "\r", sys.stdout.flush() - for i, c in enumerate(chunks): - chunk_name = get_chunk_name_string(stream, c) + stream_duration = 0 + for i, chunk in enumerate(chunks): + + if "t" in chunk.attrib: + chunk_time = chunk.attrib["t"] + elif "d" in chunk.attrib: + chunk_time = stream_duration + stream_duration = chunk_time + int(chunk.attrib["d"]) + + chunk_name = get_chunk_name_string(stream, chunk_time) chunk_file = os.path.join(chunks_src_dir, chunk_name) f = open(chunk_file, "rb") @@ -308,9 +323,16 @@ def calc_tracks_delay(manifest, stream1_index, stream2_index): s1 = streams[stream1_index] s2 = streams[stream2_index] + if "TimeScale" not in s1 or "TimeScale" not in s2: + return 0 + s1_start_chunk = s1.find("c") s2_start_chunk = s2.find("c") + if "t" not in s1_start_chunk.attrib \ + or "t" not in s2_start_chunk.attrib: + return 0 + s1_start_time = int(s1_start_chunk.attrib['t']) s2_start_time = int(s2_start_chunk.attrib['t'])