]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/spankwire.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / spankwire.py
CommitLineData
9ac0a675
PH
1from __future__ import unicode_literals
2
7b2212e9 3import re
4
5from .common import InfoExtractor
1cc79574 6from ..compat import (
47af21e8 7 compat_urllib_parse_unquote,
7b2212e9 8 compat_urllib_parse_urlparse,
1cc79574
PH
9)
10from ..utils import (
5c2266df 11 sanitized_Request,
9767726b 12 str_to_int,
1cc79574 13 unified_strdate,
7b2212e9 14)
9767726b 15from ..aes import aes_decrypt_text
7b2212e9 16
9ac0a675 17
7b2212e9 18class SpankwireIE(InfoExtractor):
28b83495 19 _VALID_URL = r'https?://(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<id>[0-9]+)/?)'
59e6acc7 20 _TESTS = [{
551c7837
S
21 # download URL pattern: */<height>P_<tbr>K_<video_id>.mp4
22 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
23 'md5': '8bbfde12b101204b39e4b9fe7eb67095',
24 'info_dict': {
25 'id': '103545',
26 'ext': 'mp4',
27 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
28 'description': 'Crazy Bitch X rated music video.',
29 'uploader': 'oreusz',
30 'uploader_id': '124697',
31 'upload_date': '20070507',
32 'age_limit': 18,
33 }
34 }, {
35 # download URL pattern: */mp4_<format_id>_<video_id>.mp4
36 'url': 'http://www.spankwire.com/Titcums-Compiloation-I/video1921551/',
37 'md5': '09b3c20833308b736ae8902db2f8d7e6',
38 'info_dict': {
39 'id': '1921551',
40 'ext': 'mp4',
41 'title': 'Titcums Compiloation I',
42 'description': 'cum on tits',
43 'uploader': 'dannyh78999',
44 'uploader_id': '3056053',
45 'upload_date': '20150822',
46 'age_limit': 18,
47 },
48 }]
7b2212e9 49
50 def _real_extract(self, url):
51 mobj = re.match(self._VALID_URL, url)
28b83495 52 video_id = mobj.group('id')
7b2212e9 53
5c2266df 54 req = sanitized_Request('http://www.' + mobj.group('url'))
7b2212e9 55 req.add_header('Cookie', 'age_verified=1')
56 webpage = self._download_webpage(req, video_id)
57
fdb4d278
S
58 title = self._html_search_regex(
59 r'<h1>([^<]+)', webpage, 'title')
0ad97bbc 60 description = self._html_search_regex(
44705366 61 r'(?s)<div\s+id="descriptionContent">(.+?)</div>',
fdb4d278 62 webpage, 'description', fatal=False)
9767726b 63 thumbnail = self._html_search_regex(
d3c9af84 64 r'playerData\.screenShot\s*=\s*["\']([^"\']+)["\']',
fdb4d278 65 webpage, 'thumbnail', fatal=False)
9767726b
S
66
67 uploader = self._html_search_regex(
fdb4d278
S
68 r'by:\s*<a [^>]*>(.+?)</a>',
69 webpage, 'uploader', fatal=False)
9767726b 70 uploader_id = self._html_search_regex(
90076b61 71 r'by:\s*<a href="/(?:user/viewProfile|Profile\.aspx)\?.*?UserId=(\d+).*?"',
fdb4d278
S
72 webpage, 'uploader id', fatal=False)
73 upload_date = unified_strdate(self._html_search_regex(
74 r'</a> on (.+?) at \d+:\d+',
75 webpage, 'upload date', fatal=False))
7b2212e9 76
fdb4d278
S
77 view_count = str_to_int(self._html_search_regex(
78 r'<div id="viewsCounter"><span>([\d,\.]+)</span> views</div>',
79 webpage, 'view count', fatal=False))
80 comment_count = str_to_int(self._html_search_regex(
44705366 81 r'<span\s+id="spCommentCount"[^>]*>([\d,\.]+)</span>',
fdb4d278
S
82 webpage, 'comment count', fatal=False))
83
551c7837
S
84 videos = re.findall(
85 r'playerData\.cdnPath([0-9]{3,})\s*=\s*(?:encodeURIComponent\()?["\']([^"\']+)["\']', webpage)
86 heights = [int(video[0]) for video in videos]
87 video_urls = list(map(compat_urllib_parse_unquote, [video[1] for video in videos]))
ec85ded8 88 if webpage.find(r'flashvars\.encrypted = "true"') != -1:
1434184c 89 password = self._search_regex(
fdb4d278
S
90 r'flashvars\.video_title = "([^"]+)',
91 webpage, 'password').replace('+', ' ')
92 video_urls = list(map(
93 lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'),
94 video_urls))
7b2212e9 95
96 formats = []
551c7837 97 for height, video_url in zip(heights, video_urls):
a56f9de1 98 path = compat_urllib_parse_urlparse(video_url).path
6a1df4fb
S
99 m = re.search(r'/(?P<height>\d+)[pP]_(?P<tbr>\d+)[kK]', path)
100 if m:
101 tbr = int(m.group('tbr'))
102 height = int(m.group('height'))
103 else:
104 tbr = None
105 formats.append({
551c7837 106 'url': video_url,
6a1df4fb 107 'format_id': '%dp' % height,
551c7837 108 'height': height,
6a1df4fb
S
109 'tbr': tbr,
110 })
9ac0a675 111 self._sort_formats(formats)
7b2212e9 112
750e9833
FV
113 age_limit = self._rta_search(webpage)
114
7b2212e9 115 return {
116 'id': video_id,
9767726b 117 'title': title,
7b2212e9 118 'description': description,
9767726b
S
119 'thumbnail': thumbnail,
120 'uploader': uploader,
121 'uploader_id': uploader_id,
122 'upload_date': upload_date,
123 'view_count': view_count,
124 'comment_count': comment_count,
7b2212e9 125 'formats': formats,
750e9833 126 'age_limit': age_limit,
7b2212e9 127 }