Repository: yt-dlp/yt-dlp

Issue:
--no-continue is bugged and does nothing (--force-overwrites also)
### Checklist

- [X] I'm reporting a bug unrelated to a specific site
- [X] I've verified that I'm running yt-dlp version **2021.12.27**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#video-url-contains-an-ampersand-and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)

### Description

I originally posted this issue months ago in Discord but didn't create an issue for it. 
--no-continue doesn't seem to do anything right now.
--force-overwrites which is meant to include it doesn't either.

The only reason I want this to work is to workaround https://github.com/yt-dlp/yt-dlp/issues/2001 .

--force-overwrites log: https://pastebin.com/raw/PZ03eWb2

### Verbose log

```shell
[debug] Command-line config: ['-v', 'https://www.funimation.com/v/k-on/disband-the-club', '--config-location', 'funimation.conf', '--exec', 'start /B yt-dlp --config-location funimation.conf -q --fixup force --embed-subs --load-info-json %(__infojson_filename)q', '--write-subs', '--download-archive', 'archive.txt', '--ffmpeg-location', 'D:\\dummy', '--write-info-json', '-P', 'D:\\Temp']
[debug] | Config "funimation.conf": ['--config-location', 'base.conf', '-f', '(bv*+ba/b)[format_note=Uncut] / (bv*+ba/b)', '-n', '--cookies', 'cookies-funimation-com.txt', '--extractor-args', 'funimation:language=english', '--no-continue']
[debug] | | Config "base.conf": ['-o', '%(extractor)s\\%(title)s%(myindex)s.%(ext)s', '-P', 'D:\\Videos', '-P', 'temp:D:\\Temp', '--parse-metadata', 'original_url:#%(playlist_index)s', '--parse-metadata', ' - %(playlist_index)d:^(?P<myindex> - \\d+)$', '--parse-metadata', '%(series)s - S%(season_number)sE%(episode_number)s - %(episode)s:^(?P<title>.+ - S\\d+E\\d+ - \\S+.*)$', '--output-na', '', '--sub-langs', 'enUS,en', '--user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0', '--fragment-retries', '500', '-N', '5', '-R', '0', '--no-mtime']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, err utf-8, pref cp1252
[debug] yt-dlp version 2021.12.27 [6223f67a8] (win_exe)
[debug] Lazy loading extractors is disabled
[debug] Python version 3.10.1 (CPython 64bit) - Windows-10-10.0.19044-SP0
WARNING: ffmpeg-location D:\dummy does not exist! Continuing without ffmpeg.
[debug] exe versions: none
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] Loading archive file 'archive.txt'
[funimation:page] Logging in
[debug] [funimation:page] Extracting URL: https://www.funimation.com/v/k-on/disband-the-club
[funimation:page] k-on_disband-the-club: Downloading JSON metadata
[debug] [Funimation] Extracting URL: https://www.funimation.com/player/1135013
[Funimation] 1135013: Downloading player webpage for 1135013
[Funimation] disband-the-club: Downloading Uncut english (1135013) JSON
[Funimation] disband-the-club: Downloading Uncut english (1135013) m3u8 information
[debug] Sort order given by extractor: lang, source
[debug] Formats sorted by: hasvid, ie_pref, lang, source, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, id
[debug] Searching for '\\#(?P<playlist_index>.+)' in '%(original_url)s'
WARNING: Could not interpret 'original_url' as '#%(playlist_index)s'
[debug] Searching for '^(?P<myindex> - \\d+)$' in ' - %(playlist_index)d'
WARNING: Could not interpret ' - %(playlist_index)d' as '^(?P<myindex> - \\d+)$'
[debug] Searching for '^(?P<title>.+ - S\\d+E\\d+ - \\S+.*)$' in '%(series)s - S%(season_number)sE%(episode_number)s - %(episode)s'
[MetadataParser] Parsed title from '%(series)s - S%(season_number)sE%(episode_number)s - %(episode)s': 'K-On! - S1E1 - Disband the Club!'
[info] 1133115: Downloading 1 format(s): 1135013-hls-6819+1135013-hls-audio-aacl-256-English
[info] Writing video metadata as JSON to: D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.info.json
WARNING: ffmpeg-location D:\dummy does not exist! Continuing without ffmpeg.
WARNING: You have requested merging of multiple formats but ffmpeg is not installed. The formats won't be merged.
[debug] Invoking downloader on "https://vmfst-api.prd.funimationsvc.com/FunimationStoreFront/V1757083/26d6f23c-a90f-45c6-80e0-e2c01864b291strnv-hl154_streaming_video_1920_1080_7800000_index.m3u8?Key-Pair-Id=APKAIHNXECY27H4O6NIA&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9kMzNldDc3ZXZkOWJnZy5jbG91ZGZyb250Lm5ldC9GdW5pbWF0aW9uU3RvcmVGcm9udC9WMTc1NzA4My8qIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNjQxNDY1MzI2fX19XX0_&Signature=i5t~O2TJZ~8XNKwFb~3huANBs5rUvs2nq2OqNsOHecNz4NkJKDJdj2sGC0zCLFu9~Kmu05wsgY-5xNChkwJ3BEM42lqiNdf~F1CJm4vJikyAVXSq--SHUHNjKXq5BWaGVMwWDd~1YHtBWlyoplYO9HnInG6~mIMMhAMGcTBkOBv1el9r2JcpI4V5CMPvCOA2TaDwKr9HeVTmHnVOOfApAfKfRR60CRsVVXgFBNdT6NGP6myy9ITdZzYinqcnggNiO2mza6jtotnokX0tOnrefthhkLikAcpzUnDZg0YC4Uj2AfTAxK~A6yGPvTp2~iR6yGayibhqFIq~-XiZK48KMw__&rt=1450032"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 727
[download] Destination: D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4
WARNING: The download speed shown is only of one thread. This is a known issue and patches are welcome
[download] D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4.part-Frag17 has already been downloaded
[download] D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4.part-Frag18 has already been downloaded
[download]   2.2% of ~1.12GiB at 21.40MiB/s ETA Unknown (frag 16/727)[download] D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4.part-Frag19 has already been downloaded
[download]   2.3% of ~1.12GiB at 781.98MiB/s ETA Unknown (frag 17/727)[download] D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4.part-Frag20 has already been downloaded
[download] D:\Temp\Funimation\K-On! - S1E1 - Disband the Club!.f1135013-hls-6819.mp4.part-Frag21 has already been downloaded
[download]   0.3% of ~39.60GiB at 11.05MiB/s ETA 56:42 (frag 20/727)
```



Discussion:
Seems to be with HLS fragments. Can reproduce with videos from YouTube. `--no-continue` (and `--force-overwrites`?) don't work with DASH fragments either. 

DASH:
```
$ yt-dlp  https://www.youtube.com/watch\?v\=hSJQIYAYEYU -f 248 -v --newline                                 
[debug] Command-line config: ['https://www.youtube.com/watch?v=hSJQIYAYEYU', '-f', '248', '-v', '--newline']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2021.12.27 [6223f67a8]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.9.9 (CPython 64bit) - Linux-5.15.6-2-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4.1 (setts), ffprobe 4.4.1, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=hSJQIYAYEYU
[youtube] hSJQIYAYEYU: Downloading webpage
[youtube] hSJQIYAYEYU: Downloading android player API JSON
[youtube] hSJQIYAYEYU: Downloading MPD manifest
[youtube] hSJQIYAYEYU: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[info] hSJQIYAYEYU: Downloading 1 format(s): 248
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/REDACTED"
[dashsegments] Total fragments: 111
[download] Destination: The Science Of Fireworks [hSJQIYAYEYU].webm
[download]   0.9% of ~88.56KiB at  1.56KiB/s ETA 00:56
[download]   0.9% of ~88.56KiB at  1.56KiB/s ETA 00:56 (frag 1/111)
[download]   0.0% of ~73.40MiB at  1.85KiB/s ETA 12:12:14 (frag 1/111)
[download]   0.0% of ~73.40MiB at  5.55KiB/s ETA 05:46:42 (frag 1/111)
[download]   0.0% of ~73.40MiB at 12.95KiB/s ETA 02:48:54 (frag 1/111)
[...]
[download]   4.4% of ~118.71MiB at  7.90MiB/s ETA 00:33 (frag 4/111)
[download]   4.5% of ~118.71MiB at  9.12MiB/s ETA 00:32 (frag 4/111)
[download]   4.5% of ~118.71MiB at  9.10MiB/s ETA 00:32 (frag 5/111)
^C
ERROR: Interrupted by user
$ yt-dlp  https://www.youtube.com/watch\?v\=hSJQIYAYEYU -f 248 -v --newline --force-overwrites --no-continue
[debug] Command-line config: ['https://www.youtube.com/watch?v=hSJQIYAYEYU', '-f', '248', '-v', '--newline', '--force-overwrites', '--no-continue']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2021.12.27 [6223f67a8]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.9.9 (CPython 64bit) - Linux-5.15.6-2-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4.1 (setts), ffprobe 4.4.1, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=hSJQIYAYEYU
[youtube] hSJQIYAYEYU: Downloading webpage
[youtube] hSJQIYAYEYU: Downloading android player API JSON
[youtube] hSJQIYAYEYU: Downloading MPD manifest
[youtube] hSJQIYAYEYU: Downloading MPD manifest
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[info] hSJQIYAYEYU: Downloading 1 format(s): 248
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/dash/expire/REDACTED"
[dashsegments] Total fragments: 111
[download] Destination: The Science Of Fireworks [hSJQIYAYEYU].webm
[download]   4.4% of ~121.36MiB at  1.61KiB/s ETA 20:32:39 (frag 5/111)
[download]   4.4% of ~121.36MiB at  4.82KiB/s ETA 06:51:02 (frag 5/111)
[download]   4.4% of ~121.36MiB at 11.23KiB/s ETA 02:56:13 (frag 5/111)
[download]   4.4% of ~121.36MiB at 24.06KiB/s ETA 01:22:16 (frag 5/111)
[download]   4.4% of ~121.36MiB at 49.50KiB/s ETA 39:59 (frag 5/111)
[download]   4.5% of ~121.36MiB at 99.52KiB/s ETA 19:53 (frag 5/111)
[download]   4.5% of ~121.36MiB at 199.60KiB/s ETA 09:54 (frag 5/111)
[...]
[download]   5.4% of ~126.52MiB at 322.47KiB/s ETA 02:02 (frag 6/111)
[download]   5.6% of ~126.52MiB at 632.56KiB/s ETA 01:45 (frag 6/111)
[download]   6.0% of ~126.52MiB at  1.19MiB/s ETA 01:22 (frag 6/111)
[download]   6.3% of ~126.52MiB at  1.63MiB/s ETA 01:10 (frag 6/111)
[download]   6.3% of ~126.52MiB at  1.63MiB/s ETA 01:10 (frag 7/111)
```

HLS:
```
$ yt-dlp  https://www.youtube.com/watch\?v\=hSJQIYAYEYU -v --newline --extractor-args youtube:player-client=ios -f 270 --force-overwrites --no-continue
[debug] Command-line config: ['https://www.youtube.com/watch?v=hSJQIYAYEYU', '-v', '--newline', '--extractor-args', 'youtube:player-client=ios', '-f', '270', '--force-overwrites', '--no-continue']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2021.12.27 [6223f67a8]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.9.9 (CPython 64bit) - Linux-5.15.6-2-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4.1 (setts), ffprobe 4.4.1, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=hSJQIYAYEYU
[youtube] hSJQIYAYEYU: Downloading webpage
[youtube] hSJQIYAYEYU: Downloading ios player API JSON
[youtube] hSJQIYAYEYU: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[info] hSJQIYAYEYU: Downloading 1 format(s): 270
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/hls_playlist/REDACTED"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 110
[download] Destination: The Science Of Fireworks [hSJQIYAYEYU].mp4
[download] Unknown % of ~0.00B at 13.56KiB/s ETA 00:00
[download] Unknown % of ~0.00B at 40.53KiB/s ETA 00:00
[download] Unknown % of ~0.00B at 67.41KiB/s ETA 00:00
[download] Unknown % of ~0.00B at 144.10KiB/s ETA 00:00
[download] Unknown % of ~0.00B at 296.83KiB/s ETA 00:00
[download] Unknown % of ~0.00B at 583.55KiB/s ETA 00:00
[download] Unknown % of ~0.00B at  1.11MiB/s ETA 00:00
[download] Unknown % of ~0.00B at  2.15MiB/s ETA 00:00
[download] Unknown % of ~0.00B at  4.16MiB/s ETA 00:00
[download] Unknown % of ~0.00B at  7.94MiB/s ETA 00:00
[download] Unknown % of ~0.00B at 14.61MiB/s ETA 00:00
[download]   0.9% of ~217.77MiB at 14.57MiB/s ETA 00:00 (frag 1/110)
[download]   1.8% of ~108.89MiB at  7.71KiB/s ETA 00:14 (frag 1/110)
[download]   1.8% of ~108.89MiB at 23.10KiB/s ETA 00:14 (frag 1/110)
[...]
[download]   3.7% of ~203.17MiB at 797.96KiB/s ETA 00:15 (frag 3/110)
[download]   3.7% of ~203.17MiB at  1.53MiB/s ETA 00:15 (frag 3/110)
[download]   3.8% of ~203.17MiB at  2.95MiB/s ETA 00:15 (frag 3/110)
[download]   3.9% of ~203.17MiB at  5.63MiB/s ETA 00:15 (frag 3/110)
^C
ERROR: Interrupted by user

$ yt-dlp  https://www.youtube.com/watch\?v\=hSJQIYAYEYU -v --newline --extractor-args youtube:player-client=ios -f 270 --force-overwrites --no-continue
[debug] Command-line config: ['https://www.youtube.com/watch?v=hSJQIYAYEYU', '-v', '--newline', '--extractor-args', 'youtube:player-client=ios', '-f', '270', '--force-overwrites', '--no-continue']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2021.12.27 [6223f67a8]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.9.9 (CPython 64bit) - Linux-5.15.6-2-MANJARO-x86_64-with-glibc2.33
[debug] exe versions: ffmpeg 4.4.1 (setts), ffprobe 4.4.1, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: https://www.youtube.com/watch?v=hSJQIYAYEYU
[youtube] hSJQIYAYEYU: Downloading webpage
[youtube] hSJQIYAYEYU: Downloading ios player API JSON
[youtube] hSJQIYAYEYU: Downloading m3u8 information
[debug] Sort order given by extractor: quality, res, fps, hdr:12, source, codec:vp9.2, lang, proto
[debug] Formats sorted by: hasvid, ie_pref, quality, res, fps, hdr:12(7), source, vcodec:vp9.2(10), acodec, lang, proto, filesize, fs_approx, tbr, vbr, abr, asr, vext, aext, hasaud, id
[info] hSJQIYAYEYU: Downloading 1 format(s): 270
[debug] Invoking downloader on "https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/REDACTED"
[hlsnative] Downloading m3u8 manifest
[hlsnative] Total fragments: 110
[download] Destination: The Science Of Fireworks [hSJQIYAYEYU].mp4
[download]   3.6% of ~203.17MiB at 13.88KiB/s ETA 04:00:40 (frag 3/110)
[download]   3.6% of ~203.17MiB at 41.50KiB/s ETA 01:20:30 (frag 3/110)
[download]   3.6% of ~203.17MiB at 96.51KiB/s ETA 34:37 (frag 3/110)
[download]   3.6% of ~203.17MiB at 206.10KiB/s ETA 16:12 (frag 3/110)
[download]   3.7% of ~203.17MiB at 412.42KiB/s ETA 08:06 (frag 3/110)
[download]   3.7% of ~203.17MiB at 818.23KiB/s ETA 04:04 (frag 3/110)
[download]   3.7% of ~203.17MiB at  1.53MiB/s ETA 02:07 (frag 3/110)
[...]
[download]   6.5% of ~194.73MiB at 11.23MiB/s ETA 00:24 (frag 5/110)
[download]   6.8% of ~194.73MiB at  9.17MiB/s ETA 00:25 (frag 5/110)
[download]   5.5% of ~244.28MiB at  9.16MiB/s ETA 00:25 (frag 6/110)
^C
ERROR: Interrupted by user
```



Continue of https://github.com/yt-dlp/yt-dlp/issues/2001#issuecomment-1052119472

Untested because I'm tired now but [fragments.py is mispelling the key for `--no-continue`, it should be `continue_dl`](https://github.com/yt-dlp/yt-dlp/blob/195c22840c594c8f9229cb47ffec2a8984c53a0c/yt_dlp/downloader/http.py#L62)
Maybe it fixes
> Continue of [#2001 (comment)](https://github.com/yt-dlp/yt-dlp/issues/2001#issuecomment-1052119472)
> 
> Untested because I'm tired now but [fragments.py is mispelling the key for `--no-continue`, it should be `continue_dl`](https://github.com/yt-dlp/yt-dlp/blob/195c22840c594c8f9229cb47ffec2a8984c53a0c/yt_dlp/downloader/http.py#L62) Maybe it fixes

Hmm... Nope, I renamed all instances of the param to continuedl but it's still returning true.
yeah I was wrong

`--no-continue` isn't passed to HttpQuietDownloader https://github.com/yt-dlp/yt-dlp/blob/195c22840c594c8f9229cb47ffec2a8984c53a0c/yt_dlp/downloader/fragment.py#L181
Yeah I just noticed that 10mins ago lol.

Resolving patch:
diff --git a/yt_dlp/downloader/fragment.py b/yt_dlp/downloader/fragment.py
--- a/yt_dlp/downloader/fragment.py
+++ b/yt_dlp/downloader/fragment.py
@@ -178,7 +178,7 @@ def _prepare_frag_download(self, ctx):
         dl = HttpQuietDownloader(
             self.ydl,
             {
-                'continuedl': True,
+                'continuedl': self.params.get('continuedl', True),
                 'quiet': self.params.get('quiet'),
                 'noprogress': True,
                 'ratelimit': self.params.get('ratelimit'),
diff --git a/yt_dlp/downloader/http.py b/yt_dlp/downloader/http.py
--- a/yt_dlp/downloader/http.py
+++ b/yt_dlp/downloader/http.py
@@ -5,7 +5,6 @@
 import socket
 import time
 import random
-import re
 
 from .common import FileDownloader
 from ..compat import (
@@ -16,6 +15,7 @@
     ContentTooShortError,
     encodeFilename,
     int_or_none,
+    parse_http_range,
     sanitized_Request,
     ThrottledDownload,
     write_xattr,
@@ -59,6 +59,9 @@ class DownloadContext(dict):
         ctx.chunk_size = None
         throttle_start = None
 
+        # parse given Range
+        req_start, req_end, _ = parse_http_range(headers.get('Range'))
+
         if self.params.get('continuedl', True):
             # Establish possible resume length
             if os.path.isfile(encodeFilename(ctx.tmpfilename)):
@@ -91,6 +94,9 @@ def establish_connection():
                               if not is_test and chunk_size else chunk_size)
             if ctx.resume_len > 0:
                 range_start = ctx.resume_len
+                if req_start is not None:
+                    # offset the beginning of Range to be within request
+                    range_start += req_start
                 if ctx.is_resume:
                     self.report_resuming_byte(ctx.resume_len)
                 ctx.open_mode = 'ab'
@@ -99,7 +105,17 @@ def establish_connection():
             else:
                 range_start = None
             ctx.is_resume = False
-            range_end = range_start + ctx.chunk_size - 1 if ctx.chunk_size else None
+
+            if ctx.chunk_size:
+                chunk_aware_end = range_start + ctx.chunk_size - 1
+                # we're not allowed to download outside Range
+                range_end = chunk_aware_end if req_end is None else min(chunk_aware_end, req_end)
+            elif req_end is not None:
+                # there's no need for chunked downloads, so download until the end of Range
+                range_end = req_end
+            else:
+                range_end = None
+
             if range_end and ctx.data_len is not None and range_end >= ctx.data_len:
                 range_end = ctx.data_len - 1
             has_range = range_start is not None
@@ -124,23 +140,19 @@ def establish_connection():
                 # https://github.com/ytdl-org/youtube-dl/issues/6057#issuecomment-126129799)
                 if has_range:
                     content_range = ctx.data.headers.get('Content-Range')
-                    if content_range:
-                        content_range_m = re.search(r'bytes (\d+)-(\d+)?(?:/(\d+))?', content_range)
+                    content_range_start, content_range_end, content_len = parse_http_range(content_range)
+                    if content_range_start is not None and range_start == content_range_start:
                         # Content-Range is present and matches requested Range, resume is possible
-                        if content_range_m:
-                            if range_start == int(content_range_m.group(1)):
-                                content_range_end = int_or_none(content_range_m.group(2))
-                                content_len = int_or_none(content_range_m.group(3))
-                                accept_content_len = (
-                                    # Non-chunked download
-                                    not ctx.chunk_size
-                                    # Chunked download and requested piece or
-                                    # its part is promised to be served
-                                    or content_range_end == range_end
-                                    or content_len < range_end)
-                                if accept_content_len:
-                                    ctx.data_len = content_len
-                                    return
+                        accept_content_len = (
+                            # Non-chunked download
+                            not ctx.chunk_size
+                            # Chunked download and requested piece or
+                            # its part is promised to be served
+                            or content_range_end == range_end
+                            or content_len < range_end)
+                        if accept_content_len:
+                            ctx.data_len = content_len
+                            return
                     # Content-Range is either not present or invalid. Assuming remote webserver is
                     # trying to send the whole file, resume is not possible, so wiping the local file
                     # and performing entire redownload
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -5252,6 +5252,16 @@ def join_nonempty(*values, delim='-', from_dict=None):
     return delim.join(map(str, filter(None, values)))
 
 
+def parse_http_range(range):
+    """ Parse value of "Range" or "Content-Range" HTTP header into tuple. """
+    if not range:
+        return None, None, None
+    crg = re.search(r'bytes[ =](\d+)-(\d+)?(?:/(\d+))?', range)
+    if not crg:
+        return None, None, None
+    return int(crg.group(1)), int_or_none(crg.group(2)), int_or_none(crg.group(3))
+
+
 class Config:
     own_args = None
     filename = None


Test patch: