]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ufctv.py
New upstream version 2018.03.14
[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 parse_duration,
7 parse_iso8601,
8 )
9
10
11 class UFCTVIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?ufc\.tv/video/(?P<id>[^/]+)'
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
29 def _real_extract(self, url):
30 display_id = self._match_id(url)
31 video_data = self._download_json(url, display_id, query={
32 'format': 'json',
33 })
34 video_id = str(video_data['id'])
35 title = video_data['name']
36 m3u8_url = self._download_json(
37 'https://www.ufc.tv/service/publishpoint', video_id, query={
38 'type': 'video',
39 'format': 'json',
40 'id': video_id,
41 }, headers={
42 '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',
43 })['path']
44 m3u8_url = m3u8_url.replace('_iphone.', '.')
45 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4')
46 self._sort_formats(formats)
47
48 return {
49 'id': video_id,
50 'title': title,
51 'description': video_data.get('description'),
52 'duration': parse_duration(video_data.get('runtime')),
53 'timestamp': parse_iso8601(video_data.get('releaseDate')),
54 'formats': formats,
55 }