From 5f168ce00b527553b7b4bf862cc400bdc5f6ee91 Mon Sep 17 00:00:00 2001 From: Antti Ajanki Date: Sun, 7 Jun 2015 18:28:25 +0300 Subject: [PATCH] [downloader/f4m] Make retry time proportional to the fragment duration If the retry time is longer than the fragment duration, we risk missing fragments. --- youtube_dl/downloader/f4m.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/youtube_dl/downloader/f4m.py b/youtube_dl/downloader/f4m.py index b1a858c45..1ca2f2996 100644 --- a/youtube_dl/downloader/f4m.py +++ b/youtube_dl/downloader/f4m.py @@ -257,16 +257,26 @@ class F4mFD(FileDownloader): bootstrap = self.ydl.urlopen(bootstrap_url).read() return read_bootstrap_info(bootstrap) + def _retry_wait_time(self, boot_info): + fragments = boot_info[u'fragments'][0]['fragments'] + durations = [frag['duration'] for frag in fragments] + if durations: + min_duration_sec = min(durations)/1000.0 + return max(min(min_duration_sec/2, 5.0), 1.0) + else: + return 5.0 + def _update_live_fragments(self, bootstrap_url, latest_fragment): fragments_list = [] retries = 30 while (not fragments_list) and (retries > 0): boot_info = self._get_bootstrap_from_url(bootstrap_url) fragments_list = build_fragments_list(boot_info) + retry_wait = self._retry_wait_time(boot_info) fragments_list = [f for f in fragments_list if f[1] > latest_fragment] if not fragments_list: # Retry after a while - time.sleep(5.0) + time.sleep(retry_wait) retries -= 1 if not fragments_list: