Merge branch 'CkuT-sexykarma'
[youtube-dl] / youtube_dl / extractor / sexykarma.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 (
8     unified_strdate,
9     parse_duration,
10     int_or_none,
11 )
12
13
14 class SexyKarmaIE(InfoExtractor):
15     _VALID_URL = r'https?://(?:www\.)?sexykarma\.com/gonewild/video/(?P<display_id>[^/]+)-(?P<id>[a-zA-Z0-9]+)\.html'
16     _TESTS = [{
17         'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html',
18         'md5': 'b9798e7d1ef1765116a8f516c8091dbd',
19         'info_dict': {
20             'id': 'yHI70cOyIHt',
21             'display_id': 'taking-a-quick-pee',
22             'ext': 'mp4',
23             'title': 'Taking a quick pee.',
24             'description': '',
25             'thumbnail': 're:^https?://.*\.jpg$',
26             'uploader': 'wildginger7',
27             'upload_date': '20141007',
28             'duration': 81,
29             'view_count': int,
30             'comment_count': int,
31             'categories': list,
32         }
33     }, {
34         'url': 'http://www.sexykarma.com/gonewild/video/pot-pixie-tribute-8Id6EZPbuHf.html',
35         'md5': 'dd216c68d29b49b12842b9babe762a5d',
36         'info_dict': {
37             'id': '8Id6EZPbuHf',
38             'display_id': 'pot-pixie-tribute',
39             'ext': 'mp4',
40             'title': 'pot_pixie tribute',
41             'description': 'tribute',
42             'thumbnail': 're:^https?://.*\.jpg$',
43             'uploader': 'banffite',
44             'upload_date': '20141013',
45             'duration': 16,
46             'view_count': int,
47             'comment_count': int,
48             'categories': list,
49         }
50     }]
51
52     def _real_extract(self, url):
53         mobj = re.match(self._VALID_URL, url)
54         video_id = mobj.group('id')
55         display_id = mobj.group('display_id')
56
57         webpage = self._download_webpage(url, display_id)
58
59         video_url = self._html_search_regex(
60             r'<p>Save this video to your computer: </p><p><a href="([^"]+)"',
61             webpage, 'url')
62
63         title = self._html_search_regex(
64             r'<h2 class="he2"><span>(.*?)</span>',
65             webpage, 'title')
66         description = self._html_search_meta(
67             'description', webpage, 'description', fatal=False, default='')
68         thumbnail = self._html_search_regex(
69             r'<span id="container"><img\s+src="([^"]+)"',
70             webpage, 'thumbnail', fatal=False)
71
72         uploader = self._html_search_regex(
73             r'class="aupa">\s*(.*?)</a>',
74             webpage, 'uploader')
75         upload_date = unified_strdate(self._html_search_regex(
76             r'Added: <strong>(.+?)</strong>', webpage, 'upload date', fatal=False))
77
78         duration = parse_duration(self._search_regex(
79             r'<td>Time:\s*</td>\s*<td align="right"><span>\s*(.+?)\s*</span>',
80             webpage, 'duration', fatal=False))
81
82         view_count = int_or_none(self._search_regex(
83             r'<td>Views:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
84             webpage, 'view count', fatal=False))
85         comment_count = int_or_none(self._search_regex(
86             r'<td>Comments:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
87             webpage, 'comment count', fatal=False))
88
89         categories = self._html_search_meta(
90             'keywords', webpage, 'categories',
91             fatal=False, default='').split(',')
92
93         return {
94             'id': video_id,
95             'display_id': display_id,
96             'url': video_url,
97             'title': title,
98             'description': description,
99             'thumbnail': thumbnail,
100             'uploader': uploader,
101             'upload_date': upload_date,
102             'duration': duration,
103             'view_count': view_count,
104             'comment_count': comment_count,
105             'categories': categories,
106         }