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.

48 lines
1.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. get_element_by_attribute,
  6. parse_duration,
  7. update_url_query,
  8. ExtractorError,
  9. )
  10. from ..compat import compat_str
  11. class USATodayIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?usatoday\.com/(?:[^/]+/)*(?P<id>[^?/#]+)'
  13. _TEST = {
  14. 'url': 'http://www.usatoday.com/media/cinematic/video/81729424/us-france-warn-syrian-regime-ahead-of-new-peace-talks/',
  15. 'md5': '4d40974481fa3475f8bccfd20c5361f8',
  16. 'info_dict': {
  17. 'id': '81729424',
  18. 'ext': 'mp4',
  19. 'title': 'US, France warn Syrian regime ahead of new peace talks',
  20. 'timestamp': 1457891045,
  21. 'description': 'md5:7e50464fdf2126b0f533748d3c78d58f',
  22. 'uploader_id': '29906170001',
  23. 'upload_date': '20160313',
  24. }
  25. }
  26. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/29906170001/38a9eecc-bdd8-42a3-ba14-95397e48b3f8_default/index.html?videoId=%s'
  27. def _real_extract(self, url):
  28. display_id = self._match_id(url)
  29. webpage = self._download_webpage(update_url_query(url, {'ajax': 'true'}), display_id)
  30. ui_video_data = get_element_by_attribute('class', 'ui-video-data', webpage)
  31. if not ui_video_data:
  32. raise ExtractorError('no video on the webpage', expected=True)
  33. video_data = self._parse_json(ui_video_data, display_id)
  34. return {
  35. '_type': 'url_transparent',
  36. 'url': self.BRIGHTCOVE_URL_TEMPLATE % video_data['brightcove_id'],
  37. 'id': compat_str(video_data['id']),
  38. 'title': video_data['title'],
  39. 'thumbnail': video_data.get('thumbnail'),
  40. 'description': video_data.get('description'),
  41. 'duration': parse_duration(video_data.get('length')),
  42. 'ie_key': 'BrightcoveNew',
  43. }