diff options
author | dirkf <fieldhouse@gmx.net> | 2023-03-11 12:17:00 +0000 |
---|---|---|
committer | dirkf <fieldhouse@gmx.net> | 2023-03-14 16:23:20 +0000 |
commit | baa6c5e95cb307e7d716645780ff8aef22de6aca (patch) | |
tree | 419f4f2cd94ac6f2b3fa8fb60483b8bb933a658c /youtube_dl/downloader/common.py | |
parent | 5c985d4f81a43ada75dafb23233e7fe39913907a (diff) |
[FragmentFD] Respect `--no-continue`
* discard partial fragment on `--no-continue`
* continue with correct progress display otherwise
Resolves #21467
Diffstat (limited to 'youtube_dl/downloader/common.py')
-rw-r--r-- | youtube_dl/downloader/common.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 1cdba89cd..c86ce2aa5 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -88,17 +88,21 @@ class FileDownloader(object): return '---.-%' return '%6s' % ('%3.1f%%' % percent) - @staticmethod - def calc_eta(start, now, total, current): + @classmethod + def calc_eta(cls, start_or_rate, now_or_remaining, *args): + if len(args) < 2: + rate, remaining = (start_or_rate, now_or_remaining) + if None in (rate, remaining): + return None + return int(float(remaining) / rate) + start, now = (start_or_rate, now_or_remaining) + total, current = args if total is None: return None if now is None: now = time.time() - dif = now - start - if current == 0 or dif < 0.001: # One millisecond - return None - rate = float(current) / dif - return int((float(total) - float(current)) / rate) + rate = cls.calc_speed(start, now, current) + return rate and int((float(total) - float(current)) / rate) @staticmethod def format_eta(eta): @@ -124,6 +128,12 @@ class FileDownloader(object): return 'inf' if retries == float('inf') else '%.0f' % retries @staticmethod + def filesize_or_none(unencoded_filename): + fn = encodeFilename(unencoded_filename) + if os.path.isfile(fn): + return os.path.getsize(fn) + + @staticmethod def best_block_size(elapsed_time, bytes): new_min = max(bytes / 2.0, 1.0) new_max = min(max(bytes * 2.0, 1.0), 4194304) # Do not surpass 4 MB |