Merge branch 'anysex' of https://github.com/peugeot/youtube-dl into peugeot-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 from ..utils import int_or_none
8
9 class AnySexIE(InfoExtractor):
10     _VALID_URL = r'http?://(?:www\.)?anysex\.com/(?P<id>\d+)/?'
11     _TEST = {
12         'url': 'http://anysex.com/156592/',
13         'md5': '023e9fbb7f7987f5529a394c34ad3d3d',
14         'info_dict': {
15             'id': '156592',
16             'ext': 'mp4',
17             'title': 'Busty and sexy blondie in her bikini strips for you',
18             'duration': 270,
19         }
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         video_id = mobj.group('id')
25
26         webpage = self._download_webpage(url, video_id)
27         title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
28         video_url = self._html_search_regex(r'video_url: \'(.*?)\',', webpage, 'video_url')
29         thumbnail = self._html_search_regex(r'preview_url: \'(.*?)\',', webpage, 'thumbnail')
30
31         mobj = re.search(r'<b>Duration:</b> (?P<minutes>\d+):(?P<seconds>\d+)<', webpage)
32         duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
33
34         view_count = self._html_search_regex(r'<b>Views:</b> (\d+)', webpage, 'view count', fatal=False)
35
36         return {
37             'id': video_id,
38             'ext': 'mp4',
39             'url': video_url,
40             'title': title,
41             'duration': int_or_none(duration),
42             'view_count': int_or_none(view_count),
43         }