Repository: streamlink/streamlink

Issue:
twitch clips still try to use the v2 api
<!--
Thanks for reporting a plugin issue!
USE THE TEMPLATE. Otherwise your plugin issue may be rejected.

First, see the contribution guidelines:
https://github.com/streamlink/streamlink/blob/master/CONTRIBUTING.md#contributing-to-streamlink

Also check the list of open and closed plugin issues:
https://github.com/streamlink/streamlink/issues?q=is%3Aissue+label%3A%22plugin+issue%22

Please see the text preview to avoid unnecessary formatting errors.
-->


## Plugin Issue

<!-- Replace [ ] with [x] in order to check the box -->
- [x] This is a plugin issue and I have read the contribution guidelines.


### Description

<!-- Explain the plugin issue as thoroughly as you can. -->
Downloading twitch clips does not work. It looks like this is something that was missed when you moved away from the v2 APIs - https://github.com/streamlink/streamlink/issues/1982 etc. - or just something I don't understand.

### Reproduction steps / Explicit stream URLs to test

$ streamlink -o test-clip https://www.twitch.tv/day9tv/clip/AmazonianEnchantingKangarooAsianGlow
[cli][info] Found matching plugin twitch for URL https://www.twitch.tv/day9tv/clip/AmazonianEnchantingKangarooAsianGlow
error: Unable to open URL: https://clips.twitch.tv/api/v2/clips/clip/status (404 Client Error: Not Found for url: https://clips.twitch.tv/api/v2/clips/clip/status?as3=t)


### Log output

<!--
TEXT LOG OUTPUT IS REQUIRED for a plugin issue!
Use the `--loglevel debug` parameter and avoid using parameters which suppress log output.
https://streamlink.github.io/cli.html#cmdoption-l

Make sure to **remove usernames and passwords**
You can copy the output to https://gist.github.com/ or paste it below.
-->

```
[cli][debug] OS:         Linux-5.0.16-100.fc28.x86_64-x86_64-with-fedora-28-Twenty_Eight
[cli][debug] Python:     3.6.8
[cli][debug] Streamlink: 1.1.1+34.g0a38762
[cli][debug] Requests(2.22.0), Socks(1.7.0), Websocket(0.56.0)
[cli][info] Found matching plugin twitch for URL https://www.twitch.tv/day9tv/clip/AmazonianEnchantingKangarooAsianGlow
error: Unable to open URL: https://clips.twitch.tv/api/v2/clips/clip/status (404 Client Error: Not Found for url: https://clips.twitch.tv/api/v2/clips/clip/status?as3=t)
```




Discussion:
I don't think the API for clips was ever public (I might be wrong) and we were using an internal API. It looks like there is a new GraphQL API that powers clips - so we'll have to update the twitch plugin to support that. 
Requesting the clip's mp4 file URLs has always been a private API call. This doesn't change with the switch to the GQL API. The only public APIs are the REST kraken/v5 and helix APIs, which (obviously) don't support that.

I'm just wondering, is it really necessary for Streamlink to support Twitch clips? Clips are just simple mp4 containers which can be downloaded via a simple HTTP request (in contrast to the HLS streams of their live streams and VODs). In terms of clips, this makes Streamlink and its Twitch plugin a simple URL resolver instead of being a stream URL resolver + HLS client. I might be wrong though, since there are a lot of other plugins which basically do the same, and it's probably also a justified use case.
I don’t have any problem with streamlink supporting clips, as long as someone wants to work on it :)
@bastimeyer I don't really care about Twitch clips and I'm not willing to ask people to spend time on it. Seems like it really just supports people downloading clips (presumably) to make clip compilations.
I originally stumbled across this when I tried to download a clip in order to manipulate it to elaborate on a joke, in a constructive way. But I admit I never thought about whether it enables people to do something undesirable.

As a simple streamlink user, I see it as a tool to reduce friction in dealing with online video - and downloading twitch clips effortlessly would be an extension of that.
@oliverhenshaw Sorry if my comment came off in an accusatory manner. It's more trying to determine if there is a use case for the work that makes it worth investing time in to and that was the only thing I could think of for use cases.
> Downloading twitch clips does not work.

`_url_re` is invalid for your URL in the **Twitch plugin**,
it does not match the clip name correctly.

> It looks like this is something that was missed when you moved away from the v2 APIs

No, it still works correctly.

Remove the `/clip/` in the url

` https://www.twitch.tv/day9tv/AmazonianEnchantingKangarooAsianGlow`



Resolving patch:
diff --git a/src/streamlink/plugins/twitch.py b/src/streamlink/plugins/twitch.py
--- a/src/streamlink/plugins/twitch.py
+++ b/src/streamlink/plugins/twitch.py
@@ -59,7 +59,7 @@
         (?P<video_id>\d+)
     )?
     (?:
-        /
+        /(?:clip/)?
         (?P<clip_name>[\w]+)
     )?
 """, re.VERBOSE)


Test patch: