Add support for Eporner
[youtube-dl] / youtube_dl / extractor / eporner.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 EpornerIE(InfoExtractor):
10     _VALID_URL = r'http?://(?:www\.)?eporner\.com/hd-porn/(?P<id>\d+)/(?P<title_dash>[\w-]+)/?'
11     _TEST = {
12         'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
13         'md5': '3b427ae4b9d60619106de3185c2987cd',
14         'info_dict': {
15             'id': '95008',
16             'ext': 'flv',
17             'title': 'Infamous Tiffany Teen Strip Tease Video',
18             'duration': 194
19         }
20     }
21
22     def _real_extract(self, url):
23         mobj = re.match(self._VALID_URL, url)
24         video_id = mobj.group('id')
25         webpage = self._download_webpage(url, video_id)
26         title = self._html_search_regex(r'<title>(.*?) - EPORNER', webpage, 'title')
27
28         redirect_code = self._html_search_regex(r'<script type="text/javascript" src="/config5/'+str(video_id)+'/([a-f\d]+)/">', webpage, 'redirect_code')
29         redirect_url = 'http://www.eporner.com/config5/' + str(video_id) +'/'+ redirect_code
30         webpage2 = self._download_webpage(redirect_url, video_id)
31         video_url = self._html_search_regex(r'file: "(.*?)",', webpage2, 'video_url')
32
33         mobj = re.search(r'class="mbtim">(?P<minutes>\d+):(?P<seconds>\d+)</div>', webpage)
34         duration = int(mobj.group('minutes')) * 60 + int(mobj.group('seconds')) if mobj else None
35
36         mobj = re.search(r'id="cinemaviews">((?P<thousands>\d+),)?(?P<units>\d+)<small>views', webpage)
37         view_count = int(mobj.group('thousands')) * 1000 + int(mobj.group('units')) if mobj else None
38
39         return {
40             'id': video_id,
41             'url': video_url,
42             'title': title,
43             'duration': int_or_none(duration),
44             'view_count': int_or_none(view_count),
45         }