X-Git-Url: https://git.ao2.it/smooth-dl.git/blobdiff_plain/3c5d261bdf46670b00120423be912ea65c7ea2a0..5823e17e70b2fe749ce6d5998b8f01cc0db1537e:/smooth-dl.py diff --git a/smooth-dl.py b/smooth-dl.py index 44ef722..60c3e00 100755 --- a/smooth-dl.py +++ b/smooth-dl.py @@ -2,7 +2,7 @@ # # smooth-dl - download videos served using Smooth Streaming technology # -# Copyright (C) 2010 Antonio Ospite +# Copyright (C) 2010-2016 Antonio Ospite # # 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 @@ -94,12 +94,18 @@ def write_wav_header(out_file, fmt, codec_private_data, data_len): def download_file(src_url, dest_file, mode): - try: - response = urllib2.urlopen(src_url) - data = response.read() - except urllib2.HTTPError: - sys.stderr.write("Error while dowloading URL: %s" % src_url) - raise + + if os.path.exists(src_url): + f = open(src_url, "rb") + data = f.read() + f.close() + else: + try: + response = urllib2.urlopen(src_url) + data = response.read() + except urllib2.HTTPError: + sys.stderr.write("Error while dowloading URL: %s\n" % src_url) + raise if dest_file: f = open(dest_file, mode) @@ -118,11 +124,8 @@ def get_manifest(url, dest_dir): if not manifest_url.lower().endswith(('/manifest', '.ismc', '.csm')): manifest_url += '/Manifest' - if manifest_url.startswith('http://'): - local_manifest_path = os.path.join(dest_dir, 'Manifest') - download_file(manifest_url, local_manifest_path, "w") - else: - local_manifest_path = url + local_manifest_path = os.path.join(dest_dir, 'Manifest') + download_file(manifest_url, local_manifest_path, "w") manifest = etree.parse(local_manifest_path) @@ -130,13 +133,18 @@ def get_manifest(url, dest_dir): if version != "2": raise Exception('Only Smooth Streaming version 2 supported') - try: - # if some intermediate client Manifest is used, like in Rai Replay - clip = manifest.find("Clip") - manifest_url = clip.attrib["Url"] - manifest = download_file(manifest_url, None, None) - except AttributeError: - pass + # if some intermediate client Manifest is used, like in Rai Replay + # then get the final manifest + clip = manifest.find("Clip") + if clip is not None and "Url" in clip.attrib: + tmp_manifest_url = clip.attrib["Url"] + try: + tmp_manifest = download_file(tmp_manifest_url, None, None) + # set the new values only if the dowload succeded + manifest_url = tmp_manifest_url + manifest = tmp_manifest + except urllib2.HTTPError: + pass manifest_pattern = re.compile("/manifest$", re.IGNORECASE) base_url = manifest_pattern.sub("", manifest_url)