Repository: yt-dlp
Issue: Fix YouTube's autogenerated subtitles
Labels: enhancement,PR-needed,site:youtube,core:post-processor

### Checklist

- [X] I'm reporting a feature request
- [X] I've verified that I'm running yt-dlp version **2021.11.10.1**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [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

When you download automatic subtitles from YouTube, the resulting subtitle is a rolling subtitle - every time a new line is added, the previous one is moved up a line - if there's more than two lines, the first one disappears. Think Star Wars intro, but with only two lines:

A subtitle converted from VTT to SRT by yt-dlp would look something like this
```
00:00 --> 00:03 
This is the first line

00:03 --> 00:10 
This is the first line
This is what happens when another line is added

00:10
This is what happens when another line is added
If a third one is added, the first one disappears and the second one shoots up
```

The problem with this is that it's really hard to read, since you expect both lines to change, and it becomes really really (reeeally) distracting. I needed subtitles from my classes to be searchable and easily read while playing, so I made a little script to fix the VTT's and manually create a new SRT, but it becomes a boring step every time I need to download a new class to download, convert and embed. Is the community interested in something like this to automatically fix Youtube's autogenerated subtitles?

My ~sketchy~ fix is as follows

```python
def fix_youtube_vtt(vtt_file_path) -> str:
    """Fixes Youtube's autogenerated VTT subtitles and returns a srt-formatted string"""

    import webvtt

    pretty_subtitle = ''  
    previous_caption_text = ''
    i = 1
    for caption in webvtt.read(vtt_file_path):

        if previous_caption_text == caption.text.strip():
            # if previous and current lines are `identical`, print the start time from the previous
            # and the end time from the current.
            pretty_subtitle += f"{i}\n{previous_caption_start} --> {caption.end}\n{previous_caption_text}\n\n"
            i += 1

        elif previous_caption_text == caption.text.strip().split("\n")[0]: 
            # if the current caption is multiline, and the previous caption is equal to 
            # the current's first line, just ignore the first line and move on with the second.
            previous_caption_text = caption.text.strip().split("\n")[1]
            previous_caption_start = caption.start
            last_caption_end = caption.end

        else:	    
            previous_caption_text = caption.text.strip()
            previous_caption_start = caption.start.strip()

    return pretty_subtitle
```

The output becomes:

```
00:00 --> 00:03 
This is the first line

00:03 --> 00:10 
This is what happens when another line is added

00:10
If a third one is added, the first one disappears and the second one shoots up
```

In no way this is an ideal solution, I'm just showing what I've done to circumvent the issue, but a few flaws in my solution are that it only outputs a single line, and the timing is slightly off (maybe in the double digit milliseconds) due to the original multi line  captions.