logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

reuters.py (2438B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. js_to_json,
  7. int_or_none,
  8. unescapeHTML,
  9. )
  10. class ReutersIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?reuters\.com/.*?\?.*?videoId=(?P<id>[0-9]+)'
  12. _TEST = {
  13. 'url': 'http://www.reuters.com/video/2016/05/20/san-francisco-police-chief-resigns?videoId=368575562',
  14. 'md5': '8015113643a0b12838f160b0b81cc2ee',
  15. 'info_dict': {
  16. 'id': '368575562',
  17. 'ext': 'mp4',
  18. 'title': 'San Francisco police chief resigns',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. webpage = self._download_webpage(
  24. 'http://www.reuters.com/assets/iframe/yovideo?videoId=%s' % video_id, video_id)
  25. video_data = js_to_json(self._search_regex(
  26. r'(?s)Reuters\.yovideo\.drawPlayer\(({.*?})\);',
  27. webpage, 'video data'))
  28. def get_json_value(key, fatal=False):
  29. return self._search_regex(r'"%s"\s*:\s*"([^"]+)"' % key, video_data, key, fatal=fatal)
  30. title = unescapeHTML(get_json_value('title', fatal=True))
  31. mmid, fid = re.search(r',/(\d+)\?f=(\d+)', get_json_value('flv', fatal=True)).groups()
  32. mas_data = self._download_json(
  33. 'http://mas-e.cds1.yospace.com/mas/%s/%s?trans=json' % (mmid, fid),
  34. video_id, transform_source=js_to_json)
  35. formats = []
  36. for f in mas_data:
  37. f_url = f.get('url')
  38. if not f_url:
  39. continue
  40. method = f.get('method')
  41. if method == 'hls':
  42. formats.extend(self._extract_m3u8_formats(
  43. f_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  44. else:
  45. container = f.get('container')
  46. ext = '3gp' if method == 'mobile' else container
  47. formats.append({
  48. 'format_id': ext,
  49. 'url': f_url,
  50. 'ext': ext,
  51. 'container': container if method != 'mobile' else None,
  52. })
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'thumbnail': get_json_value('thumb'),
  58. 'duration': int_or_none(get_json_value('seconds')),
  59. 'formats': formats,
  60. }