Print more details when downloading a chunk fails
[smooth-dl.git] / smooth-dl.py
index 16ee966..29115b3 100755 (executable)
@@ -92,8 +92,7 @@ def write_wav_header(out_file, fmt, codec_private_data, data_len):
     out_file.write(struct.pack('<L', data_len))
 
 
-def get_manifest(base_url, dest_dir=tempfile.gettempdir(),
-        manifest_file='Manifest'):
+def get_manifest(base_url, dest_dir=tempfile.gettempdir()):
     """Returns the manifest and the new URL if this is changed"""
 
     if os.path.exists(dest_dir) == False:
@@ -108,7 +107,7 @@ def get_manifest(base_url, dest_dir=tempfile.gettempdir(),
         response = urllib2.urlopen(manifest_url)
         data = response.read()
 
-        manifest_path = os.path.join(dest_dir, manifest_file)
+        manifest_path = os.path.join(dest_dir, 'Manifest')
         f = open(manifest_path, "w")
         f.write(data)
         f.close()
@@ -216,12 +215,16 @@ def download_chunks(base_url, manifest, stream_index, quality_level, dest_dir):
 
         if os.path.exists(chunk_file) == False:
             chunk_url = base_url + '/' + chunks_quality + '/' + chunk_name
-            response = urllib2.urlopen(chunk_url)
-            data = response.read()
+            try:
+                response = urllib2.urlopen(chunk_url)
+                data = response.read()
+
+                f = open(chunk_file, "wb")
+                f.write(data)
+                f.close()
+            except Exception as e:
+                print e
 
-            f = open(chunk_file, "wb")
-            f.write(data)
-            f.close()
         else:
             f = open(chunk_file, "rb")
             data = f.read()