]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tnaflix.py
[extractor/common] Use NO_DEFAULT from utils
[yt-dlp.git] / youtube_dl / extractor / tnaflix.py
CommitLineData
1dba4a21 1from __future__ import unicode_literals
2
3import re
4
5from .common import InfoExtractor
6from ..utils import (
7 parse_duration,
eb833b7f 8 fix_xml_ampersands,
1dba4a21 9)
10
eb833b7f 11
1dba4a21 12class TNAFlixIE(InfoExtractor):
abac15f3 13 _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/[^/]+/(?P<display_id>[^/]+)/video(?P<id>\d+)'
eb833b7f 14
079d1dcd 15 _TITLE_REGEX = r'<title>(.+?) - TNAFlix Porn Videos</title>'
eb833b7f
S
16 _DESCRIPTION_REGEX = r'<h3 itemprop="description">([^<]+)</h3>'
17 _CONFIG_REGEX = r'flashvars\.config\s*=\s*escape\("([^"]+)"'
18
ed5a637d 19 _TESTS = [
20 {
21 'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
22 'md5': 'ecf3498417d09216374fc5907f9c6ec0',
23 'info_dict': {
24 'id': '553878',
25 'display_id': 'Carmella-Decesare-striptease',
26 'ext': 'mp4',
27 'title': 'Carmella Decesare - striptease',
28 'description': '',
29 'thumbnail': 're:https?://.*\.jpg$',
30 'duration': 91,
31 'age_limit': 18,
32 }
33 },
34 {
35 'url': 'https://www.tnaflix.com/amateur-porn/bunzHD-Ms.Donk/video358632',
56c837cc 36 'only_matching': True,
1dba4a21 37 }
ed5a637d 38 ]
1dba4a21 39
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 video_id = mobj.group('id')
43 display_id = mobj.group('display_id')
44
45 webpage = self._download_webpage(url, display_id)
46
eb833b7f
S
47 title = self._html_search_regex(
48 self._TITLE_REGEX, webpage, 'title') if self._TITLE_REGEX else self._og_search_title(webpage)
49 description = self._html_search_regex(
50 self._DESCRIPTION_REGEX, webpage, 'description', fatal=False, default='')
51
52 age_limit = self._rta_search(webpage)
53
e52c0bd0
S
54 duration = parse_duration(self._html_search_meta(
55 'duration', webpage, 'duration', default=None))
eb833b7f 56
68f705ca
S
57 cfg_url = self._proto_relative_url(self._html_search_regex(
58 self._CONFIG_REGEX, webpage, 'flashvars.config'), 'http:')
eb833b7f
S
59
60 cfg_xml = self._download_xml(
61 cfg_url, display_id, note='Downloading metadata',
62 transform_source=fix_xml_ampersands)
63
3d6388e3
S
64 thumbnail = self._proto_relative_url(
65 cfg_xml.find('./startThumb').text, 'http:')
eb833b7f 66
1dba4a21 67 formats = []
eb833b7f
S
68 for item in cfg_xml.findall('./quality/item'):
69 video_url = re.sub('speed=\d+', 'speed=', item.find('videoLink').text)
70 format_id = item.find('res').text
1dba4a21 71 fmt = {
3d6388e3 72 'url': self._proto_relative_url(video_url, 'http:'),
1dba4a21 73 'format_id': format_id,
74 }
75 m = re.search(r'^(\d+)', format_id)
76 if m:
77 fmt['height'] = int(m.group(1))
78 formats.append(fmt)
79 self._sort_formats(formats)
5f6a1245 80
1dba4a21 81 return {
82 'id': video_id,
83 'display_id': display_id,
1dba4a21 84 'title': title,
eb833b7f 85 'description': description,
1dba4a21 86 'thumbnail': thumbnail,
eb833b7f
S
87 'duration': duration,
88 'age_limit': age_limit,
89 'formats': formats,
1dba4a21 90 }