]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ninegag.py
[youtube] Relax URL expansion in description
[yt-dlp.git] / youtube_dl / extractor / ninegag.py
CommitLineData
ed850070
JMF
1from __future__ import unicode_literals
2
7fc3fa05
PH
3import re
4
5from .common import InfoExtractor
d7666dff 6from ..utils import str_to_int
7fc3fa05
PH
7
8
9class NineGagIE(InfoExtractor):
10 IE_NAME = '9gag'
78f9fb90 11 _VALID_URL = r'https?://(?:www\.)?9gag(?:\.com/tv|\.tv)/(?:p|embed)/(?P<id>[a-zA-Z0-9]+)(?:/(?P<display_id>[^?#/]+))?'
7fc3fa05 12
4be9f8c8 13 _TESTS = [{
d8fef8fa
S
14 'url': 'http://9gag.com/tv/p/Kk2X5/people-are-awesome-2013-is-absolutely-awesome',
15 'info_dict': {
16 'id': 'Kk2X5',
17 'ext': 'mp4',
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',
e9404524
PH
20 'uploader_id': 'UCdEH6EjDKwtTe-sO2f0_1XA',
21 'uploader': 'CompilationChannel',
22 'upload_date': '20131110',
d8fef8fa 23 'view_count': int,
7fc3fa05 24 },
8ea6bd28
S
25 'add_ie': ['Youtube'],
26 }, {
27 'url': 'http://9gag.com/tv/p/aKolP3',
28 'info_dict': {
29 'id': 'aKolP3',
30 'ext': 'mp4',
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',
36 'view_count': int,
37 },
38 'add_ie': ['Vimeo'],
9e1a5b84 39 }, {
c3a4e2ec
S
40 'url': 'http://9gag.com/tv/p/KklwM',
41 'only_matching': True,
6400f8ec
S
42 }, {
43 'url': 'http://9gag.tv/p/Kk2X5',
44 'only_matching': True,
78f9fb90
S
45 }, {
46 'url': 'http://9gag.com/tv/embed/a5Dmvl',
47 'only_matching': True,
4be9f8c8 48 }]
78f9fb90 49
de3fc356 50 _EXTERNAL_VIDEO_PROVIDER = {
51 '1': {
52 'url': '%s',
53 'ie_key': 'Youtube',
54 },
55 '2': {
56 'url': 'http://player.vimeo.com/video/%s',
57 'ie_key': 'Vimeo',
58 },
59 '3': {
60 'url': 'http://instagram.com/p/%s',
61 'ie_key': 'Instagram',
62 },
63 '4': {
64 'url': 'http://vine.co/v/%s',
65 'ie_key': 'Vine',
66 },
67 }
7fc3fa05
PH
68
69 def _real_extract(self, url):
70 mobj = re.match(self._VALID_URL, url)
de3fc356 71 video_id = mobj.group('id')
e28c7946 72 display_id = mobj.group('display_id') or video_id
7fc3fa05 73
4be9f8c8 74 webpage = self._download_webpage(url, display_id)
7fc3fa05 75
c659022b
S
76 post_view = self._parse_json(
77 self._search_regex(
78 r'var\s+postView\s*=\s*new\s+app\.PostView\({\s*post:\s*({.+?})\s*,\s*posts:\s*prefetchedCurrentPost',
79 webpage, 'post view'),
80 display_id)
d7666dff 81
6b8ce312 82 ie_key = None
83 source_url = post_view.get('sourceUrl')
da9f1808 84 if not source_url:
6b8ce312 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']
d7666dff 89 title = post_view['title']
8ca2e93e
S
90 description = post_view.get('description')
91 view_count = str_to_int(post_view.get('externalView'))
d7666dff 92 thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
7fc3fa05
PH
93
94 return {
95 '_type': 'url_transparent',
6b8ce312 96 'url': source_url,
97 'ie_key': ie_key,
7fc3fa05 98 'id': video_id,
4be9f8c8
PH
99 'display_id': display_id,
100 'title': title,
84769e70
PH
101 'description': description,
102 'view_count': view_count,
d7666dff 103 'thumbnail': thumbnail,
7fc3fa05 104 }