]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pornhd.py
718fe9aba5fc710ee5efc47c2bbae2b02fc3c117
[youtubedl] / youtube_dl / extractor / pornhd.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import int_or_none
8
9
10 class PornHdIE(InfoExtractor):
11 _VALID_URL = r'http://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)'
12 _TEST = {
13 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
14 'md5': '956b8ca569f7f4d8ec563e2c41598441',
15 'info_dict': {
16 'id': '1962',
17 'ext': 'mp4',
18 'title': 'Sierra loves doing laundry',
19 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
20 'age_limit': 18,
21 }
22 }
23
24 def _real_extract(self, url):
25 mobj = re.match(self._VALID_URL, url)
26 video_id = mobj.group('id')
27
28 webpage = self._download_webpage(url, video_id)
29
30 title = self._og_search_title(webpage)
31 TITLE_SUFFIX = ' porn HD Video | PornHD.com '
32 if title.endswith(TITLE_SUFFIX):
33 title = title[:-len(TITLE_SUFFIX)]
34
35 description = self._html_search_regex(
36 r'<div class="description">([^<]+)</div>', webpage, 'description', fatal=False)
37 view_count = int_or_none(self._html_search_regex(
38 r'(\d+) views </span>', webpage, 'view count', fatal=False))
39
40 formats = [
41 {
42 'url': format_url,
43 'ext': format.lower(),
44 'format_id': '%s-%s' % (format.lower(), quality.lower()),
45 'quality': 1 if quality.lower() == 'high' else 0,
46 } for format, quality, format_url in re.findall(
47 r'var __video([\da-zA-Z]+?)(Low|High)StreamUrl = \'(http://.+?)\?noProxy=1\'', webpage)
48 ]
49
50 mobj = re.search(r'flashVars = (?P<flashvars>{.+?});', webpage)
51 if mobj:
52 flashvars = json.loads(mobj.group('flashvars'))
53 formats.extend([
54 {
55 'url': flashvars['hashlink'].replace('?noProxy=1', ''),
56 'ext': 'flv',
57 'format_id': 'flv-low',
58 'quality': 0,
59 },
60 {
61 'url': flashvars['hd'].replace('?noProxy=1', ''),
62 'ext': 'flv',
63 'format_id': 'flv-high',
64 'quality': 1,
65 }
66 ])
67 thumbnail = flashvars['urlWallpaper']
68 else:
69 thumbnail = self._og_search_thumbnail(webpage)
70
71 self._sort_formats(formats)
72
73 return {
74 'id': video_id,
75 'title': title,
76 'description': description,
77 'thumbnail': thumbnail,
78 'view_count': view_count,
79 'formats': formats,
80 'age_limit': 18,
81 }