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.

55 lines
1.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. parse_iso8601,
  7. )
  8. class UFCTVIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?ufc\.tv/video/(?P<id>[^/]+)'
  10. _TEST = {
  11. 'url': 'https://www.ufc.tv/video/ufc-219-countdown-full-episode',
  12. 'info_dict': {
  13. 'id': '34167',
  14. 'ext': 'mp4',
  15. 'title': 'UFC 219 Countdown: Full Episode',
  16. 'description': 'md5:26d4e8bf4665ae5878842d7050c3c646',
  17. 'timestamp': 1513962360,
  18. 'upload_date': '20171222',
  19. },
  20. 'params': {
  21. # m3u8 download
  22. 'skip_download': True,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. display_id = self._match_id(url)
  27. video_data = self._download_json(url, display_id, query={
  28. 'format': 'json',
  29. })
  30. video_id = str(video_data['id'])
  31. title = video_data['name']
  32. m3u8_url = self._download_json(
  33. 'https://www.ufc.tv/service/publishpoint', video_id, query={
  34. 'type': 'video',
  35. 'format': 'json',
  36. 'id': video_id,
  37. }, headers={
  38. 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0_1 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A402 Safari/604.1',
  39. })['path']
  40. m3u8_url = m3u8_url.replace('_iphone.', '.')
  41. formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
  42. self._sort_formats(formats)
  43. return {
  44. 'id': video_id,
  45. 'title': title,
  46. 'description': video_data.get('description'),
  47. 'duration': parse_duration(video_data.get('runtime')),
  48. 'timestamp': parse_iso8601(video_data.get('releaseDate')),
  49. 'formats': formats,
  50. }