[xnxx] fix url regex
[youtube-dl] / youtube_dl / extractor / xnxx.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse_unquote
6
7
8 class XNXXIE(InfoExtractor):
9     _VALID_URL = r'^https?://(?:video|www)\.xnxx\.com/video-?(?P<id>[0-9a-z]+)/(.*)'
10     _TESTS = [{
11         'url': 'http://www.xnxx.com/video-6gqggeb/hd_star-581_sam',
12         'md5': '6a2a6aff3f10467d94e572edb7b7deb6',
13         'info_dict': {
14             'id': '6gqggeb',
15             'ext': 'flv',
16             'title': 'HD STAR-581 sam',
17             'age_limit': 18,
18         },
19     }, {
20         'url': 'http://video.xnxx.com/video1135332/lida_naked_funny_actress_5_',
21         'only_matching': True,
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         video_url = self._search_regex(r'flv_url=(.*?)&amp;',
29                                        webpage, 'video URL')
30         video_url = compat_urllib_parse_unquote(video_url)
31
32         video_title = self._html_search_regex(r'<title>(.*?)\s+-\s+XNXX.COM',
33                                               webpage, 'title')
34
35         video_thumbnail = self._search_regex(r'url_bigthumb=(.*?)&amp;',
36                                              webpage, 'thumbnail', fatal=False)
37
38         return {
39             'id': video_id,
40             'url': video_url,
41             'title': video_title,
42             'ext': 'flv',
43             'thumbnail': video_thumbnail,
44             'age_limit': 18,
45         }