usatoday.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. get_element_by_attribute,
  5. parse_duration,
  6. try_get,
  7. update_url_query,
  8. )
  9. class USATodayIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?usatoday\.com/(?:[^/]+/)*(?P<id>[^?/#]+)'
  11. _TESTS = [{
  12. # Brightcove Partner ID = 29906170001
  13. 'url': 'http://www.usatoday.com/media/cinematic/video/81729424/us-france-warn-syrian-regime-ahead-of-new-peace-talks/',
  14. 'md5': '033587d2529dc3411a1ab3644c3b8827',
  15. 'info_dict': {
  16. 'id': '4799374959001',
  17. 'ext': 'mp4',
  18. 'title': 'US, France warn Syrian regime ahead of new peace talks',
  19. 'timestamp': 1457891045,
  20. 'description': 'md5:7e50464fdf2126b0f533748d3c78d58f',
  21. 'uploader_id': '29906170001',
  22. 'upload_date': '20160313',
  23. },
  24. }, {
  25. # ui-video-data[asset_metadata][items][brightcoveaccount] = 28911775001
  26. 'url': 'https://www.usatoday.com/story/tech/science/2018/08/21/yellowstone-supervolcano-eruption-stop-worrying-its-blow/973633002/',
  27. 'info_dict': {
  28. 'id': '5824495846001',
  29. 'ext': 'mp4',
  30. 'title': 'Yellowstone more likely to crack rather than explode',
  31. 'timestamp': 1534790612,
  32. 'description': 'md5:3715e7927639a4f16b474e9391687c62',
  33. 'uploader_id': '28911775001',
  34. 'upload_date': '20180820',
  35. },
  36. }]
  37. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/default_default/index.html?videoId=%s'
  38. def _real_extract(self, url):
  39. display_id = self._match_id(url)
  40. webpage = self._download_webpage(update_url_query(url, {'ajax': 'true'}), display_id)
  41. ui_video_data = get_element_by_attribute('class', 'ui-video-data', webpage)
  42. if not ui_video_data:
  43. raise ExtractorError('no video on the webpage', expected=True)
  44. video_data = self._parse_json(ui_video_data, display_id)
  45. item = try_get(video_data, lambda x: x['asset_metadata']['items'], dict) or {}
  46. return {
  47. '_type': 'url_transparent',
  48. 'url': self.BRIGHTCOVE_URL_TEMPLATE % (item.get('brightcoveaccount', '29906170001'), item.get('brightcoveid') or video_data['brightcove_id']),
  49. 'id': str(video_data['id']),
  50. 'title': video_data['title'],
  51. 'thumbnail': video_data.get('thumbnail'),
  52. 'description': video_data.get('description'),
  53. 'duration': parse_duration(video_data.get('length')),
  54. 'ie_key': 'BrightcoveNew',
  55. }