]>
Commit | Line | Data |
---|---|---|
ed850070 JMF |
1 | from __future__ import unicode_literals |
2 | ||
7fc3fa05 | 3 | import re |
d7666dff | 4 | import json |
7fc3fa05 PH |
5 | |
6 | from .common import InfoExtractor | |
d7666dff | 7 | from ..utils import str_to_int |
7fc3fa05 PH |
8 | |
9 | ||
10 | class NineGagIE(InfoExtractor): | |
11 | IE_NAME = '9gag' | |
4be9f8c8 PH |
12 | _VALID_URL = r'''(?x)^https?://(?:www\.)?9gag\.tv/ |
13 | (?: | |
14 | v/(?P<numid>[0-9]+)| | |
15 | p/(?P<id>[a-zA-Z0-9]+)/(?P<display_id>[^?#/]+) | |
16 | ) | |
17 | ''' | |
7fc3fa05 | 18 | |
4be9f8c8 | 19 | _TESTS = [{ |
ed850070 | 20 | "url": "http://9gag.tv/v/1912", |
ed850070 | 21 | "info_dict": { |
d2983ccb PH |
22 | "id": "1912", |
23 | "ext": "mp4", | |
ed850070 | 24 | "description": "This 3-minute video will make you smile and then make you feel untalented and insignificant. Anyway, you should share this awesomeness. (Thanks, Dino!)", |
84769e70 PH |
25 | "title": "\"People Are Awesome 2013\" Is Absolutely Awesome", |
26 | "view_count": int, | |
27 | "thumbnail": "re:^https?://", | |
7fc3fa05 | 28 | }, |
ed850070 | 29 | 'add_ie': ['Youtube'] |
4be9f8c8 PH |
30 | }, |
31 | { | |
32 | 'url': 'http://9gag.tv/p/KklwM/alternate-banned-opening-scene-of-gravity?ref=fsidebar', | |
33 | 'info_dict': { | |
34 | 'id': 'KklwM', | |
35 | 'ext': 'mp4', | |
36 | 'display_id': 'alternate-banned-opening-scene-of-gravity', | |
37 | "description": "While Gravity was a pretty awesome movie already, YouTuber Krishna Shenoi came up with a way to improve upon it, introducing a much better solution to Sandra Bullock's seemingly endless tumble in space. The ending is priceless.", | |
38 | 'title': "Banned Opening Scene Of \"Gravity\" That Changes The Whole Movie", | |
39 | }, | |
40 | }] | |
7fc3fa05 PH |
41 | |
42 | def _real_extract(self, url): | |
43 | mobj = re.match(self._VALID_URL, url) | |
4be9f8c8 PH |
44 | video_id = mobj.group('numid') or mobj.group('id') |
45 | display_id = mobj.group('display_id') or video_id | |
7fc3fa05 | 46 | |
4be9f8c8 | 47 | webpage = self._download_webpage(url, display_id) |
7fc3fa05 | 48 | |
d7666dff | 49 | post_view = json.loads(self._html_search_regex( |
1aac0379 | 50 | r'var postView = new app\.PostView\({\s*post:\s*({.+?}),\s*posts:\s*prefetchedCurrentPost', webpage, 'post view')) |
d7666dff S |
51 | |
52 | youtube_id = post_view['videoExternalId'] | |
53 | title = post_view['title'] | |
54 | description = post_view['description'] | |
55 | view_count = str_to_int(post_view['externalView']) | |
56 | thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w') | |
7fc3fa05 PH |
57 | |
58 | return { | |
59 | '_type': 'url_transparent', | |
84769e70 | 60 | 'url': youtube_id, |
7fc3fa05 PH |
61 | 'ie_key': 'Youtube', |
62 | 'id': video_id, | |
4be9f8c8 PH |
63 | 'display_id': display_id, |
64 | 'title': title, | |
84769e70 PH |
65 | 'description': description, |
66 | 'view_count': view_count, | |
d7666dff | 67 | 'thumbnail': thumbnail, |
7fc3fa05 | 68 | } |