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 def _print_formats(self
, formats
):
21 """Print all available formats"""
22 print(u
'Available formats:')
23 print(u
'ext\t\tformat')
24 print(u
'---------------------------------')
25 for format
in formats
:
26 print(u
'%s\t\t%s' % (format
['ext'], format
['format']))
28 def _specific(self
, req_format
, formats
):
30 if x
["format"] == req_format
:
34 def _real_extract(self
, url
):
35 mobj
= re
.match(self
._VALID
_URL
, url
)
36 video_id
= mobj
.group('videoid')
38 req
= compat_urllib_request
.Request(url
)
39 req
.add_header('Cookie', 'age_verified=1')
40 webpage
= self
._download
_webpage
(req
, video_id
)
43 json_params
= self
._search
_regex
(r
'var currentVideo = new Video\((.*)\);', webpage
, u
'JSON parameters')
45 params
= json
.loads(json_params
)
47 raise ExtractorError(u
'Invalid JSON')
49 self
.report_extraction(video_id
)
51 video_title
= params
['title']
52 upload_date
= unified_strdate(params
['release_date_f'])
53 video_description
= params
['description']
54 video_uploader
= params
['submitted_by']
55 thumbnail
= params
['thumbnails'][0]['image']
57 raise ExtractorError('Missing JSON parameter: ' + sys
.exc_info()[1])
59 # Get all of the formats available
60 DOWNLOAD_LIST_RE
= r
'(?s)<ul class="downloadList">(?P<download_list>.*?)</ul>'
61 download_list_html
= self
._search
_regex
(DOWNLOAD_LIST_RE
,
62 webpage
, u
'download list').strip()
64 # Get all of the links from the page
65 LINK_RE
= r
'(?s)<a href="(?P<url>[^"]+)">'
66 links
= re
.findall(LINK_RE
, download_list_html
)
68 raise ExtractorError(u
'ERROR: no known formats available for video')
70 self
.to_screen(u
'Links found: %d' % len(links
))
75 # A link looks like this:
76 # 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
77 # A path looks like this:
78 # /201210/31/8004515/480p_370k_8004515/YouPorn%20-%20Nubile%20Films%20The%20Pillow%20Fight.mp4
79 video_url
= unescapeHTML( link
)
80 path
= compat_urllib_parse_urlparse( video_url
).path
81 extension
= os
.path
.splitext( path
)[1][1:]
82 format
= path
.split('/')[4].split('_')[:2]
85 format
= "-".join( format
)
86 # title = u'%s-%s-%s' % (video_title, size, bitrate)
91 'uploader': video_uploader
,
92 'upload_date': upload_date
,
96 'thumbnail': thumbnail
,
97 'description': video_description
100 if self
._downloader
.params
.get('listformats', None):
101 self
._print
_formats
(formats
)
104 req_format
= self
._downloader
.params
.get('format', None)
105 self
.to_screen(u
'Format: %s' % req_format
)
107 if req_format
is None or req_format
== 'best':
109 elif req_format
== 'worst':
111 elif req_format
in ('-1', 'all'):
114 format
= self
._specific
( req_format
, formats
)
116 raise ExtractorError(u
'Requested format not available')