1 from __future__ import unicode_literals
9 from .common import InfoExtractor
10 from ..compat import (
11 compat_urllib_parse_urlparse,
12 compat_urllib_request,
24 class YouPornIE(InfoExtractor):
25 _VALID_URL = r'^(?P<proto>https?://)(?:www\.)?(?P<url>youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+))'
27 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
31 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
32 'description': 'Watch Sex Ed: Is It Safe To Masturbate Daily? at YouPorn.com - YouPorn is the biggest free porn tube site on the net!',
33 'uploader': 'Ask Dan And Jennifer',
34 'thumbnail': 'http://cdn5.image.youporn.phncdn.com/201012/17/505835/640x480/8/sex-ed-is-it-safe-to-masturbate-daily-8.jpg',
40 def _real_extract(self, url):
41 mobj = re.match(self._VALID_URL, url)
42 video_id = mobj.group('videoid')
43 url = mobj.group('proto') + 'www.' + mobj.group('url')
45 req = compat_urllib_request.Request(url)
46 req.add_header('Cookie', 'age_verified=1')
47 webpage = self._download_webpage(req, video_id)
48 age_limit = self._rta_search(webpage)
50 self.report_extraction(video_id)
51 video_title = self._html_search_regex(r'page_params.video_title = \'(.+?)\';', webpage, 'video URL', fatal=False)
52 video_description = self._html_search_meta('description', webpage, 'video DESC', fatal=False)
53 video_thumbnail = self._html_search_regex(r'page_params.imageurl\t=\t"(.+?)";', webpage, 'video THUMB', fatal=False)
54 video_uploader = self._html_search_regex(r"<div class=\'videoInfoBy\'>By:</div>\n<a href=\"[^>]+\">(.+?)</a>", webpage, 'video UPLOADER', fatal=False)
55 video_date = self._html_search_regex(r"<div class='videoInfoTime'>\n<i class='icon-clock'></i> (.+?)\n</div>", webpage, 'video DATE', fatal=False)
56 video_date = datetime.datetime.strptime(video_date, '%B %d, %Y').strftime('%Y%m%d')
58 # Get all of the links from the page
59 DOWNLOAD_LIST_RE = r'(?s)sources: {\n(?P<download_list>.*?)}'
60 download_list_html = self._search_regex(DOWNLOAD_LIST_RE, webpage, 'download list').strip()
61 LINK_RE = r': \'(.+?)\','
62 links = re.findall(LINK_RE, download_list_html)
64 # Get all encrypted links
65 encrypted_links = re.findall(r'page_params.encryptedQuality[0-9]{3,4}URL\s=\s\'([a-zA-Z0-9+/]+={0,2})\';', webpage)
66 for encrypted_link in encrypted_links:
67 link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
68 # it's unclear if encryted links still differ from normal ones, so only include in links array if it's unique
74 # A link looks like this:
75 # http://cdn2b.public.youporn.phncdn.com/201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4?rs=200&ri=2500&s=1445599900&e=1445773500&h=5345d19ce9944ec52eb167abf24af248
76 # A path looks like this:
77 # 201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
78 video_url = unescapeHTML(link)
79 path = compat_urllib_parse_urlparse(video_url).path
80 format_parts = path.split('/')[4].split('_')[:2]
82 dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0]
84 resolution = format_parts[0]
85 height = int(resolution[:-len('p')])
86 bitrate = int(format_parts[1][:-len('k')])
87 format = '-'.join(format_parts) + '-' + dn
95 'resolution': resolution,
98 self._sort_formats(formats)
101 raise ExtractorError('ERROR: no known formats available for video')
105 'title': video_title,
106 'description': video_description,
107 'thumbnail': video_thumbnail,
108 'uploader': video_uploader,
110 'age_limit': age_limit,