lay295 / TwitchDownloader

Twitch VOD/Clip Downloader - Chat Download/Render/Replay
MIT License
2.68k stars 261 forks source link

Fix VOD download trimming and quality selection #936

Closed vaindil closed 9 months ago

vaindil commented 9 months ago

Fixes #935, see that for a more detailed discussion.

This also fixes a separate bug with stream quality selection when downloading VODs. Twitch's Usher endpoint to list stream qualities sometimes returns a 1080p60 stream quality with full framerate info, but sometimes that stream is returned as Source with no framerate info. Because there was no exact match for the stream name between the quality dropdown and the response when downloading, the logic would fall through to this: https://github.com/lay295/TwitchDownloader/blob/e48a04b2dd07c089cec63380c9814af17a4f36f4/TwitchDownloaderCore/Extensions/M3U8Extensions.cs#L77

However, in this case the framerate is 0 for the Source stream, which breaks this calculation. The other streams in the response do have framerate info when this happens, so the second-best quality would be chosen instead (720p60 in my case). This adds a manual override for these Source streams so they're always selected as the best quality.

vaindil commented 9 months ago

Here's a bit more detail on the second fix.

The usual response from Twitch for the playlist with video qualities in it looks like this:

image

The best-quality stream is named 1080p60, and there's framerate info at the tail end there. When this response is returned, everything is great.

Twitch sometimes returns this response, however:

image

Note that the name is different, and there's no framerate info.

ScrubN commented 9 months ago

Note that the name is different, and there's no framerate info.

Yeah, I ran into this myself at some point when writing M3U8Extensions. If possible, the framerate is assumed via the name when this happens: https://github.com/lay295/TwitchDownloader/blob/e48a04b2dd07c089cec63380c9814af17a4f36f4/TwitchDownloaderCore/Tools/M3U8.cs#L619-L628

Edit: I realize now that this code has the possibility to throw if twitch's M3U8 response changes in the future, but even if that was fixed I think M3U8Extensions.GetStreamofQuality would also throw...

ScrubN commented 9 months ago

Awesome, thank you for the fix!

Nutri626 commented 9 months ago

is update coming soon tho, its really hard to use it properly rn

ScrubN commented 9 months ago

I want to release an update tomorrow at the very latest (north america), but I want to give @lay295 time to decide if he wants to implement the temporary solution for #934 first.

In the meantime, you can download the workflow build from here: https://github.com/lay295/TwitchDownloader/actions/runs/7434637911

Alternatively, if you only crop on 10-second intervals, you will not experience the bad crop issue.