1 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..utils import str_to_int
10 class NineGagIE(InfoExtractor):
12 _VALID_URL = r'''(?x)^https?://(?:www\.)?9gag\.tv/
15 p/(?P<id>[a-zA-Z0-9]+)/(?P<display_id>[^?#/]+)
20 "url": "http://9gag.tv/v/1912",
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!)",
25 "title": "\"People Are Awesome 2013\" Is Absolutely Awesome",
26 'uploader_id': 'UCdEH6EjDKwtTe-sO2f0_1XA',
27 'uploader': 'CompilationChannel',
28 'upload_date': '20131110',
30 "thumbnail": "re:^https?://",
34 'url': 'http://9gag.tv/p/KklwM/alternate-banned-opening-scene-of-gravity?ref=fsidebar',
38 'display_id': 'alternate-banned-opening-scene-of-gravity',
39 "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.",
40 'title': "Banned Opening Scene Of \"Gravity\" That Changes The Whole Movie",
41 'uploader': 'Krishna Shenoi',
42 'upload_date': '20140401',
43 'uploader_id': 'krishnashenoi93',
47 def _real_extract(self, url):
48 mobj = re.match(self._VALID_URL, url)
49 video_id = mobj.group('numid') or mobj.group('id')
50 display_id = mobj.group('display_id') or video_id
52 webpage = self._download_webpage(url, display_id)
54 post_view = json.loads(self._html_search_regex(
55 r'var postView = new app\.PostView\({\s*post:\s*({.+?}),\s*posts:\s*prefetchedCurrentPost', webpage, 'post view'))
57 youtube_id = post_view['videoExternalId']
58 title = post_view['title']
59 description = post_view['description']
60 view_count = str_to_int(post_view['externalView'])
61 thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
64 '_type': 'url_transparent',
68 'display_id': display_id,
70 'description': description,
71 'view_count': view_count,
72 'thumbnail': thumbnail,