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