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.

73 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. parse_duration,
  7. parse_iso8601,
  8. urlencode_postdata,
  9. )
  10. class UFCTVIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?ufc\.tv/video/(?P<id>[^/]+)'
  12. _NETRC_MACHINE = 'ufctv'
  13. _TEST = {
  14. 'url': 'https://www.ufc.tv/video/ufc-219-countdown-full-episode',
  15. 'info_dict': {
  16. 'id': '34167',
  17. 'ext': 'mp4',
  18. 'title': 'UFC 219 Countdown: Full Episode',
  19. 'description': 'md5:26d4e8bf4665ae5878842d7050c3c646',
  20. 'timestamp': 1513962360,
  21. 'upload_date': '20171222',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. }
  27. }
  28. def _real_initialize(self):
  29. username, password = self._get_login_info()
  30. if username is None:
  31. return
  32. code = self._download_json(
  33. 'https://www.ufc.tv/secure/authenticate',
  34. None, 'Logging in', data=urlencode_postdata({
  35. 'username': username,
  36. 'password': password,
  37. 'format': 'json',
  38. })).get('code')
  39. if code and code != 'loginsuccess':
  40. raise ExtractorError(code, expected=True)
  41. def _real_extract(self, url):
  42. display_id = self._match_id(url)
  43. video_data = self._download_json(url, display_id, query={
  44. 'format': 'json',
  45. })
  46. video_id = str(video_data['id'])
  47. title = video_data['name']
  48. m3u8_url = self._download_json(
  49. 'https://www.ufc.tv/service/publishpoint', video_id, query={
  50. 'type': 'video',
  51. 'format': 'json',
  52. 'id': video_id,
  53. }, headers={
  54. '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',
  55. })['path']
  56. m3u8_url = m3u8_url.replace('_iphone.', '.')
  57. formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
  58. self._sort_formats(formats)
  59. return {
  60. 'id': video_id,
  61. 'title': title,
  62. 'description': video_data.get('description'),
  63. 'duration': parse_duration(video_data.get('runtime')),
  64. 'timestamp': parse_iso8601(video_data.get('releaseDate')),
  65. 'formats': formats,
  66. }