1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-30 04:08:01 +01:00

[downloader/f4m] Make retry time proportional to the fragment duration

If the retry time is longer than the fragment duration, we risk
missing fragments.
This commit is contained in:
Antti Ajanki 2015-06-07 18:28:25 +03:00
parent 68477c3dab
commit 5f168ce00b

View File

@ -257,16 +257,26 @@ class F4mFD(FileDownloader):
bootstrap = self.ydl.urlopen(bootstrap_url).read() bootstrap = self.ydl.urlopen(bootstrap_url).read()
return read_bootstrap_info(bootstrap) 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): def _update_live_fragments(self, bootstrap_url, latest_fragment):
fragments_list = [] fragments_list = []
retries = 30 retries = 30
while (not fragments_list) and (retries > 0): while (not fragments_list) and (retries > 0):
boot_info = self._get_bootstrap_from_url(bootstrap_url) boot_info = self._get_bootstrap_from_url(bootstrap_url)
fragments_list = build_fragments_list(boot_info) 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] fragments_list = [f for f in fragments_list if f[1] > latest_fragment]
if not fragments_list: if not fragments_list:
# Retry after a while # Retry after a while
time.sleep(5.0) time.sleep(retry_wait)
retries -= 1 retries -= 1
if not fragments_list: if not fragments_list: