fusion.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. mimetype2ext,
  6. parse_iso8601,
  7. )
  8. class FusionIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?fusion\.(?:net|tv)/(?:video/|show/.+?\bvideo=)(?P<id>\d+)'
  10. _TESTS = [{
  11. 'url': 'http://fusion.tv/video/201781/u-s-and-panamanian-forces-work-together-to-stop-a-vessel-smuggling-drugs/',
  12. 'info_dict': {
  13. 'id': '3145868',
  14. 'ext': 'mp4',
  15. 'title': 'U.S. and Panamanian forces work together to stop a vessel smuggling drugs',
  16. 'description': 'md5:0cc84a9943c064c0f46b128b41b1b0d7',
  17. 'duration': 140.0,
  18. 'timestamp': 1442589635,
  19. 'uploader': 'UNIVISON',
  20. 'upload_date': '20150918',
  21. },
  22. 'params': {
  23. 'skip_download': True,
  24. },
  25. 'add_ie': ['Anvato'],
  26. }, {
  27. 'url': 'http://fusion.tv/video/201781',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'https://fusion.tv/show/food-exposed-with-nelufar-hedayat/?ancla=full-episodes&video=588644',
  31. 'only_matching': True,
  32. }]
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. video = self._download_json(
  36. 'https://platform.fusion.net/wp-json/fusiondotnet/v1/video/' + video_id, video_id)
  37. info = {
  38. 'id': video_id,
  39. 'title': video['title'],
  40. 'description': video.get('excerpt'),
  41. 'timestamp': parse_iso8601(video.get('published')),
  42. 'series': video.get('show'),
  43. }
  44. formats = []
  45. src = video.get('src') or {}
  46. for f_id, f in src.items():
  47. for q_id, q in f.items():
  48. q_url = q.get('url')
  49. if not q_url:
  50. continue
  51. ext = determine_ext(q_url, mimetype2ext(q.get('type')))
  52. if ext == 'smil':
  53. formats.extend(self._extract_smil_formats(q_url, video_id, fatal=False))
  54. elif f_id == 'm3u8-variant' or (ext == 'm3u8' and q_id == 'Variant'):
  55. formats.extend(self._extract_m3u8_formats(
  56. q_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  57. else:
  58. formats.append({
  59. 'format_id': '-'.join([f_id, q_id]),
  60. 'url': q_url,
  61. 'width': int_or_none(q.get('width')),
  62. 'height': int_or_none(q.get('height')),
  63. 'tbr': int_or_none(self._search_regex(r'_(\d+)\.m(?:p4|3u8)', q_url, 'bitrate')),
  64. 'ext': 'mp4' if ext == 'm3u8' else ext,
  65. 'protocol': 'm3u8_native' if ext == 'm3u8' else 'https',
  66. })
  67. if formats:
  68. info['formats'] = formats
  69. else:
  70. info.update({
  71. '_type': 'url',
  72. 'url': 'anvato:uni:' + video['video_ids']['anvato'],
  73. 'ie_key': 'Anvato',
  74. })
  75. return info