[digg] Improve extraction

This commit is contained in:
Sergey M․ 2018-01-10 22:19:51 +07:00
parent e654829b4c
commit 1b79daffd9
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -1,11 +1,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import js_to_json
class DiggIE(InfoExtractor): class DiggIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?digg\.com/video/(?P<id>[^/?#&]+)' _VALID_URL = r'https?://(?:www\.)?digg\.com/video/(?P<id>[^/?#&]+)'
_TEST = { _TESTS = [{
# JWPlatform via provider
'url': 'http://digg.com/video/sci-fi-short-jonah-daniel-kaluuya-get-out', 'url': 'http://digg.com/video/sci-fi-short-jonah-daniel-kaluuya-get-out',
'info_dict': { 'info_dict': {
'id': 'LcqvmS0b', 'id': 'LcqvmS0b',
@ -18,24 +20,37 @@ class DiggIE(InfoExtractor):
'params': { 'params': {
'skip_download': True, 'skip_download': True,
}, },
} }, {
# Youtube via provider
'url': 'http://digg.com/video/dog-boat-seal-play',
'only_matching': True,
}, {
# vimeo as regular embed
'url': 'http://digg.com/video/dream-girl-short-film',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id) webpage = self._download_webpage(url, display_id)
jwplatform_id = self._search_regex( info = self._parse_json(
r'video_id\s*:\s*["\']([a-zA-Z0-9]{8})', webpage, 'jwplatform id', self._search_regex(
default=None) r'(?s)video_info\s*=\s*({.+?});\n', webpage, 'video info',
default='{}'), display_id, transform_source=js_to_json,
fatal=False)
if not jwplatform_id: video_id = info.get('video_id')
return self.url_result(url, 'Generic')
return { if video_id:
'_type': 'url_transparent', provider = info.get('provider_name')
'ie_key': 'JWPlatform', if provider == 'youtube':
'url': 'jwplatform:%s' % jwplatform_id, return self.url_result(
'id': jwplatform_id, video_id, ie='Youtube', video_id=video_id)
'display_id': display_id, elif provider == 'jwplayer':
} return self.url_result(
'jwplatform:%s' % video_id, ie='JWPlatform',
video_id=video_id)
return self.url_result(url, 'Generic')