-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
plugins.twitch: refactor plugin #3227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugins.twitch: refactor plugin #3227
Conversation
334fc1a
to
ccdbbfb
Compare
One minor comment regarding qualities, but in general the commits look good to me. |
ccdbbfb
to
07aeb0e
Compare
I'm not 100% happy with the changes, but overall, I think it should be much better now and the rest can be improve later on if really needed. As an improvement, all validation schemas should ideally be created lazily on the first access, because there are a lot of schemas now and most of them are not needed in most cases. I was also thinking about adding a new method to the validation module, I've also decided to remove the custom stream weights, as they should not be needed anymore. I haven't seen a channel with old quality names in ages. Codecov still seems to be dead. What a joke. The PR check requirement needs to be removed. I think it's best to also reduce the config to a minimum and let it always pass. This didn't turn out the way I thought it would, sorry about that. 😞 😠 Regarding the failed test run on py39, this is a bit surprising. I didn't touch the TwitchHLS logic here (also seen a failed test run yesterday IIRC) and it looks like a still remaining issue with the threads of the writer thread's ThreadPoolExecutor. Or could this be because of a change in 3.9?
|
07aeb0e
to
ac5f010
Compare
I've rebased the PR onto the new master HEAD with the latest HLS bugfixes. One thing to mention though: did Twitch remove rerun streams? They were labeled as "stream_type=playlist" on the API before, but most channels didn't use that feature and just set a "rerun" stream title and used the regular live stream format. That would make the https://dev.twitch.tv/docs/v5/reference/streams#get-live-streams
Everything else should be working fine: live
channel VOD
global VOD
channel clip
global clip
player live
player VOD
hosted channel
hosted channel - disabled
|
They definitely didn't remove them from the site, but after the discussion in #3206 it's possible that maybe they just dropped them from the API?
How about rebasing a few of them, then we can do a rebase and merge so the history is preserved without being too extensive for a single plugin? |
Yes, that was basically the idea. I'll clean this up a bit later. |
ac5f010
to
f79f24f
Compare
There's only one video type supported by Twitch, namely the old "v" one, which is implicit.
- refactor TwitchAPI class - extend TwitchAPI class with GQL API calls - replace API query methods with logical methods - move all validation schemas to TwitchAPI class - add validation schemas for channel ID API calls - remove requests.prepare_request availability check
- split up _get_hls_streams into live and video - re-implement hosted channel logic and add tests - refactor rerun check
- move URL regex - remove custom stream weights - reorder methods
f79f24f
to
3bb019f
Compare
Completely rebased it again because I decided to move the validation schemas to the TwitchAPI class and add methods for each type of API query instead of each endpoint, like I've mentioned above. This eleminates the need for lazy schema definitions and makes the overall plugin code more clean and easier to read. This also reduces the number of commits by one and the individual commits should be much better now (the API related one is a bit big though because it moves a lot of validation schema code). |
That works for me and this looks good. I'm going to rebase and merge. |
Opening this as a draft PR for now, because it's still WIP.
As already said in #3206, I wanted to refactor the entire Twitch plugin, as it hasn't been done in years and there's a ton of cruft.
I've split this up into multiple commits for reviewing reasons, but this should be squashed if it gets merged. Commits are therefore probably not 100% optimal and also don't have a proper commit message.
I can rebase this into fewer proper commits though, if you feel like it's too many changes for a single commit if squashed.
My goals with the code-refactor are the following:
There's only one type now
Removed in favor of "collections" in 2017, but doesn't matter, since Streamlink can output only a single stream anyway and videos in a collection have their own canonical URL.
Which year is it again?
_get_hls_streams
and_access_token
by stream type ("live" and "video")Simplifies logic and removes dead code paths
This is a private API call which can break at any time. It's currently being used on each live stream and doesn't have a try/except block. Also currently calls
_get_hls_streams
multiple times instead of just resolving the hosted channel chain in a loop.Now it also automatically updates the metadata on channel switch.
This PR moves it to its correct position within the plugin class.
Validation schemas should be added and redundancies removed.
Keep the new Twitch API in mind
At least for the stuff that doesn't require mocking every network request