diff --git a/rtv/mime_parsers.py b/rtv/mime_parsers.py index 95c0e91..a2d8e78 100644 --- a/rtv/mime_parsers.py +++ b/rtv/mime_parsers.py @@ -376,11 +376,15 @@ class LiveleakMIMEParser(BaseMIMEParser): 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 + iframe = soup.find_all(lambda t: t.name == 'iframe' and + 'youtube.com' in t['src']) + if iframe: + return YoutubeMIMEParser.get_mimetype(iframe[0]['src'].strip('/')) + else: + return url, None class ClippitUserMIMEParser(BaseMIMEParser): @@ -471,6 +475,8 @@ class WorldStarHipHopMIMEParser(BaseMIMEParser): 'youtube.com' in t['src']) if iframe: return YoutubeMIMEParser.get_mimetype(iframe[0]['src']) + else: + return url, None diff --git a/tests/cassettes/test_parser[liveleak_video].yaml b/tests/cassettes/test_parser[liveleak_video_1].yaml similarity index 100% rename from tests/cassettes/test_parser[liveleak_video].yaml rename to tests/cassettes/test_parser[liveleak_video_1].yaml diff --git a/tests/cassettes/test_parser[liveleak_video_2].yaml b/tests/cassettes/test_parser[liveleak_video_2].yaml new file mode 100644 index 0000000..e681203 --- /dev/null +++ b/tests/cassettes/test_parser[liveleak_video_2].yaml @@ -0,0 +1,341 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [python-requests/2.14.2] + method: GET + uri: https://www.liveleak.com/view?i=cad_1487311993 + response: + body: {string: "\r\n\r\n\r\n\tLiveLeak.com + - Trump Toys with Reporters at Press Conference Today \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
Trump + Toys with Reporters at Press Conference Today
\r\n
\r\n + \
\r\n
\"\" Part of channel(s): Presidency of Donald Trump (current + event)
\r\n

The MSM is circling + the drain and can't be done with fast enough!

\r\n\t\t
\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: + Feb-17-2017 Occurred On: Feb-17-2017 + \
By: TurnOffTelevision + \
In:
Politics + \
Tags: No, + More, Fake, News
Location: United States (load + item map)
Views: + 18845 | Comments: 292 | Votes: 25\r\n + | Favorites: 1 + | Shared: 38 | 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: ['Sun, 29 Oct 2017 13:56:26 GMT'] + Expires: ['Thu, 19 Nov 1981 08:52:00 GMT'] + Pragma: [no-cache] + Server: [nginx/1.6.1] + Set-Cookie: [PHPSESSID=c47884aaee715fa322e3e3952ac01ded; path=/; domain=.liveleak.com, + 'liveleak_safe_mode=1; expires=Mon, 29-Oct-2018 13:56:26 GMT; Max-Age=31536000; + path=/; domain=.liveleak.com; httponly', 'liveleak_use_old_player=1; expires=Mon, + 29-Oct-2018 13:56:26 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 883a3e7..d9f64a5 100644 --- a/tests/test_mime_parsers.py +++ b/tests/test_mime_parsers.py @@ -70,10 +70,14 @@ URLS = OrderedDict([ re.compile('https://(.*)\.cloudfront\.net/videos/15694926/52450725.mp4(.*)'), 'video/mp4', marks=pytest.mark.xfail(reason="vidme API appears to have changed format"))), - ('liveleak_video', ( + ('liveleak_video_1', ( 'https://www.liveleak.com/view?i=08b_1499296574', re.compile('https://cdn\.liveleak\.com/(.*)\.mp4(.*)'), 'video/mp4')), + ('liveleak_video_2', ( + 'https://www.liveleak.com/view?i=cad_1487311993', + re.compile('www\.youtube\.com/embed/D4GrlOMlOBY'), + 'video/x-youtube')), ('reddit_gif', ( 'https://v.redd.it/wkm9zol8c6fz', 'https://v.redd.it/wkm9zol8c6fz/DASH_600_K',