2014-03-21 00:19:54 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
2013-06-23 22:12:14 +02:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import sys
|
2015-10-17 19:22:47 +02:00
|
|
|
import datetime
|
2013-06-23 22:12:14 +02:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2014-12-13 12:24:42 +01:00
|
|
|
from ..compat import (
|
2013-06-23 22:12:14 +02:00
|
|
|
compat_urllib_parse_urlparse,
|
|
|
|
compat_urllib_request,
|
2014-12-13 12:24:42 +01:00
|
|
|
)
|
|
|
|
from ..utils import (
|
2013-06-23 22:12:14 +02:00
|
|
|
ExtractorError,
|
|
|
|
unescapeHTML,
|
|
|
|
unified_strdate,
|
|
|
|
)
|
2013-08-09 18:37:33 +02:00
|
|
|
from ..aes import (
|
|
|
|
aes_decrypt_text
|
|
|
|
)
|
2013-06-23 22:12:14 +02:00
|
|
|
|
2013-12-26 18:37:12 +01:00
|
|
|
|
2013-06-23 22:12:14 +02:00
|
|
|
class YouPornIE(InfoExtractor):
|
2014-03-21 00:19:54 +01:00
|
|
|
_VALID_URL = r'^(?P<proto>https?://)(?:www\.)?(?P<url>youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+))'
|
2013-06-27 20:46:46 +02:00
|
|
|
_TEST = {
|
2014-03-21 00:19:54 +01:00
|
|
|
'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '505835',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
|
2015-10-17 19:22:47 +02:00
|
|
|
'description': 'Watch Sex Ed: Is It Safe To Masturbate Daily? at YouPorn.com - YouPorn is the biggest free porn tube site on the net!',
|
|
|
|
'uploader': 'Ask Dan And Jennifer',
|
|
|
|
'thumbnail': 'http://cdn5.image.youporn.phncdn.com/201012/17/505835/640x480/8/sex-ed-is-it-safe-to-masturbate-daily-8.jpg',
|
|
|
|
'date': '20101221',
|
2014-03-21 00:19:54 +01:00
|
|
|
'age_limit': 18,
|
2013-06-27 20:46:46 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 22:12:14 +02:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
video_id = mobj.group('videoid')
|
2014-03-21 00:19:54 +01:00
|
|
|
url = mobj.group('proto') + 'www.' + mobj.group('url')
|
2013-06-23 22:12:14 +02:00
|
|
|
|
|
|
|
req = compat_urllib_request.Request(url)
|
|
|
|
req.add_header('Cookie', 'age_verified=1')
|
|
|
|
webpage = self._download_webpage(req, video_id)
|
2013-10-06 06:06:30 +02:00
|
|
|
age_limit = self._rta_search(webpage)
|
2013-06-23 22:12:14 +02:00
|
|
|
|
|
|
|
self.report_extraction(video_id)
|
2015-10-17 19:22:47 +02:00
|
|
|
video_title = self._html_search_regex(r'page_params.video_title = \'(.+?)\';', webpage, 'video URL', fatal=False)
|
|
|
|
video_description = self._html_search_meta('description', webpage, 'video DESC', fatal=False)
|
|
|
|
video_thumbnail = self._html_search_regex(r'page_params.imageurl\t=\t"(.+?)";', webpage, 'video THUMB', fatal=False)
|
|
|
|
video_uploader = self._html_search_regex(r"<div class=\'videoInfoBy\'>By:</div>\n<a href=\"[^>]+\">(.+?)</a>", webpage, 'video UPLOADER', fatal=False)
|
|
|
|
video_date = self._html_search_regex(r"<div class='videoInfoTime'>\n<i class='icon-clock'></i> (.+?)\n</div>", webpage, 'video DATE', fatal=False)
|
|
|
|
video_date = datetime.datetime.strptime(video_date, '%B %d, %Y').strftime('%Y%m%d')
|
2013-06-23 22:12:14 +02:00
|
|
|
|
2013-10-26 21:57:10 +02:00
|
|
|
# Get all of the links from the page
|
2015-10-17 19:22:47 +02:00
|
|
|
DOWNLOAD_LIST_RE = r'(?s)sources: {\n(?P<download_list>.*?)}'
|
|
|
|
download_list_html = self._search_regex(DOWNLOAD_LIST_RE, webpage, 'download list').strip()
|
|
|
|
LINK_RE = r': \'(.+?)\','
|
2013-06-23 22:12:14 +02:00
|
|
|
links = re.findall(LINK_RE, download_list_html)
|
2013-10-26 21:57:10 +02:00
|
|
|
|
|
|
|
# Get all encrypted links
|
2015-10-17 19:22:47 +02:00
|
|
|
encrypted_links = re.findall(r'page_params.encryptedQuality[0-9]{3,4}URL\s=\s\'([a-zA-Z0-9+/]+={0,2})\';', webpage)
|
2013-10-26 21:57:10 +02:00
|
|
|
for encrypted_link in encrypted_links:
|
|
|
|
link = aes_decrypt_text(encrypted_link, video_title, 32).decode('utf-8')
|
2015-10-17 19:22:47 +02:00
|
|
|
# it's unclear if encryted links still differ from normal ones, so only include in links array if it's unique
|
|
|
|
if link not in links:
|
|
|
|
links.append(link)
|
2014-11-23 20:41:03 +01:00
|
|
|
|
2013-06-23 22:12:14 +02:00
|
|
|
formats = []
|
|
|
|
for link in links:
|
|
|
|
# A link looks like this:
|
2015-10-17 19:22:47 +02:00
|
|
|
# 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
|
2013-06-23 22:12:14 +02:00
|
|
|
# A path looks like this:
|
2015-10-17 19:22:47 +02:00
|
|
|
# 201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
|
2013-11-03 14:03:17 +01:00
|
|
|
video_url = unescapeHTML(link)
|
|
|
|
path = compat_urllib_parse_urlparse(video_url).path
|
2013-12-26 18:37:12 +01:00
|
|
|
format_parts = path.split('/')[4].split('_')[:2]
|
2013-10-26 21:57:10 +02:00
|
|
|
|
2013-12-26 18:37:12 +01:00
|
|
|
dn = compat_urllib_parse_urlparse(video_url).netloc.partition('.')[0]
|
|
|
|
|
|
|
|
resolution = format_parts[0]
|
|
|
|
height = int(resolution[:-len('p')])
|
|
|
|
bitrate = int(format_parts[1][:-len('k')])
|
2014-03-21 00:19:54 +01:00
|
|
|
format = '-'.join(format_parts) + '-' + dn
|
2013-06-23 22:12:14 +02:00
|
|
|
|
|
|
|
formats.append({
|
|
|
|
'url': video_url,
|
|
|
|
'format': format,
|
2013-10-26 21:57:10 +02:00
|
|
|
'format_id': format,
|
2013-12-26 18:37:12 +01:00
|
|
|
'height': height,
|
|
|
|
'tbr': bitrate,
|
|
|
|
'resolution': resolution,
|
2013-06-23 22:12:14 +02:00
|
|
|
})
|
|
|
|
|
2013-12-26 18:37:12 +01:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
if not formats:
|
2014-11-26 13:06:02 +01:00
|
|
|
raise ExtractorError('ERROR: no known formats available for video')
|
2014-11-23 20:41:03 +01:00
|
|
|
|
2013-10-26 21:57:10 +02:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': video_title,
|
|
|
|
'description': video_description,
|
2015-10-17 19:22:47 +02:00
|
|
|
'thumbnail': video_thumbnail,
|
|
|
|
'uploader': video_uploader,
|
|
|
|
'date': video_date,
|
2013-10-26 21:57:10 +02:00
|
|
|
'age_limit': age_limit,
|
|
|
|
'formats': formats,
|
|
|
|
}
|