Repository: yt-dlp
Issue: How to handle missing/incomplete fragments more elegantly
Labels: enhancement,core:downloader

### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I remove or skip any mandatory\* field

### Checklist

- [X] I'm asking a question and **not** reporting a bug or requesting a feature
- [X] I've looked through the [README](https://github.com/yt-dlp/yt-dlp#readme)
- [X] I've verified that I'm running yt-dlp version **2023.01.06** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar questions **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)

### Please make sure the question is worded well enough to be understood

First some observations regarding fragments:

- `--fragment-retries infinite` bangs its head against the same wall forever
- `--abort-on-unavailable-fragments` bails on the first sign of trouble
- `--keep-fragments` floods the directory with hundreds of fragments
- `--no-keep-fragments` iteratively merges fragments while downloading (but if a fragment is missing it will be left as a separate file, the merged video will lack this fragment, and video/audio/subtitles will be out of sync)

So, is there a way to tell yt-dlp:

1. If some fragments can't be downloaded, skip them
2. Focus on getting all the fragments that *are* available
3. Iteratively merge all sequential fragments that are complete
4. When finished, if some fragments are missing/incomplete, don't merge or delete anything
5. Let the user re-run the download at a later time to try to quickly get the (probably few) remaining fragments
6. Merge and delete once all fragments are available 

Pseudo:

```
foreach video in batch
  failures = 0
  foreach fragment in video
    if fragment missing or incomplete
      get fragment, try=10
    if fragment complete
      merge fragment with preceding complete fragments
    else
      print "fragment # missing. download will continue, but merging will be skipped."
      failures++
  if failures == 0
    merge video
    delete fragments
```

Example of a condensed way to keep/merge fragments:

```
.part-Frag001-020
.part-Frag021.part
.part-Frag022-049
.part-Frag050.part
.part-Frag051-099
```

PS! When running a standard `yt-dlp <video>` that *was* merged, but has at least one `.part-Frag###.part` (in which case video/audio/subtitles will be out of sync), is there currently any way to re-run the download to get the missing fragment and merge with the already merged video? (I assume no, and though possibly technically possible to implement, would be better handled pre-emptively as described above.)

### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
$ yt-dlp -vU
[debug] Command-line config: ['-vU']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2023.01.06 [6becd2508] (source)
[debug] Git HEAD: 88d8928
[debug] Python 3.10.9 (CPython x86_64 64bit) - macOS-12.6.2-x86_64-i386-64bit (OpenSSL 1.1.1s  1 Nov 2022)
[debug] exe versions: ffmpeg git-2022-06-01-c6364b71 (setts), ffprobe git-2022-06-01-c6364b71, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.15.0, certifi-2022.06.15, sqlite3-2.6.0, xattr-0.9.9
[debug] Proxy map: {}
[debug] Loaded 1735 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: 2023.01.06, Current version: 2023.01.06
yt-dlp is up to date (2023.01.06)
```