]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/libraryofcongress.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class LibraryOfCongressIE(InfoExtractor
):
18 IE_DESC
= 'Library of Congress'
19 _VALID_URL
= r
'https?://(?:www\.)?loc\.gov/(?:item/|today/cyberlc/feature_wdesc\.php\?.*\brec=)(?P<id>[0-9]+)'
21 # embedded via <div class="media-player"
22 'url': 'http://loc.gov/item/90716351/',
23 'md5': '353917ff7f0255aa6d4b80a034833de8',
27 'title': "Pa's trip to Mars",
28 'thumbnail': r
're:^https?://.*\.jpg$',
33 # webcast embedded via mediaObjectId
34 'url': 'https://www.loc.gov/today/cyberlc/feature_wdesc.php?rec=5578',
38 'title': 'Help! Preservation Training Needs Here, There & Everywhere',
41 'subtitles': 'mincount:1',
44 'skip_download': True,
47 # with direct download links
48 'url': 'https://www.loc.gov/item/78710669/',
52 'title': 'La vie et la passion de Jesus-Christ',
55 'formats': 'mincount:4',
58 'skip_download': True,
62 def _real_extract(self
, url
):
63 video_id
= self
._match
_id
(url
)
64 webpage
= self
._download
_webpage
(url
, video_id
)
66 media_id
= self
._search
_regex
(
67 (r
'id=(["\'])media
-player
-(?P
<id>.+?
)\
1',
68 r'<video
[^
>]+id=(["\'])uuid-(?P<id>.+?)\1',
69 r'<video[^>]+data-uuid=(["\'])(?P
<id>.+?
)\
1',
70 r'mediaObjectId\s
*:\s
*(["\'])(?P<id>.+?)\1'),
71 webpage, 'media id', group='id')
73 data = self._download_json(
74 'https://media.loc.gov/services/v1/media?id=%s&context=json' % media_id,
75 video_id)['mediaObject']
77 derivative = data['derivatives'][0]
78 media_url = derivative['derivativeUrl']
80 title = derivative.get('shortName') or data.get('shortName') or self._og_search_title(
83 # Following algorithm was extracted from setAVSource js function
85 media_url = media_url.replace('rtmp', 'https')
87 is_video = data.get('mediaType', 'v').lower() == 'v'
88 ext = determine_ext(media_url)
89 if ext not in ('mp4', 'mp3'):
90 media_url += '.mp4' if is_video else '.mp3'
92 if 'vod/mp4:' in media_url:
94 'url': media_url.replace('vod/mp4:', 'hls-vod/media/') + '.m3u8',
97 'protocol': 'm3u8_native',
100 elif 'vod/mp3:' in media_url:
102 'url': media_url.replace('vod/mp3:', ''),
106 download_urls = set()
107 for m in re.finditer(
108 r'<option[^>]+value=(["\'])(?P
<url
>.+?
)\
1[^
>]+data
-file-download
=[^
>]+>\s
*(?P
<id>.+?
)(?
:(?
: 
;|\s
+)\
((?P
<size
>.+?
)\
))?\s
*<', webpage):
109 format_id = m.group('id').lower()
110 if format_id == 'gif
':
112 download_url = m.group('url
')
113 if download_url in download_urls:
115 download_urls.add(download_url)
118 'format_id
': format_id,
119 'filesize_approx
': parse_filesize(m.group('size
')),
122 self._sort_formats(formats)
124 duration = float_or_none(data.get('duration
'))
125 view_count = int_or_none(data.get('viewCount
'))
128 cc_url = data.get('ccUrl
')
130 subtitles.setdefault('en
', []).append({
138 'thumbnail
': self._og_search_thumbnail(webpage, default=None),
139 'duration
': duration,
140 'view_count
': view_count,
142 'subtitles
': subtitles,