logo

youtube-dl

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

fusion.py (3168B)


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