Merge remote-tracking branch 'peugeot/eporner'
[youtube-dl] / youtube_dl / extractor / sunporno.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     int_or_none,
9     qualities,
10     determine_ext,
11 )
12
13
14 class SunPornoIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?sunporno\.com/videos/(?P<id>\d+)'
16     _TEST = {
17         'url': 'http://www.sunporno.com/videos/807778/',
18         'md5': '6457d3c165fd6de062b99ef6c2ff4c86',
19         'info_dict': {
20             'id': '807778',
21             'ext': 'flv',
22             'title': 'md5:0a400058e8105d39e35c35e7c5184164',
23             'description': 'md5:a31241990e1bd3a64e72ae99afb325fb',
24             'thumbnail': 're:^https?://.*\.jpg$',
25             'duration': 302,
26         }
27     }
28
29     def _real_extract(self, url):
30         mobj = re.match(self._VALID_URL, url)
31         video_id = mobj.group('id')
32
33         webpage = self._download_webpage(url, video_id)
34
35         title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'title')
36         description = self._html_search_meta('description', webpage, 'description')
37         thumbnail = self._html_search_regex(
38             r'poster="([^"]+)"', webpage, 'thumbnail', fatal=False)
39
40         duration = parse_duration(self._search_regex(
41             r'<span>Duration: (\d+:\d+)</span>', webpage, 'duration', fatal=False))
42
43         view_count = int_or_none(self._html_search_regex(
44             r'<span class="views">(\d+)</span>', webpage, 'view count', fatal=False))
45         comment_count = int_or_none(self._html_search_regex(
46             r'(\d+)</b> Comments?', webpage, 'comment count', fatal=False))
47
48         formats = []
49         quality = qualities(['mp4', 'flv'])
50         for video_url in re.findall(r'<source src="([^"]+)"', webpage):
51             video_ext = determine_ext(video_url)
52             formats.append({
53                 'url': video_url,
54                 'format_id': video_ext,
55                 'quality': quality(video_ext),
56             })
57         self._sort_formats(formats)
58
59         return {
60             'id': video_id,
61             'title': title,
62             'description': description,
63             'thumbnail': thumbnail,
64             'duration': duration,
65             'view_count': view_count,
66             'comment_count': comment_count,
67             'formats': formats,
68         }