Merge branch 'tnaflix' of https://github.com/peugeot/youtube-dl into peugeot-tnaflix
[youtube-dl] / youtube_dl / extractor / tnaflix.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_duration,
8     str_to_int,
9 )
10
11 class TNAFlixIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?tnaflix\.com/(?P<cat_id>[\w-]+)/(?P<display_id>[\w-]+)/video(?P<id>\d+)'
13     _TEST = {
14         'url': 'http://www.tnaflix.com/porn-stars/Carmella-Decesare-striptease/video553878',
15         'md5': 'ecf3498417d09216374fc5907f9c6ec0',
16         'info_dict': {
17             'id': '553878',
18             'display_id': 'Carmella-Decesare-striptease',
19             'ext': 'mp4',
20             'title': 'Carmella Decesare - striptease',
21             'thumbnail': 're:https?://.*\.jpg$',
22             #'duration': 84,
23             'age_limit': 18,
24         }
25     }
26
27     def _real_extract(self, url):
28         mobj = re.match(self._VALID_URL, url)
29         video_id = mobj.group('id')
30         display_id = mobj.group('display_id')
31
32         webpage = self._download_webpage(url, display_id)
33
34         redir_url = self._html_search_regex(
35             r'flashvars.config = escape\("([^"]+)"', webpage, 'redirection URL')
36         redirection_webpage = self._download_webpage(redir_url, display_id)
37         sources = self._search_regex(
38             r'<quality>(.+)</quality>', redirection_webpage, 'sources', flags=re.MULTILINE|re.DOTALL)
39         
40         formats = []
41         for format_id, video_url in re.findall(r'<res>([^<]+)</res>\s*<videoLink>([^<]+)</videoLink>', sources, flags=re.MULTILINE|re.DOTALL):
42             fmt = {
43                 'url': video_url,
44                 'format_id': format_id,
45             }
46             m = re.search(r'^(\d+)', format_id)
47             if m:
48                 fmt['height'] = int(m.group(1))
49             formats.append(fmt)
50         self._sort_formats(formats)
51         
52         title = self._og_search_title(webpage)
53         
54         #duration = self._html_search_regex(r'<meta itemprop="duration" content="T(\d+)M(\d+)S"', webpage, 'duration')
55
56         thumbnail = self._html_search_regex(
57             r'<meta\s+itemprop="thumbnailUrl"\s+content="([^"]+)"',
58             webpage, 'thumbnail', fatal=False)
59
60         return {
61             'id': video_id,
62             'display_id': display_id,
63             'url': video_url,
64             'title': title,
65             'thumbnail': thumbnail,
66             #'duration': duration,
67             'age_limit': self._rta_search(webpage),
68         }