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'https?://(?:www\.)?9gag(?:\.com/tv|\.tv)/p/(?P<id>[a-zA-Z0-9]+)(?:/(?P<display_id>[^?#/]+))?'
15 "url": "http://9gag.com/tv/p/Kk2X5/people-are-awesome-2013-is-absolutely-awesome",
19 "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!)",
20 "title": "\"People Are Awesome 2013\" Is Absolutely Awesome",
21 'uploader_id': 'UCdEH6EjDKwtTe-sO2f0_1XA',
22 'uploader': 'CompilationChannel',
23 'upload_date': '20131110',
25 "thumbnail": "re:^https?://",
29 'url': 'http://9gag.com/tv/p/KklwM',
30 'only_matching': True,
32 'url': 'http://9gag.tv/p/Kk2X5',
33 'only_matching': True,
35 _EXTERNAL_VIDEO_PROVIDER = {
41 'url': 'http://player.vimeo.com/video/%s',
45 'url': 'http://instagram.com/p/%s',
46 'ie_key': 'Instagram',
49 'url': 'http://vine.co/v/%s',
54 def _real_extract(self, url):
55 mobj = re.match(self._VALID_URL, url)
56 video_id = mobj.group('id')
57 display_id = mobj.group('display_id') or video_id
59 webpage = self._download_webpage(url, display_id)
61 post_view = json.loads(self._html_search_regex(
62 r'var\s+postView\s*=\s*new\s+app\.PostView\({\s*post:\s*({.+?})\s*,\s*posts:\s*prefetchedCurrentPost',
63 webpage, 'post view'))
66 source_url = post_view.get('sourceUrl')
68 external_video_id = post_view['videoExternalId']
69 external_video_provider = post_view['videoExternalProvider']
70 source_url = self._EXTERNAL_VIDEO_PROVIDER[external_video_provider]['url'] % external_video_id
71 ie_key = self._EXTERNAL_VIDEO_PROVIDER[external_video_provider]['ie_key']
72 title = post_view['title']
73 description = post_view.get('description')
74 view_count = str_to_int(post_view.get('externalView'))
75 thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
78 '_type': 'url_transparent',
82 'display_id': display_id,
84 'description': description,
85 'view_count': view_count,
86 'thumbnail': thumbnail,