Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

add Twitch mime parser #694

Open
geeseven opened this issue May 25, 2019 · 5 comments
Open

add Twitch mime parser #694

geeseven opened this issue May 25, 2019 · 5 comments

Comments

@geeseven
Copy link

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.

@goggle
Copy link

goggle commented May 27, 2019

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

@geeseven
Copy link
Author

geeseven commented May 27, 2019

I am currently using the following regex:

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

@geeseven
Copy link
Author

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

@geeseven
Copy link
Author

geeseven commented Jun 7, 2019

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,

@ajakk
Copy link

ajakk commented Jun 11, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants