You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.1 KiB

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