]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/pornhd.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / pornhd.py
CommitLineData
e299f6d2
PH
1from __future__ import unicode_literals
2
8e05c870 3import re
4b9cced1 4import json
8e05c870
MO
5
6from .common import InfoExtractor
842cca7d
S
7from ..utils import (
8 int_or_none,
9 js_to_json,
10 qualities,
842cca7d 11)
8e05c870 12
6f5dcd4e 13
8e05c870 14class PornHdIE(InfoExtractor):
5886b38d 15 _VALID_URL = r'https?://(?:www\.)?pornhd\.com/(?:[a-z]{2,4}/)?videos/(?P<id>\d+)(?:/(?P<display_id>.+))?'
8e05c870 16 _TEST = {
e299f6d2 17 'url': 'http://www.pornhd.com/videos/1962/sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
65a40ab8 18 'md5': '956b8ca569f7f4d8ec563e2c41598441',
e299f6d2 19 'info_dict': {
4b9cced1 20 'id': '1962',
842cca7d 21 'display_id': 'sierra-day-gets-his-cum-all-over-herself-hd-porn-video',
4b9cced1
S
22 'ext': 'mp4',
23 'title': 'Sierra loves doing laundry',
24 'description': 'md5:8ff0523848ac2b8f9b065ba781ccf294',
842cca7d
S
25 'thumbnail': 're:^https?://.*\.jpg',
26 'view_count': int,
4b9cced1 27 'age_limit': 18,
8e05c870
MO
28 }
29 }
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
4b9cced1 33 video_id = mobj.group('id')
842cca7d 34 display_id = mobj.group('display_id')
8e05c870 35
842cca7d 36 webpage = self._download_webpage(url, display_id or video_id)
8e05c870 37
ceff3fd8 38 title = self._html_search_regex(
1b381853
S
39 [r'<span[^>]+class=["\']video-name["\'][^>]*>([^<]+)',
40 r'<title>(.+?) - .*?[Pp]ornHD.*?</title>'], webpage, 'title')
4b9cced1
S
41 description = self._html_search_regex(
42 r'<div class="description">([^<]+)</div>', webpage, 'description', fatal=False)
43 view_count = int_or_none(self._html_search_regex(
ceff3fd8 44 r'(\d+) views\s*</span>', webpage, 'view count', fatal=False))
842cca7d
S
45 thumbnail = self._search_regex(
46 r"'poster'\s*:\s*'([^']+)'", webpage, 'thumbnail', fatal=False)
4b9cced1 47
807962f4
PH
48 quality = qualities(['sd', 'hd'])
49 sources = json.loads(js_to_json(self._search_regex(
f7a211dc
PH
50 r"(?s)'sources'\s*:\s*(\{.+?\})\s*\}[;,)]",
51 webpage, 'sources')))
807962f4 52 formats = []
f7a211dc
PH
53 for qname, video_url in sources.items():
54 if not video_url:
55 continue
56 formats.append({
57 'url': video_url,
58 'format_id': qname,
59 'quality': quality(qname),
60 })
4b9cced1 61 self._sort_formats(formats)
8e05c870
MO
62
63 return {
6f5dcd4e 64 'id': video_id,
842cca7d 65 'display_id': display_id,
4b9cced1
S
66 'title': title,
67 'description': description,
68 'thumbnail': thumbnail,
69 'view_count': view_count,
70 'formats': formats,
71 'age_limit': 18,
8e05c870 72 }