bostonglobe.py 3.0 KB

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