2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_unquote
,
21 class KinjaEmbedIE(InfoExtractor
):
22 IENAME
= 'kinja:embed'
23 _DOMAIN_REGEX
= r
'''(?:[^.]+\.)?
35 the(?:inventory|onion|root|takeout)
42 _VALID_URL
= r
'''(?x)https?://%s%s
52 soundcloud(?:-playlist)?|
59 youtube-(?:list|video)
60 )-(?P<id>[^&]+)''' % (_DOMAIN_REGEX
, _COMMON_REGEX
)
62 'url': 'https://kinja.com/ajax/inset/iframe?id=fb-10103303356633621',
63 'only_matching': True,
65 'url': 'https://kinja.com/ajax/inset/iframe?id=kinjavideo-100313',
66 'only_matching': True,
68 'url': 'https://kinja.com/ajax/inset/iframe?id=megaphone-PPY1300931075',
69 'only_matching': True,
71 'url': 'https://kinja.com/ajax/inset/iframe?id=ooyala-xzMXhleDpopuT0u1ijt_qZj3Va-34pEX%2FZTIxYmJjZDM2NWYzZDViZGRiOWJjYzc5',
72 'only_matching': True,
74 'url': 'https://kinja.com/ajax/inset/iframe?id=soundcloud-128574047',
75 'only_matching': True,
77 'url': 'https://kinja.com/ajax/inset/iframe?id=soundcloud-playlist-317413750',
78 'only_matching': True,
80 'url': 'https://kinja.com/ajax/inset/iframe?id=tumblr-post-160130699814-daydreams-at-midnight',
81 'only_matching': True,
83 'url': 'https://kinja.com/ajax/inset/iframe?id=twitch-stream-libratus_extra',
84 'only_matching': True,
86 'url': 'https://kinja.com/ajax/inset/iframe?id=twitter-1068875942473404422',
87 'only_matching': True,
89 'url': 'https://kinja.com/ajax/inset/iframe?id=ustream-channel-10414700',
90 'only_matching': True,
92 'url': 'https://kinja.com/ajax/inset/iframe?id=vimeo-120153502',
93 'only_matching': True,
95 'url': 'https://kinja.com/ajax/inset/iframe?id=vine-5BlvV5qqPrD',
96 'only_matching': True,
98 'url': 'https://kinja.com/ajax/inset/iframe?id=youtube-list-BCQ3KyrPjgA/PLE6509247C270A72E',
99 'only_matching': True,
101 'url': 'https://kinja.com/ajax/inset/iframe?id=youtube-video-00QyL0AgPAE',
102 'only_matching': True,
104 _JWPLATFORM_PROVIDER
= ('cdn.jwplayer.com/v2/media/', 'JWPlatform')
106 'fb': ('facebook.com/video.php?v=', 'Facebook'),
107 'imgur': ('imgur.com/', 'Imgur'),
108 'instagram': ('instagram.com/p/', 'Instagram'),
109 'jwplayer-video': _JWPLATFORM_PROVIDER
,
110 'jwp-video': _JWPLATFORM_PROVIDER
,
111 'megaphone': ('player.megaphone.fm/', 'Generic'),
112 'ooyala': ('player.ooyala.com/player.js?embedCode=', 'Ooyala'),
113 'soundcloud': ('api.soundcloud.com/tracks/', 'Soundcloud'),
114 'soundcloud-playlist': ('api.soundcloud.com/playlists/', 'SoundcloudPlaylist'),
115 'tumblr-post': ('%s.tumblr.com/post/%s', 'Tumblr'),
116 'twitch-stream': ('twitch.tv/', 'TwitchStream'),
117 'twitter': ('twitter.com/i/cards/tfw/v1/', 'TwitterCard'),
118 'ustream-channel': ('ustream.tv/embed/', 'Ustream'),
119 'vimeo': ('vimeo.com/', 'Vimeo'),
120 'vine': ('vine.co/v/', 'Vine'),
121 'youtube-list': ('youtube.com/embed/%s?list=%s', 'YoutubePlaylist'),
122 'youtube-video': ('youtube.com/embed/', 'Youtube'),
126 def _extract_urls(webpage
, url
):
127 return [urljoin(url
, unescapeHTML(mobj
.group('url'))) for mobj
in re
.finditer(
128 r
'(?x)<iframe[^>]+?src=(?P<q>["\'])(?P
<url
>(?
:(?
:https?
:)?
//%s)?
%s(?
:(?
!\
1).)+)\
1' % (KinjaEmbedIE._DOMAIN_REGEX, KinjaEmbedIE._COMMON_REGEX),
131 def _real_extract(self, url):
132 video_type, video_id = re.match(self._VALID_URL, url).groups()
134 provider = self._PROVIDER_MAP.get(video_type)
136 video_id = compat_urllib_parse_unquote(video_id)
137 if video_type == 'tumblr
-post
':
138 video_id, blog = video_id.split('-', 1)
139 result_url = provider[0] % (blog, video_id)
140 elif video_type == 'youtube
-list':
141 video_id, playlist_id = video_id.split('/')
142 result_url = provider[0] % (video_id, playlist_id)
144 if video_type == 'ooyala
':
145 video_id = video_id.split('/')[0]
146 result_url = provider[0] + video_id
147 return self.url_result('http
://' + result_url, provider[1])
149 if video_type == 'kinjavideo
':
150 data = self._download_json(
151 'https
://kinja
.com
/api
/core
/video
/views
/videoById
',
152 video_id, query={'videoId
': video_id})['data
']
153 title = data['title
']
156 for k in ('signedPlaylist
', 'streaming
'):
157 m3u8_url = data.get(k + 'Url
')
159 formats.extend(self._extract_m3u8_formats(
160 m3u8_url, video_id, 'mp4
', 'm3u8_native
',
161 m3u8_id='hls
', fatal=False))
162 self._sort_formats(formats)
165 poster = data.get('poster
') or {}
166 poster_id = poster.get('id')
168 thumbnail = 'https
://i
.kinja
-img
.com
/gawker
-media
/image
/upload
/%s.%s' % (poster_id, poster.get('format
') or 'jpg
')
173 'description
': strip_or_none(data.get('description
')),
175 'tags
': data.get('tags
'),
176 'timestamp
': int_or_none(try_get(
177 data, lambda x: x['postInfo
']['publishTimeMillis
']), 1000),
178 'thumbnail
': thumbnail,
179 'uploader
': data.get('network
'),
182 video_data = self._download_json(
183 'https
://api
.vmh
.univision
.com
/metadata
/v1
/content
/' + video_id,
184 video_id)['videoMetadata
']
185 iptc = video_data['photoVideoMetadataIPTC
']
186 title = iptc['title
']['en
']
187 fmg = video_data.get('photoVideoMetadata_fmg
') or {}
188 tvss_domain = fmg.get('tvssDomain
') or 'https
://auth
.univision
.com
'
189 data = self._download_json(
190 tvss_domain + '/api
/v3
/video
-auth
/url
-signature
-tokens
',
191 video_id, query={'mcpids
': video_id})['data
'][0]
194 rendition_url = data.get('renditionUrl
')
196 formats = self._extract_m3u8_formats(
197 rendition_url, video_id, 'mp4
',
198 'm3u8_native
', m3u8_id='hls
', fatal=False)
200 fallback_rendition_url = data.get('fallbackRenditionUrl
')
201 if fallback_rendition_url:
203 'format_id
': 'fallback
',
204 'tbr
': int_or_none(self._search_regex(
205 r'_(\d
+)\
.mp4
', fallback_rendition_url,
206 'bitrate
', default=None)),
207 'url
': fallback_rendition_url,
210 self._sort_formats(formats)
215 'thumbnail
': try_get(iptc, lambda x: x['cloudinaryLink
']['link
'], compat_str),
216 'uploader
': fmg.get('network
'),
217 'duration
': int_or_none(iptc.get('fileDuration
')),
219 'description
': try_get(iptc, lambda x: x['description
']['en
'], compat_str),
220 'timestamp
': parse_iso8601(iptc.get('dateReleased
')),