[spankbang] Check formats (#8398)
[youtube-dl] / youtube_dl / extractor / spankbang.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class SpankBangIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:(?:www|[a-z]{2})\.)?spankbang\.com/(?P<id>[\da-z]+)/video'
10     _TEST = {
11         'url': 'http://spankbang.com/3vvn/video/fantasy+solo',
12         'md5': '1cc433e1d6aa14bc376535b8679302f7',
13         'info_dict': {
14             'id': '3vvn',
15             'ext': 'mp4',
16             'title': 'fantasy solo',
17             'description': 'dillion harper masturbates on a bed',
18             'thumbnail': 're:^https?://.*\.jpg$',
19             'uploader': 'silly2587',
20             'age_limit': 18,
21         }
22     }
23
24     def _real_extract(self, url):
25         video_id = self._match_id(url)
26         webpage = self._download_webpage(url, video_id)
27
28         stream_key = self._html_search_regex(
29             r'''var\s+stream_key\s*=\s*['"](.+?)['"]''',
30             webpage, 'stream key')
31
32         formats = [{
33             'url': 'http://spankbang.com/_%s/%s/title/%sp__mp4' % (video_id, stream_key, height),
34             'ext': 'mp4',
35             'format_id': '%sp' % height,
36             'height': int(height),
37         } for height in re.findall(r'<(?:span|li|p)[^>]+[qb]_(\d+)p', webpage)]
38         self._check_formats(formats, video_id)
39         self._sort_formats(formats)
40
41         title = self._html_search_regex(
42             r'(?s)<h1[^>]*>(.+?)</h1>', webpage, 'title')
43         description = self._search_regex(
44             r'class="desc"[^>]*>([^<]+)',
45             webpage, 'description', default=None)
46         thumbnail = self._og_search_thumbnail(webpage)
47         uploader = self._search_regex(
48             r'class="user"[^>]*>([^<]+)',
49             webpage, 'uploader', fatal=False)
50
51         age_limit = self._rta_search(webpage)
52
53         return {
54             'id': video_id,
55             'title': title,
56             'description': description,
57             'thumbnail': thumbnail,
58             'uploader': uploader,
59             'formats': formats,
60             'age_limit': age_limit,
61         }