Add support for AnySex
[youtube-dl] / youtube_dl / extractor / anysex.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8 class AnySexIE(InfoExtractor):
9     _VALID_URL = r'http?://(?:www\.)?anysex\.com/(?P<id>\d+)/?'
10     _TEST = {
11         'url': 'http://anysex.com/156592/',
12         'md5': '023e9fbb7f7987f5529a394c34ad3d3d',
13         'info_dict': {
14             'id': '156592',
15             'ext': 'mp4',
16             'title': 'Busty and sexy blondie in her bikini strips for you',
17             'duration': 270
18         }
19     }
20
21     def _real_extract(self, url):
22         mobj = re.match(self._VALID_URL, url)
23         video_id = mobj.group('id')
24
25         webpage = self._download_webpage(url, video_id)
26         title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
27         video_url = self._html_search_regex(r'video_url: \'(.*?)\',', webpage, 'video_url')
28         thumbnail = self._html_search_regex(r'preview_url: \'(.*?)\',', webpage, 'thumbnail')
29
30         mobj = re.search(r'<b>Duration:</b> (?P<minutes>\d+):(?P<seconds>\d+)<', webpage)
31         duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
32
33         view_count = self._html_search_regex(r'<b>Views:</b> (\d+)', webpage, 'view count', fatal=False)
34
35         return {
36             'id': video_id,
37             'ext': 'mp4',
38             'url': video_url,
39             'title': title,
40             'duration': duration,
41             'view_count': view_count
42         }