From d6a4cd05049e28ce7a7a30175c8effc016d9a74e Mon Sep 17 00:00:00 2001 From: woorst Date: Wed, 20 Jun 2018 23:20:14 -0400 Subject: [PATCH] Add mime parser: vimeo.com --- rtv/mime_parsers.py | 13 +++++++++++++ tests/test_mime_parsers.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/rtv/mime_parsers.py b/rtv/mime_parsers.py index 79583a5..acb1336 100644 --- a/rtv/mime_parsers.py +++ b/rtv/mime_parsers.py @@ -103,6 +103,18 @@ class YoutubeMIMEParser(BaseMIMEParser): return url, 'video/x-youtube' +class VimeoMIMEParser(BaseMIMEParser): + """ + Vimeo 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?://(www\.)?vimeo\.com/\d+$') + + @staticmethod + def get_mimetype(url): + return url, 'video/x-youtube' + + class GifvMIMEParser(BaseMIMEParser): """ Special case for .gifv, which is a custom video format for imgur serves @@ -502,6 +514,7 @@ parsers = [ RedditUploadsMIMEParser, RedditVideoMIMEParser, YoutubeMIMEParser, + VimeoMIMEParser, LiveleakMIMEParser, TwitchMIMEParser, FlickrMIMEParser, diff --git a/tests/test_mime_parsers.py b/tests/test_mime_parsers.py index d9f64a5..f431010 100644 --- a/tests/test_mime_parsers.py +++ b/tests/test_mime_parsers.py @@ -134,6 +134,10 @@ URLS = OrderedDict([ 'http://www.worldstarhiphop.com/videos/video.php?v=wshhJ6bVdAv0iMrNGFZG', 'http://www.youtube.com/embed/Bze53qwHS8o?autoplay=1', 'video/x-youtube')), + ('vimeo', ( + 'https://vimeo.com/247872788', + 'https://vimeo.com/247872788', + 'video/x-youtube')), ])