thesun.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import extract_attributes
  4. class TheSunIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:www\.)?the-?sun(\.co\.uk|\.com)/[^/]+/(?P<id>\d+)'
  6. _TESTS = [{
  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. 'url': 'https://www.the-sun.com/entertainment/7611415/1000lb-sisters-fans-rip-amy-dangerous-health-decision/',
  15. 'info_dict': {
  16. 'id': '7611415',
  17. 'title': 'md5:e0b9b976f79dc770e5c80f22f40bb844',
  18. },
  19. 'playlist_count': 1,
  20. }]
  21. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
  22. def _real_extract(self, url):
  23. article_id = self._match_id(url)
  24. webpage = self._download_webpage(url, article_id)
  25. entries = []
  26. for video in re.findall(
  27. r'<video[^>]+data-video-id-pending=[^>]+>',
  28. webpage):
  29. attrs = extract_attributes(video)
  30. video_id = attrs['data-video-id-pending']
  31. account_id = attrs.get('data-account', '5067014667001')
  32. entries.append(self.url_result(
  33. self.BRIGHTCOVE_URL_TEMPLATE % (account_id, video_id),
  34. 'BrightcoveNew', video_id))
  35. return self.playlist_result(
  36. entries, article_id, self._og_search_title(webpage, fatal=False))