]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/bostonglobe.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / bostonglobe.py
1 import re
2
3 from .common import InfoExtractor
4
5 from ..utils import (
6 extract_attributes,
7 )
8
9
10 class BostonGlobeIE(InfoExtractor):
11 _VALID_URL = r'(?i)https?://(?:www\.)?bostonglobe\.com/.*/(?P<id>[^/]+)/\w+(?:\.html)?'
12 _TESTS = [
13 {
14 'url': 'http://www.bostonglobe.com/metro/2017/02/11/tree-finally-succumbs-disease-leaving-hole-neighborhood/h1b4lviqzMTIn9sVy8F3gP/story.html',
15 'md5': '0a62181079c85c2d2b618c9a738aedaf',
16 'info_dict': {
17 'title': 'A tree finally succumbs to disease, leaving a hole in a neighborhood',
18 'id': '5320421710001',
19 'ext': 'mp4',
20 'description': 'It arrived as a sapling when the Back Bay was in its infancy, a spindly American elm tamped down into a square of dirt cut into the brick sidewalk of 1880s Marlborough Street, no higher than the first bay window of the new brownstone behind it.',
21 'timestamp': 1486877593,
22 'upload_date': '20170212',
23 'uploader_id': '245991542',
24 },
25 },
26 {
27 # Embedded youtube video; we hand it off to the Generic extractor.
28 'url': 'https://www.bostonglobe.com/lifestyle/names/2017/02/17/does-ben-affleck-play-matt-damon-favorite-version-batman/ruqkc9VxKBYmh5txn1XhSI/story.html',
29 'md5': '582b40327089d5c0c949b3c54b13c24b',
30 'info_dict': {
31 'title': "Who Is Matt Damon's Favorite Batman?",
32 'id': 'ZW1QCnlA6Qc',
33 'ext': 'mp4',
34 'upload_date': '20170217',
35 'description': 'md5:3b3dccb9375867e0b4d527ed87d307cb',
36 'uploader': 'The Late Late Show with James Corden',
37 'uploader_id': 'TheLateLateShow',
38 },
39 'expected_warnings': ['404'],
40 },
41 ]
42
43 def _real_extract(self, url):
44 page_id = self._match_id(url)
45 webpage = self._download_webpage(url, page_id)
46
47 page_title = self._og_search_title(webpage, default=None)
48
49 # <video data-brightcove-video-id="5320421710001" data-account="245991542" data-player="SJWAiyYWg" data-embed="default" class="video-js" controls itemscope itemtype="http://schema.org/VideoObject">
50 entries = []
51 for video in re.findall(r'(?i)(<video[^>]+>)', webpage):
52 attrs = extract_attributes(video)
53
54 video_id = attrs.get('data-brightcove-video-id')
55 account_id = attrs.get('data-account')
56 player_id = attrs.get('data-player')
57 embed = attrs.get('data-embed')
58
59 if video_id and account_id and player_id and embed:
60 entries.append(
61 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
62 % (account_id, player_id, embed, video_id))
63
64 if len(entries) == 0:
65 return self.url_result(url, 'Generic')
66 elif len(entries) == 1:
67 return self.url_result(entries[0], 'BrightcoveNew')
68 else:
69 return self.playlist_from_matches(entries, page_id, page_title, ie='BrightcoveNew')