6 from .common
import InfoExtractor
8 compat_urllib_parse_urlparse
,
17 class YouPornIE(InfoExtractor
):
18 _VALID_URL
= r
'^(?:https?://)?(?:\w+\.)?youporn\.com/watch/(?P<videoid>[0-9]+)/(?P<title>[^/]+)'
20 u
'url': u
'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
21 u
'file': u
'505835.mp4',
22 u
'md5': u
'c37ddbaaa39058c76a7e86c6813423c1',
24 u
"upload_date": u
"20101221",
25 u
"description": u
"Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?",
26 u
"uploader": u
"Ask Dan And Jennifer",
27 u
"title": u
"Sex Ed: Is It Safe To Masturbate Daily?"
31 def _print_formats(self
, formats
):
32 """Print all available formats"""
33 print(u
'Available formats:')
34 print(u
'ext\t\tformat')
35 print(u
'---------------------------------')
36 for format
in formats
:
37 print(u
'%s\t\t%s' % (format
['ext'], format
['format']))
39 def _specific(self
, req_format
, formats
):
41 if x
["format"] == req_format
:
45 def _real_extract(self
, url
):
46 mobj
= re
.match(self
._VALID
_URL
, url
)
47 video_id
= mobj
.group('videoid')
49 req
= compat_urllib_request
.Request(url
)
50 req
.add_header('Cookie', 'age_verified=1')
51 webpage
= self
._download
_webpage
(req
, video_id
)
54 json_params
= self
._search
_regex
(r
'var currentVideo = new Video\((.*)\);', webpage
, u
'JSON parameters')
56 params
= json
.loads(json_params
)
58 raise ExtractorError(u
'Invalid JSON')
60 self
.report_extraction(video_id
)
62 video_title
= params
['title']
63 upload_date
= unified_strdate(params
['release_date_f'])
64 video_description
= params
['description']
65 video_uploader
= params
['submitted_by']
66 thumbnail
= params
['thumbnails'][0]['image']
68 raise ExtractorError('Missing JSON parameter: ' + sys
.exc_info()[1])
70 # Get all of the formats available
71 DOWNLOAD_LIST_RE
= r
'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
72 download_list_html
= self
._search
_regex
(DOWNLOAD_LIST_RE
,
73 webpage
, u
'download list').strip()
75 # Get all of the links from the page
76 LINK_RE
= r
'(?s)<a href="(?P<url>[^"]+)">'
77 links
= re
.findall(LINK_RE
, download_list_html
)
79 raise ExtractorError(u
'ERROR: no known formats available for video')
81 self
.to_screen(u
'Links found: %d' % len(links
))
86 # A link looks like this:
87 # http://cdn1.download.youporn.phncdn.com/201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4?nvb=20121113051249&nva=20121114051249&ir=1200&sr=1200&hash=014b882080310e95fb6a0
88 # A path looks like this:
89 # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
90 video_url
= unescapeHTML( link
)
91 path
= compat_urllib_parse_urlparse( video_url
).path
92 extension
= os
.path
.splitext( path
)[1][1:]
93 format
= path
.split('/')[4].split('_')[:2]
96 format
= "-".join( format
)
97 # title = u'%s-%s-%s' % (video_title, size, bitrate)
102 'uploader': video_uploader
,
103 'upload_date': upload_date
,
104 'title': video_title
,
107 'thumbnail': thumbnail
,
108 'description': video_description
111 if self
._downloader
.params
.get('listformats', None):
112 self
._print
_formats
(formats
)
115 req_format
= self
._downloader
.params
.get('format', None)
116 self
.to_screen(u
'Format: %s' % req_format
)
118 if req_format
is None or req_format
== 'best':
120 elif req_format
== 'worst':
122 elif req_format
in ('-1', 'all'):
125 format
= self
._specific
( req_format
, formats
)
127 raise ExtractorError(u
'Requested format not available')