diff --git a/rtv/mime_parsers.py b/rtv/mime_parsers.py index 3475c4d..e782151 100644 --- a/rtv/mime_parsers.py +++ b/rtv/mime_parsers.py @@ -221,6 +221,36 @@ class VidmeMIMEParser(BaseMIMEParser): return url, None +class LiveleakMIMEParser(BaseMIMEParser): + """ + https://www.liveleak.com/view?i=12c_3456789 + + Sometimes only one video source is available + """ + pattern = re.compile(r'https?://((www|m)\.)?liveleak\.com/view\?i=\w+$') + + @staticmethod + def get_mimetype(url): + page = requests.get(url) + soup = BeautifulSoup(page.content, 'html.parser') + + urls = [] + videos = soup.find_all('video') + for vid in videos: + source = vid.find('source', attr={'res': 'HD'}) \ + or vid.find('source') + if source: + urls.append((source.get('src'), source.get('type'))) + # TODO: Handle pages with multiple videos + # TODO: Handle pages with youtube embeds + if urls: + return urls[0] + else: + return url, None + # Parsers should be listed in the order they will be checked parsers = [ StreamableMIMEParser, @@ -231,5 +261,6 @@ parsers = [ ImgurMIMEParser, RedditUploadsMIMEParser, YoutubeMIMEParser, + LiveleakMIMEParser, GifvMIMEParser, BaseMIMEParser] diff --git a/tests/cassettes/test_parser[liveleak_video].yaml b/tests/cassettes/test_parser[liveleak_video].yaml new file mode 100644 index 0000000..6f93910 --- /dev/null +++ b/tests/cassettes/test_parser[liveleak_video].yaml @@ -0,0 +1,381 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python-requests/2.17.3] + method: GET + uri: https://www.liveleak.com/view?i=08b_1499296574 + response: + body: {string: "\r\n\r\n\r\n\tLiveLeak.com + - German Tourists shoot a silenced .22\r\n \r\n \r\n \r\n \r\n + \ \r\n + \ \r\n\r\n\r\n\r\n + \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nSafe Mode: On\r\n
\r\n\t
\r\n\t\t\"\"/\r\n\r\n\t\t
\r\n\t\t\t

\r\n\t\t\t\t + \ Create Account | \r\n\t\t\t\tLog in | \r\n  \r\n \r\n \t\t\t

\r\n
\r\n\t\t\t\r\n\r\n\t\t\t
\r\n
\r\n\t\t\t\t\r\n\t\t\t\t\r\n
\r\n\t\t + \
\r\n
\r\n\r\n\t\t
\r\n\r\n\t\t\t\t\t\r\n\t
\r\n
\r\n
\r\n
\r\n\t
\r\n\t\t
+ \
\r\n \r\n
\r\n \r\n + \
\r\n
\r\n
German + Tourists shoot a silenced .22 
\r\n + \
\r\n
\r\n
\"\" Part of channel(s): Liveleakers (promoted)
\r\n

I met some German tourists passing through (father and + son) and I took them out shooting the next day. They had a good time. This + was his first shot with the silenced .22. It ended up being their favorite. + He is shooting at a bottle approximately 30 yards away.
\r\n
\r\nSilencer + makes a big difference ..... almost no noise at all.

\r\n\t\t\r\n\r\n
+ \
\r\n \r\n + \
\r\n \r\n
\r\n \r\n
\r\n + \
\r\n
\r\n\t\t\t\t\t
\r\n\t\t\t\t\t\r\n\t\t\t + \
\r\n
\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tAdded: + 4 days ago Occurred On: Jun-7-2017 + \
By: The + gambler
In:
Weapons, + Other Items from Liveleakers
Tags: Germany, USA, + Guns, silencer, + .22, fun, bottle
Location: Colorado, + United States (load + item map)
Marked as: featured
Views: 81322 | Comments: 333 | Votes: + 28\r\n + | Favorites: 3 + | Shared: 43 | Updates: 0 | Times + used in channels: 3 + \
\r\n \r\n
\r\n + \
\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t\r\n
\r\n\r\n
\r\n\r\n + \ \r\n + \ Direct link:


\r\n Direct + link without comments:
\r\n
\r\n
+ \r\n\t\t\t\t\t
\r\n\t\t\t\t
\r\n + \
\r\n \r\n
\r\n \r\n + \
\r\n \r\n
\r\n \r\n\r\n + \
You need to be registered in order to add comments! + Register HERE
\r\n + \ \r\n \r\n\r\n \r\n
\r\n + \ \r\n
\r\n + \
\r\n\t\r\n \r\n \r\n

\r\n\r\n Advertisement below\r\n
\r\n
\r\n\r\n\r\n
\r\n + \
\r\n \r\n\r\n \r\n\r\n \r\n\r\n\r\n + \ \r\n\r\n\r\n
Liveleak + on Facebook
\r\nLIKE Liveleak.com

\r\n
Items
\r\n
\r\n\t\t\t\t\t
\r\n\t\t\t\t\t\t
    \r\n + \ \t\t\t\t\t\t\t
  • Related
  • \r\n \t\t\t\t\t\t\t
  • User
  • \r\n \t\t\t\t\t\t
\r\n\t\t\t\t\t\t
\r\n\t\t\t
\r\n\t\t\t\t\t\t\t
\r\n\t\t\t\t\t\t\t\t + \r\n\t\t\t\t\t\t\t
\r\n\t\t\t\t\t\t
\r\n\t\t\t\t\t
\r\n\t\t\t\t
\r\n \t\t
\r\n
Advertisers
\r\n
\r\n\t\t\t
\r\n\t\t\t
\r\n\t\t\t
\r\n\t\t\t\t

\r\n Advertise on Liveleak
\r\n + \ Liveleak Forums
\r\n TomoNews - Animated News
\r\n + \

\r\n
\r\n
+ \r\n \t\t
\r\n\t
\r\n
\r\n
\r\n\t
\r\n\t\t\r\n\r\n\t\t\"Web\r\n\t\tBACK + TO TOP\r\n\r\n\t
\r\n
\r\n \r\n + \ \r\n\r\n + \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"} + headers: + Access-Control-Allow-Origin: ['*'] + Cache-Control: ['no-store, no-cache, must-revalidate, post-check=0, pre-check=0'] + Connection: [keep-alive] + Content-Type: [text/html; charset=UTF-8] + Date: ['Mon, 10 Jul 2017 22:04:43 GMT'] + Expires: ['Thu, 19 Nov 1981 08:52:00 GMT'] + Pragma: [no-cache] + Server: [nginx/1.10.2] + Set-Cookie: [PHPSESSID=7c66aca605ccae0c962f89812dd332bc; path=/; domain=.liveleak.com, + 'liveleak_safe_mode=1; expires=Tue, 10-Jul-2018 22:04:42 GMT; Max-Age=31536000; + path=/; domain=.liveleak.com; httponly', 'liveleak_use_old_player=1; expires=Tue, + 10-Jul-2018 22:04:42 GMT; Max-Age=31536000; path=/; domain=.liveleak.com; + httponly'] + X-Powered-By: [PHP/5.6.30] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/test_mime_parsers.py b/tests/test_mime_parsers.py index 403183e..a1ad3d4 100644 --- a/tests/test_mime_parsers.py +++ b/tests/test_mime_parsers.py @@ -69,6 +69,10 @@ URLS = OrderedDict([ 'https://vid.me/rHlb', re.compile('https://(.*)\.cloudfront\.net/videos/15694926/52450725.mp4(.*)'), 'video/mp4')), + ('liveleak_video', ( + 'https://www.liveleak.com/view?i=08b_1499296574', + re.compile('https://cdn.liveleak.com/80281E/ll_a_s/2017/Jul/5/LiveLeak-dot-com-08b_1499296574-NMHH8690_1499296571.mov.h264_720p.mp4(.*)'), + 'video/mp4')), ])