]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/bostonglobe.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / bostonglobe.py
CommitLineData
46b18f23
JH
1import re
2
3from .common import InfoExtractor
46b18f23
JH
4from ..utils import (
5 extract_attributes,
6)
7
8
9class BostonGlobeIE(InfoExtractor):
10 _VALID_URL = r'(?i)https?://(?:www\.)?bostonglobe\.com/.*/(?P<id>[^/]+)/\w+(?:\.html)?'
11 _TESTS = [
12 {
13 'url': 'http://www.bostonglobe.com/metro/2017/02/11/tree-finally-succumbs-disease-leaving-hole-neighborhood/h1b4lviqzMTIn9sVy8F3gP/story.html',
14 'md5': '0a62181079c85c2d2b618c9a738aedaf',
15 'info_dict': {
16 'title': 'A tree finally succumbs to disease, leaving a hole in a neighborhood',
17 'id': '5320421710001',
18 'ext': 'mp4',
19 '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.',
20 'timestamp': 1486877593,
21 'upload_date': '20170212',
22 'uploader_id': '245991542',
23 },
24 },
25 {
26 # Embedded youtube video; we hand it off to the Generic extractor.
27 'url': 'https://www.bostonglobe.com/lifestyle/names/2017/02/17/does-ben-affleck-play-matt-damon-favorite-version-batman/ruqkc9VxKBYmh5txn1XhSI/story.html',
28 'md5': '582b40327089d5c0c949b3c54b13c24b',
29 'info_dict': {
30 'title': "Who Is Matt Damon's Favorite Batman?",
31 'id': 'ZW1QCnlA6Qc',
32 'ext': 'mp4',
33 'upload_date': '20170217',
34 'description': 'md5:3b3dccb9375867e0b4d527ed87d307cb',
35 'uploader': 'The Late Late Show with James Corden',
36 'uploader_id': 'TheLateLateShow',
37 },
38 'expected_warnings': ['404'],
39 },
40 ]
41
42 def _real_extract(self, url):
43 page_id = self._match_id(url)
44 webpage = self._download_webpage(url, page_id)
45
46 page_title = self._og_search_title(webpage, default=None)
47
48 # <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">
49 entries = []
50 for video in re.findall(r'(?i)(<video[^>]+>)', webpage):
51 attrs = extract_attributes(video)
52
53 video_id = attrs.get('data-brightcove-video-id')
54 account_id = attrs.get('data-account')
55 player_id = attrs.get('data-player')
56 embed = attrs.get('data-embed')
57
58 if video_id and account_id and player_id and embed:
59 entries.append(
60 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s'
61 % (account_id, player_id, embed, video_id))
62
63 if len(entries) == 0:
64 return self.url_result(url, 'Generic')
65 elif len(entries) == 1:
66 return self.url_result(entries[0], 'BrightcoveNew')
67 else:
68 return self.playlist_from_matches(entries, page_id, page_title, ie='BrightcoveNew')