]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pornhd.py
debian/control: Remove mplayer2 from recommends. (Closes: #841187)
[youtubedl] / youtube_dl / extractor / pornhd.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 int_or_none,
9 js_to_json,
10 )
11
12
13 class PornHdIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
15 _TESTS = [{
16 'url': 'http://www.pornhd.com/videos/9864/selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
17 'md5': 'c8b964b1f0a4b5f7f28ae3a5c9f86ad5',
18 'info_dict': {
19 'id': '9864',
20 'display_id': 'selfie-restroom-masturbation-fun-with-chubby-cutie-hd-porn-video',
21 'ext': 'mp4',
22 'title': 'Restroom selfie masturbation',
23 'description': 'md5:3748420395e03e31ac96857a8f125b2b',
24 'thumbnail': 're:^https?://.*\.jpg',
25 'view_count': int,
26 'age_limit': 18,
27 }
28 }, {
29 # removed video
30 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
31 'md5': '956b8ca569f7f4d8ec563e2c41598441',
32 'info_dict': {
33 'id': '1962',
34 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
35 'ext': 'mp4',
36 'title': 'Sierra loves doing laundry',
37 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
38 'thumbnail': 're:^https?://.*\.jpg',
39 'view_count': int,
40 'age_limit': 18,
41 },
42 'skip': 'Not available anymore',
43 }]
44
45 def _real_extract(self, url):
46 mobj = re.match(self._VALID_URL, url)
47 video_id = mobj.group('id')
48 display_id = mobj.group('display_id')
49
50 webpage = self._download_webpage(url, display_id or video_id)
51
52 title = self._html_search_regex(
53 [r'<span[^>]+class=["\']video-name["\'][^>]*>([^<]+)',
54 r'<title>(.+?) - .*?[Pp]ornHD.*?</title>'], webpage, 'title')
55
56 sources = self._parse_json(js_to_json(self._search_regex(
57 r"(?s)'sources'\s*:\s*(\{.+?\})\s*\}[;,)]",
58 webpage, 'sources', default='{}')), video_id)
59
60 if not sources:
61 message = self._html_search_regex(
62 r'(?s)<(div|p)[^>]+class="no-video"[^>]*>(?P<value>.+?)</\1',
63 webpage, 'error message', group='value')
64 raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
65
66 formats = []
67 for format_id, video_url in sources.items():
68 if not video_url:
69 continue
70 height = int_or_none(self._search_regex(
71 r'^(\d+)[pP]', format_id, 'height', default=None))
72 formats.append({
73 'url': video_url,
74 'format_id': format_id,
75 'height': height,
76 })
77 self._sort_formats(formats)
78
79 description = self._html_search_regex(
80 r'<(div|p)[^>]+class="description"[^>]*>(?P<value>[^<]+)</\1',
81 webpage, 'description', fatal=False, group='value')
82 view_count = int_or_none(self._html_search_regex(
83 r'(\d+) views\s*<', webpage, 'view count', fatal=False))
84 thumbnail = self._search_regex(
85 r"'poster'\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False)
86
87 return {
88 'id': video_id,
89 'display_id': display_id,
90 'title': title,
91 'description': description,
92 'thumbnail': thumbnail,
93 'view_count': view_count,
94 'formats': formats,
95 'age_limit': 18,
96 }