3 from .common
import InfoExtractor
13 class LibraryOfCongressIE(InfoExtractor
):
15 IE_DESC
= 'Library of Congress'
16 _VALID_URL
= r
'https?://(?:www\.)?loc\.gov/(?:item/|today/cyberlc/feature_wdesc\.php\?.*\brec=)(?P<id>[0-9a-z_.]+)'
18 # embedded via <div class="media-player"
19 'url': 'http://loc.gov/item/90716351/',
20 'md5': '6ec0ae8f07f86731b1b2ff70f046210a',
24 'title': "Pa's trip to Mars",
29 # webcast embedded via mediaObjectId
30 'url': 'https://www.loc.gov/today/cyberlc/feature_wdesc.php?rec=5578',
34 'title': 'Help! Preservation Training Needs Here, There & Everywhere',
37 'subtitles': 'mincount:1',
40 'skip_download': True,
43 # with direct download links
44 'url': 'https://www.loc.gov/item/78710669/',
48 'title': 'La vie et la passion de Jesus-Christ',
51 'formats': 'mincount:4',
54 'skip_download': True,
57 'url': 'https://www.loc.gov/item/ihas.200197114/',
58 'only_matching': True,
60 'url': 'https://www.loc.gov/item/afc1981005_afs20503/',
61 'only_matching': True,
64 def _real_extract(self
, url
):
65 video_id
= self
._match
_id
(url
)
66 webpage
= self
._download
_webpage
(url
, video_id
)
68 media_id
= self
._search
_regex
(
69 (r
'id=(["\'])media
-player
-(?P
<id>.+?
)\
1',
70 r'<video
[^
>]+id=(["\'])uuid-(?P<id>.+?)\1',
71 r'<video[^>]+data-uuid=(["\'])(?P
<id>.+?
)\
1',
72 r'mediaObjectId\s
*:\s
*(["\'])(?P<id>.+?)\1',
73 r'data-tab="share
-media
-(?P
<id>[0-9A
-F
]{32}
)"'),
74 webpage, 'media id', group='id')
76 data = self._download_json(
77 'https://media.loc.gov/services/v1/media?id=%s&context=json' % media_id,
78 media_id)['mediaObject']
80 derivative = data['derivatives'][0]
81 media_url = derivative['derivativeUrl']
83 title = derivative.get('shortName') or data.get('shortName') or self._og_search_title(
86 # Following algorithm was extracted from setAVSource js function
88 media_url = media_url.replace('rtmp', 'https')
90 is_video = data.get('mediaType', 'v').lower() == 'v'
91 ext = determine_ext(media_url)
92 if ext not in ('mp4', 'mp3'):
93 media_url += '.mp4' if is_video else '.mp3'
96 if '/vod/mp4:' in media_url:
98 'url': media_url.replace('/vod/mp4:', '/hls-vod/media/') + '.m3u8',
101 'protocol': 'm3u8_native',
105 'url': re.sub(r'(://[^/]+/)(?:[^/]+/)*(?:mp4|mp3):', r'\1', media_url),
110 http_format['vcodec'] = 'none'
111 formats.append(http_format)
113 download_urls = set()
114 for m in re.finditer(
115 r'<option[^>]+value=(["\'])(?P
<url
>.+?
)\
1[^
>]+data
-file-download
=[^
>]+>\s
*(?P
<id>.+?
)(?
:(?
: 
;|\s
+)\
((?P
<size
>.+?
)\
))?\s
*<', webpage):
116 format_id = m.group('id').lower()
117 if format_id in ('gif
', 'jpeg
'):
119 download_url = m.group('url
')
120 if download_url in download_urls:
122 download_urls.add(download_url)
125 'format_id
': format_id,
126 'filesize_approx
': parse_filesize(m.group('size
')),
129 duration = float_or_none(data.get('duration
'))
130 view_count = int_or_none(data.get('viewCount
'))
133 cc_url = data.get('ccUrl
')
135 subtitles.setdefault('en
', []).append({
143 'thumbnail
': self._og_search_thumbnail(webpage, default=None),
144 'duration
': duration,
145 'view_count
': view_count,
147 'subtitles
': subtitles,