thesun.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import extract_attributes
  4. class TheSunIE(InfoExtractor):
  5. _VALID_URL = r'https://(?:www\.)?thesun\.co\.uk/[^/]+/(?P<id>\d+)'
  6. _TEST = {
  7. 'url': 'https://www.thesun.co.uk/tvandshowbiz/2261604/orlando-bloom-and-katy-perry-post-adorable-instagram-video-together-celebrating-thanksgiving-after-split-rumours/',
  8. 'info_dict': {
  9. 'id': '2261604',
  10. 'title': 'md5:cba22f48bad9218b64d5bbe0e16afddf',
  11. },
  12. 'playlist_count': 2,
  13. }
  14. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
  15. def _real_extract(self, url):
  16. article_id = self._match_id(url)
  17. webpage = self._download_webpage(url, article_id)
  18. entries = []
  19. for video in re.findall(
  20. r'<video[^>]+data-video-id-pending=[^>]+>',
  21. webpage):
  22. attrs = extract_attributes(video)
  23. video_id = attrs['data-video-id-pending']
  24. account_id = attrs.get('data-account', '5067014667001')
  25. entries.append(self.url_result(
  26. self.BRIGHTCOVE_URL_TEMPLATE % (account_id, video_id),
  27. 'BrightcoveNew', video_id))
  28. return self.playlist_result(
  29. entries, article_id, self._og_search_title(webpage, fatal=False))