rtv icon indicating copy to clipboard operation
rtv copied to clipboard

add Twitch mime parser

Open geeseven opened this issue 5 years ago • 5 comments

Is your feature request related to a problem? Please describe. Twitch streams or clips act differently than other video links as they can only be opened in a browser.

Describe the solution you'd like It would be nice to launch mpv or vlc for Twitch streams or clips.

Describe alternatives you've considered Copy/paste is a workaround.

Additional context Seeing that youtube-dl has support for Twitch, I have a working branch that uses 'video/x-youtube' like Vimeo. I would be more than happy to make a pull request.

geeseven avatar May 25 '19 20:05 geeseven

I think it would be helpful to have examples of all the possible Twitch URLs.

goggle avatar May 27 '19 02:05 goggle

I am currently using the following regex:

https?://(clips\.|www\.|m\.)?twitch\.tv/[^.]+$

geeseven avatar May 27 '19 15:05 geeseven

Looking over the current Twitch extractor for youtube-dl, looks like we would also need to add the go and player subdomains.

geeseven avatar May 27 '19 22:05 geeseven

Given #696, it does not make sense to submit a pull request. For anyone interested, here is what I did:

$ git diff rtv/mime_parsers.py
diff --git a/rtv/mime_parsers.py b/rtv/mime_parsers.py
index 9d7eae8..3a51444 100644
--- a/rtv/mime_parsers.py
+++ b/rtv/mime_parsers.py
@@ -320,6 +320,17 @@ class StreamableMIMEParser(OpenGraphMIMEParser):
     """
     pattern = re.compile(r'https?://(www\.)?streamable\.com/[^.]+$')
 
+class TwitchMIMEParser(BaseMIMEParser):
+    """
+    Twitch videos can be streamed with vlc or downloaded with youtube-dl.
+    Assign a custom mime-type so they can be referenced in mailcap.
+    """
+    pattern = re.compile(r'https?://(clips|go|m|player|www)\.?twitch\.tv/[^.]+$')
+
+    @staticmethod
+    def get_mimetype(url):
+        return url, 'video/x-youtube'
+
 
 class LiveleakMIMEParser(BaseMIMEParser):
     """
@@ -479,6 +490,7 @@ parsers = [
     GiphyMIMEParser,
     ImgflipMIMEParser,
     LivememeMIMEParser,
+    TwitchMIMEParser,
     MakeamemeMIMEParser,
     WorldStarHipHopMIMEParser,
     GifvMIMEParser,

geeseven avatar Jun 07 '19 13:06 geeseven

Hi geeseven, I have a fork of rtv called tuir on Gitlab here and I would love to include your code here if you submit a pull request over there

ajakk avatar Jun 11 '19 17:06 ajakk