[Rte] Improve extractor
[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     IE_DESC = 'Sexy Karma and Watch Indian Porn'
16     _VALID_URL = r'https?://(?:www\.)?(?:sexykarma\.com|watchindianporn\.net)/(?:[^/]+/)*video/(?P<display_id>[^/]+)-(?P<id>[a-zA-Z0-9]+)\.html'
17     _TESTS = [{
18         'url': 'http://www.sexykarma.com/gonewild/video/taking-a-quick-pee-yHI70cOyIHt.html',
19         'md5': 'b9798e7d1ef1765116a8f516c8091dbd',
20         'info_dict': {
21             'id': 'yHI70cOyIHt',
22             'display_id': 'taking-a-quick-pee',
23             'ext': 'mp4',
24             'title': 'Taking a quick pee.',
25             'thumbnail': 're:^https?://.*\.jpg$',
26             'uploader': 'wildginger7',
27             'upload_date': '20141007',
28             'duration': 22,
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             'thumbnail': 're:^https?://.*\.jpg$',
42             'uploader': 'banffite',
43             'upload_date': '20141013',
44             'duration': 16,
45             'view_count': int,
46             'comment_count': int,
47             'categories': list,
48         }
49     }, {
50         'url': 'http://www.watchindianporn.net/video/desi-dancer-namrata-stripping-completely-nude-and-dancing-on-a-hot-number-dW2mtctxJfs.html',
51         'md5': '9afb80675550406ed9a63ac2819ef69d',
52         'info_dict': {
53             'id': 'dW2mtctxJfs',
54             'display_id': 'desi-dancer-namrata-stripping-completely-nude-and-dancing-on-a-hot-number',
55             'ext': 'mp4',
56             'title': 'Desi dancer namrata stripping completely nude and dancing on a hot number',
57             'thumbnail': 're:^https?://.*\.jpg$',
58             'uploader': 'Don',
59             'upload_date': '20140213',
60             'duration': 83,
61             'view_count': int,
62             'comment_count': int,
63             'categories': list,
64         }
65     }]
66
67     def _real_extract(self, url):
68         mobj = re.match(self._VALID_URL, url)
69         video_id = mobj.group('id')
70         display_id = mobj.group('display_id')
71
72         webpage = self._download_webpage(url, display_id)
73
74         video_url = self._html_search_regex(
75             r"url: escape\('([^']+)'\)", webpage, 'url')
76
77         title = self._html_search_regex(
78             r'<h2 class="he2"><span>(.*?)</span>',
79             webpage, 'title')
80         thumbnail = self._html_search_regex(
81             r'<span id="container"><img\s+src="([^"]+)"',
82             webpage, 'thumbnail', fatal=False)
83
84         uploader = self._html_search_regex(
85             r'class="aupa">\s*(.*?)</a>',
86             webpage, 'uploader')
87         upload_date = unified_strdate(self._html_search_regex(
88             r'Added: <strong>(.+?)</strong>', webpage, 'upload date', fatal=False))
89
90         duration = parse_duration(self._search_regex(
91             r'<td>Time:\s*</td>\s*<td align="right"><span>\s*(.+?)\s*</span>',
92             webpage, 'duration', fatal=False))
93
94         view_count = int_or_none(self._search_regex(
95             r'<td>Views:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
96             webpage, 'view count', fatal=False))
97         comment_count = int_or_none(self._search_regex(
98             r'<td>Comments:\s*</td>\s*<td align="right"><span>\s*(\d+)\s*</span>',
99             webpage, 'comment count', fatal=False))
100
101         categories = re.findall(
102             r'<a href="[^"]+/search/video/desi"><span>([^<]+)</span></a>',
103             webpage)
104
105         return {
106             'id': video_id,
107             'display_id': display_id,
108             'url': video_url,
109             'title': title,
110             'thumbnail': thumbnail,
111             'uploader': uploader,
112             'upload_date': upload_date,
113             'duration': duration,
114             'view_count': view_count,
115             'comment_count': comment_count,
116             'categories': categories,
117         }