3 from .common
import InfoExtractor
12 class LibraryOfCongressIE(InfoExtractor
):
14 IE_DESC
= 'Library of Congress'
15 _VALID_URL
= r
'https?://(?:www\.)?loc\.gov/(?:item/|today/cyberlc/feature_wdesc\.php\?.*\brec=)(?P<id>[0-9a-z_.]+)'
17 # embedded via <div class="media-player"
18 'url': 'http://loc.gov/item/90716351/',
19 'md5': '6ec0ae8f07f86731b1b2ff70f046210a',
23 'title': "Pa's trip to Mars",
28 # webcast embedded via mediaObjectId
29 'url': 'https://www.loc.gov/today/cyberlc/feature_wdesc.php?rec=5578',
33 'title': 'Help! Preservation Training Needs Here, There & Everywhere',
36 'subtitles': 'mincount:1',
39 'skip_download': True,
42 # with direct download links
43 'url': 'https://www.loc.gov/item/78710669/',
47 'title': 'La vie et la passion de Jesus-Christ',
50 'formats': 'mincount:4',
53 'skip_download': True,
56 'url': 'https://www.loc.gov/item/ihas.200197114/',
57 'only_matching': True,
59 'url': 'https://www.loc.gov/item/afc1981005_afs20503/',
60 'only_matching': True,
63 def _real_extract(self
, url
):
64 video_id
= self
._match
_id
(url
)
65 webpage
= self
._download
_webpage
(url
, video_id
)
67 media_id
= self
._search
_regex
(
68 (r
'id=(["\'])media
-player
-(?P
<id>.+?
)\
1',
69 r'<video
[^
>]+id=(["\'])uuid-(?P<id>.+?)\1',
70 r'<video[^>]+data-uuid=(["\'])(?P
<id>.+?
)\
1',
71 r'mediaObjectId\s
*:\s
*(["\'])(?P<id>.+?)\1',
72 r'data-tab="share
-media
-(?P
<id>[0-9A
-F
]{32}
)"'),
73 webpage, 'media id', group='id')
75 data = self._download_json(
76 f'https://media.loc.gov/services/v1/media?id={media_id}&context=json',
77 media_id)['mediaObject']
79 derivative = data['derivatives'][0]
80 media_url = derivative['derivativeUrl']
82 title = derivative.get('shortName') or data.get('shortName') or self._og_search_title(
85 # Following algorithm was extracted from setAVSource js function
87 media_url = media_url.replace('rtmp', 'https')
89 is_video = data.get('mediaType', 'v').lower() == 'v'
90 ext = determine_ext(media_url)
91 if ext not in ('mp4', 'mp3'):
92 media_url += '.mp4' if is_video else '.mp3'
95 if '/vod/mp4:' in media_url:
97 'url': media_url.replace('/vod/mp4:', '/hls-vod/media/') + '.m3u8',
100 'protocol': 'm3u8_native',
104 'url': re.sub(r'(://[^/]+/)(?:[^/]+/)*(?:mp4|mp3):', r'\1', media_url),
109 http_format['vcodec'] = 'none'
110 formats.append(http_format)
112 download_urls = set()
113 for m in re.finditer(
114 r'<option[^>]+value=(["\'])(?P
<url
>.+?
)\
1[^
>]+data
-file-download
=[^
>]+>\s
*(?P
<id>.+?
)(?
:(?
: 
;|\s
+)\
((?P
<size
>.+?
)\
))?\s
*<', webpage):
115 format_id = m.group('id').lower()
116 if format_id in ('gif
', 'jpeg
'):
118 download_url = m.group('url
')
119 if download_url in download_urls:
121 download_urls.add(download_url)
124 'format_id
': format_id,
125 'filesize_approx
': parse_filesize(m.group('size
')),
128 duration = float_or_none(data.get('duration
'))
129 view_count = int_or_none(data.get('viewCount
'))
132 cc_url = data.get('ccUrl
')
134 subtitles.setdefault('en
', []).append({
142 'thumbnail
': self._og_search_thumbnail(webpage, default=None),
143 'duration
': duration,
144 'view_count
': view_count,
146 'subtitles
': subtitles,