[plays] Add new extractor(#8458)
[youtube-dl] / youtube_dl / extractor / plays.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import int_or_none
8
9
10 class PlaysTVIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?plays\.tv/video/(?P<id>[0-9a-f]{18})'
12     _TEST = {
13         'url': 'http://plays.tv/video/56af17f56c95335490/when-you-outplay-the-azir-wall',
14         'md5': 'dfeac1198506652b5257a62762cec7bc',
15         'info_dict': {
16             'id': '56af17f56c95335490',
17             'ext': 'mp4',
18             'title': 'When you outplay the Azir wall',
19             'description': 'Posted by Bjergsen',
20         }
21     }
22
23     def _real_extract(self, url):
24         video_id = self._match_id(url)
25         webpage = self._download_webpage(url, video_id)
26
27         title = self._og_search_title(webpage)
28         content = self._parse_json(
29             self._search_regex(r'R\.bindContent\(({.+?})\);', webpage,
30             'content'), video_id)['content']
31         mpd_url, sources = re.search(
32             r'(?s)<video[^>]+data-mpd="([^"]+)"[^>]*>(.+?)</video>',
33             content).groups()
34         formats = self._extract_mpd_formats(
35             self._proto_relative_url(mpd_url), video_id, mpd_id='DASH')
36         for format_id, height, format_url in re.findall(r'<source\s+res="((\d+)h?)"\s+src="([^"]+)"', sources):
37             formats.append({
38                 'url': self._proto_relative_url(format_url),
39                 'format_id': 'http-' + format_id,
40                 'height': int_or_none(height),
41             })
42         self._sort_formats(formats)
43
44         return {
45             'id': video_id,
46             'title': title,
47             'description': self._og_search_description(webpage),
48             'thumbnail': self._og_search_thumbnail(webpage),
49             'formats': formats,
50         }