about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-09-03 23:00:52 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-09-04 17:32:29 +0800
commit919cf1a62f022c61cfa65498e8c1b1cc0d21046e (patch)
tree5a75ca48dba7445eb3ef7d90ac45b6bad4b77cb4
parentb29cd56591f1ef001d9f30bdff87789815f1fa0c (diff)
downloadyoutube-dl-919cf1a62f022c61cfa65498e8c1b1cc0d21046e.tar.gz
youtube-dl-919cf1a62f022c61cfa65498e8c1b1cc0d21046e.tar.xz
youtube-dl-919cf1a62f022c61cfa65498e8c1b1cc0d21046e.zip
[downloader/dash] Abort if the first segment fails
Closes #10497, Closes #10542
-rw-r--r--ChangeLog4
-rw-r--r--youtube_dl/downloader/dash.py20
2 files changed, 17 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 616b55803..1d277b562 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 version <unreleased>
 
+Core
+* If the first segment of DASH fails, abort the whole download process to
+  prevent throttling (#10497)
+
 Extractors
 * [pornvoisines] Fix extraction (#10469)
 * [rottentomatoes] Fix extraction (#10467)
diff --git a/youtube_dl/downloader/dash.py b/youtube_dl/downloader/dash.py
index efeae02a3..41fc9cfc2 100644
--- a/youtube_dl/downloader/dash.py
+++ b/youtube_dl/downloader/dash.py
@@ -40,7 +40,8 @@ class DashSegmentsFD(FragmentFD):
         fragment_retries = self.params.get('fragment_retries', 0)
         skip_unavailable_fragments = self.params.get('skip_unavailable_fragments', True)
 
-        def append_url_to_file(target_url, tmp_filename, segment_name):
+        def process_segment(segment, tmp_filename, fatal):
+            target_url, segment_name = segment
             target_filename = '%s-%s' % (tmp_filename, segment_name)
             count = 0
             while count <= fragment_retries:
@@ -64,18 +65,23 @@ class DashSegmentsFD(FragmentFD):
                     if count <= fragment_retries:
                         self.report_retry_fragment(err, segment_name, count, fragment_retries)
             if count > fragment_retries:
-                if skip_unavailable_fragments:
+                if not fatal:
                     self.report_skip_fragment(segment_name)
                     return True
                 self.report_error('giving up after %s fragment retries' % fragment_retries)
                 return False
             return True
 
-        if initialization_url:
-            if not append_url_to_file(initialization_url, ctx['tmpfilename'], 'Init'):
-                return False
-        for i, segment_url in enumerate(segment_urls):
-            if not append_url_to_file(segment_url, ctx['tmpfilename'], 'Seg%d' % i):
+        segments_to_download = [(initialization_url, 'Init')] if initialization_url else []
+        segments_to_download.extend([
+            (segment_url, 'Seg%d' % i)
+            for i, segment_url in enumerate(segment_urls)])
+
+        for i, segment in enumerate(segments_to_download):
+            # In DASH, the first segment contains necessary headers to
+            # generate a valid MP4 file, so always abort for the first segment
+            fatal = i == 0 or not skip_unavailable_fragments
+            if not process_segment(segment, ctx['tmpfilename'], fatal):
                 return False
 
         self._finish_frag_download(ctx)