[loc] Add support for another URL schema and simplify

This commit is contained in:
Sergey M․ 2016-06-03 23:43:34 +07:00
parent bf4c6a38e1
commit 76e9cd7f24
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -13,8 +13,8 @@
class LibraryOfCongressIE(InfoExtractor): class LibraryOfCongressIE(InfoExtractor):
IE_NAME = 'loc' IE_NAME = 'loc'
IE_DESC = 'Library of Congress' IE_DESC = 'Library of Congress'
_VALID_URL = r'https?://(?:www\.)?loc\.gov/item/(?P<id>[0-9]+)' _VALID_URL = r'https?://(?:www\.)?loc\.gov/(?:item/|today/cyberlc/feature_wdesc\.php\?.*\brec=)(?P<id>[0-9]+)'
_TEST = { _TESTS = [{
'url': 'http://loc.gov/item/90716351/', 'url': 'http://loc.gov/item/90716351/',
'md5': '353917ff7f0255aa6d4b80a034833de8', 'md5': '353917ff7f0255aa6d4b80a034833de8',
'info_dict': { 'info_dict': {
@ -25,7 +25,10 @@ class LibraryOfCongressIE(InfoExtractor):
'duration': 0, 'duration': 0,
'view_count': int, 'view_count': int,
}, },
} }, {
'url': 'https://www.loc.gov/today/cyberlc/feature_wdesc.php?rec=5578',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
@ -34,13 +37,12 @@ def _real_extract(self, url):
media_id = self._search_regex( media_id = self._search_regex(
(r'id=(["\'])media-player-(?P<id>.+?)\1', (r'id=(["\'])media-player-(?P<id>.+?)\1',
r'<video[^>]+id=(["\'])uuid-(?P<id>.+?)\1', r'<video[^>]+id=(["\'])uuid-(?P<id>.+?)\1',
r'<video[^>]+data-uuid=(["\'])(?P<id>.+?)\1'), r'<video[^>]+data-uuid=(["\'])(?P<id>.+?)\1',
r'mediaObjectId\s*:\s*(["\'])(?P<id>.+?)\1'),
webpage, 'media id', group='id') webpage, 'media id', group='id')
data = self._parse_json( data = self._download_json(
self._download_webpage( 'https://media.loc.gov/services/v1/media?id=%s&context=json' % media_id,
'https://media.loc.gov/services/v1/media?id=%s&context=json' % media_id,
video_id),
video_id)['mediaObject'] video_id)['mediaObject']
derivative = data['derivatives'][0] derivative = data['derivatives'][0]
@ -77,7 +79,7 @@ def _real_extract(self, url):
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'thumbnail': self._og_search_thumbnail(webpage), 'thumbnail': self._og_search_thumbnail(webpage, default=None),
'duration': duration, 'duration': duration,
'view_count': view_count, 'view_count': view_count,
'formats': formats, 'formats': formats,