]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/youporn.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
14 from ..aes
import aes_decrypt_text
17 class YouPornIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?youporn\.com/watch/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
20 'url': 'http://www.youporn.com/watch/505835/sex-ed-is-it-safe-to-masturbate-daily/',
21 'md5': '3744d24c50438cf5b6f6d59feb5055c2',
24 'display_id': 'sex-ed-is-it-safe-to-masturbate-daily',
26 'title': 'Sex Ed: Is It Safe To Masturbate Daily?',
27 'description': 'Love & Sex Answers: http://bit.ly/DanAndJenn -- Is It Unhealthy To Masturbate Daily?',
28 'thumbnail': r
're:^https?://.*\.jpg$',
29 'uploader': 'Ask Dan And Jennifer',
30 'upload_date': '20101217',
31 'average_rating': int,
40 'url': 'http://www.youporn.com/watch/561726/big-tits-awesome-brunette-on-amazing-webcam-show/?from=related3&al=2&from_id=561726&pos=4',
43 'display_id': 'big-tits-awesome-brunette-on-amazing-webcam-show',
45 'title': 'Big Tits Awesome Brunette On amazing webcam show',
46 'description': 'http://sweetlivegirls.com Big Tits Awesome Brunette On amazing webcam show.mp4',
47 'thumbnail': r
're:^https?://.*\.jpg$',
48 'uploader': 'Unknown',
49 'upload_date': '20110418',
50 'average_rating': int,
58 'skip_download': True,
62 def _real_extract(self
, url
):
63 mobj
= re
.match(self
._VALID
_URL
, url
)
64 video_id
= mobj
.group('id')
65 display_id
= mobj
.group('display_id')
67 request
= sanitized_Request(url
)
68 request
.add_header('Cookie', 'age_verified=1')
69 webpage
= self
._download
_webpage
(request
, display_id
)
71 title
= self
._html
_search
_regex
(
72 r
'(?s)<div[^>]+class=["\']watchVideoTitle
[^
>]+>(.+?
)</div
>',
73 webpage, 'title
', default=None) or self._og_search_title(
74 webpage, default=None) or self._html_search_meta(
75 'title
', webpage, fatal=True)
80 definitions = self._parse_json(
82 r'mediaDefinition\s
*=\s
*(\
[.+?\
]);', webpage,
83 'media definitions
', default='[]'),
84 video_id, fatal=False)
86 for definition in definitions:
87 if not isinstance(definition, dict):
89 video_url = url_or_none(definition.get('videoUrl
'))
91 links.append(video_url)
93 # Fallback #1, this also contains extra low quality 180p format
94 for _, link in re.findall(r'<a
[^
>]+href
=(["\'])(http.+?)\1[^>]+title=["\']Download
[Vv
]ideo
', webpage):
97 # Fallback #2 (unavailable as at 22.06.2017)
98 sources = self._search_regex(
99 r'(?s
)sources\s
*:\s
*({.+?
})', webpage, 'sources
', default=None)
101 for _, link in re.findall(r'[^
:]+\s
*:\s
*(["\'])(http.+?)\1', sources):
104 # Fallback #3 (unavailable as at 22.06.2017)
105 for _, link in re.findall(
106 r'(?:videoSrc|videoIpadUrl|html5PlayerSrc)\s*[:=]\s*(["\'])(http
.+?
)\
1', webpage):
109 # Fallback #4, encrypted links (unavailable as at 22.06.2017)
110 for _, encrypted_link in re.findall(
111 r'encryptedQuality\d
{3,4}URL\s
*=\s
*(["\'])([\da-zA-Z+/=]+)\1', webpage):
112 links.append(aes_decrypt_text(encrypted_link, title, 32).decode('utf-8'))
115 for video_url in set(unescapeHTML(link) for link in links):
119 # Video URL's path looks like this:
120 # /201012/17/505835/720p_1500k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
121 # /201012/17/505835/vl_240p_240k_505835/YouPorn%20-%20Sex%20Ed%20Is%20It%20Safe%20To%20Masturbate%20Daily.mp4
122 # We will benefit from it by extracting some metadata
123 mobj = re.search(r'(?P<height>\d{3,4})[pP]_(?P<bitrate>\d+)[kK]_\d+/', video_url)
125 height = int(mobj.group('height'))
126 bitrate = int(mobj.group('bitrate'))
128 'format_id': '%dp-%dk' % (height, bitrate),
133 self._sort_formats(formats)
135 description = self._html_search_regex(
136 r'(?s)<div[^>]+\bid=["\']description
["\'][^>]*>(.+?)</div>',
137 webpage, 'description',
138 default=None) or self._og_search_description(
139 webpage, default=None)
140 thumbnail = self._search_regex(
141 r'(?:imageurl\s*=|poster\s*:)\s*(["\'])(?P
<thumbnail
>.+?
)\
1',
142 webpage, 'thumbnail
', fatal=False, group='thumbnail
')
144 uploader = self._html_search_regex(
145 r'(?s
)<div
[^
>]+class=["\']submitByLink["\'][^
>]*>(.+?
)</div
>',
146 webpage, 'uploader
', fatal=False)
147 upload_date = unified_strdate(self._html_search_regex(
148 [r'Date\s
+[Aa
]dded
:\s
*<span
>([^
<]+)',
149 r'(?s
)<div
[^
>]+class=["\']videoInfo(?:Date|Time)["\'][^
>]*>(.+?
)</div
>'],
150 webpage, 'upload date
', fatal=False))
152 age_limit = self._rta_search(webpage)
154 average_rating = int_or_none(self._search_regex(
155 r'<div
[^
>]+class=["\']videoRatingPercentage["\'][^
>]*>(\d
+)%</div
>',
156 webpage, 'average rating
', fatal=False))
158 view_count = str_to_int(self._search_regex(
159 r'(?s
)<div
[^
>]+class=(["\']).*?\bvideoInfoViews\b.*?\1[^>]*>.*?(?P<count>[\d,.]+)<',
160 webpage, 'view count', fatal=False, group='count'))
161 comment_count = str_to_int(self._search_regex(
162 r'>All [Cc]omments? \(([\d,.]+)\)',
163 webpage, 'comment count', fatal=False))
165 def extract_tag_box(regex, title):
166 tag_box = self._search_regex(regex, webpage, title, default=None)
169 return re.findall(r'<a[^>]+href=[^>]+>([^<]+)', tag_box)
171 categories = extract_tag_box(
172 r'(?s)Categories:.*?</[^>]+>(.+?)</div>', 'categories')
173 tags = extract_tag_box(
174 r'(?s)Tags:.*?</div>\s*<div[^>]+class=["\']tagBoxContent
["\'][^>]*>(.+?)</div>',
179 'display_id': display_id,
181 'description': description,
182 'thumbnail': thumbnail,
183 'uploader': uploader,
184 'upload_date': upload_date,
185 'average_rating': average_rating,
186 'view_count': view_count,
187 'comment_count': comment_count,
188 'categories': categories,
190 'age_limit': age_limit,