1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..utils import str_to_int
9 class NineGagIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?9gag(?:\.com/tv|\.tv)/(?:p|embed)/(?P<id>[a-zA-Z0-9]+)(?:/(?P<display_id>[^?#/]+))?'
14 'url': 'http://9gag.com/tv/p/Kk2X5/people-are-awesome-2013-is-absolutely-awesome',
18 '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!)',
19 'title': '\"People Are Awesome 2013\" Is Absolutely Awesome',
20 'uploader_id': 'UCdEH6EjDKwtTe-sO2f0_1XA',
21 'uploader': 'CompilationChannel',
22 'upload_date': '20131110',
25 'add_ie': ['Youtube'],
27 'url': 'http://9gag.com/tv/p/aKolP3',
31 'title': 'This Guy Travelled 11 countries In 44 days Just To Make This Amazing Video',
32 'description': "I just saw more in 1 minute than I've seen in 1 year. This guy's video is epic!!",
33 'uploader_id': 'rickmereki',
34 'uploader': 'Rick Mereki',
35 'upload_date': '20110803',
40 'url': 'http://9gag.com/tv/p/KklwM',
41 'only_matching': True,
43 'url': 'http://9gag.tv/p/Kk2X5',
44 'only_matching': True,
46 'url': 'http://9gag.com/tv/embed/a5Dmvl',
47 'only_matching': True,
50 _EXTERNAL_VIDEO_PROVIDER = {
56 'url': 'http://player.vimeo.com/video/%s',
60 'url': 'http://instagram.com/p/%s',
61 'ie_key': 'Instagram',
64 'url': 'http://vine.co/v/%s',
69 def _real_extract(self, url):
70 mobj = re.match(self._VALID_URL, url)
71 video_id = mobj.group('id')
72 display_id = mobj.group('display_id') or video_id
74 webpage = self._download_webpage(url, display_id)
76 post_view = self._parse_json(
78 r'var\s+postView\s*=\s*new\s+app\.PostView\({\s*post:\s*({.+?})\s*,\s*posts:\s*prefetchedCurrentPost',
79 webpage, 'post view'),
83 source_url = post_view.get('sourceUrl')
85 external_video_id = post_view['videoExternalId']
86 external_video_provider = post_view['videoExternalProvider']
87 source_url = self._EXTERNAL_VIDEO_PROVIDER[external_video_provider]['url'] % external_video_id
88 ie_key = self._EXTERNAL_VIDEO_PROVIDER[external_video_provider]['ie_key']
89 title = post_view['title']
90 description = post_view.get('description')
91 view_count = str_to_int(post_view.get('externalView'))
92 thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
95 '_type': 'url_transparent',
99 'display_id': display_id,
101 'description': description,
102 'view_count': view_count,
103 'thumbnail': thumbnail,