]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spankwire.py
b936202f6f3005fe9ae085724566d709c6a484cc
[youtubedl] / youtube_dl / extractor / spankwire.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_urllib_parse,
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 )
11 from ..utils import (
12 str_to_int,
13 unified_strdate,
14 )
15 from ..aes import aes_decrypt_text
16
17
18 class SpankwireIE(InfoExtractor):
19 _VALID_URL = r'https?://(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
20 _TEST = {
21 'url': 'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
22 'md5': '8bbfde12b101204b39e4b9fe7eb67095',
23 'info_dict': {
24 'id': '103545',
25 'ext': 'mp4',
26 'title': 'Buckcherry`s X Rated Music Video Crazy Bitch',
27 'description': 'Crazy Bitch X rated music video.',
28 'uploader': 'oreusz',
29 'uploader_id': '124697',
30 'upload_date': '20070508',
31 'age_limit': 18,
32 }
33 }
34
35 def _real_extract(self, url):
36 mobj = re.match(self._VALID_URL, url)
37 video_id = mobj.group('videoid')
38 url = 'http://www.' + mobj.group('url')
39
40 req = compat_urllib_request.Request(url)
41 req.add_header('Cookie', 'age_verified=1')
42 webpage = self._download_webpage(req, video_id)
43
44 title = self._html_search_regex(
45 r'<h1>([^<]+)', webpage, 'title')
46 description = self._html_search_regex(
47 r'<div\s+id="descriptionContent">([^<]+)<',
48 webpage, 'description', fatal=False)
49 thumbnail = self._html_search_regex(
50 r'playerData\.screenShot\s*=\s*["\']([^"\']+)["\']',
51 webpage, 'thumbnail', fatal=False)
52
53 uploader = self._html_search_regex(
54 r'by:\s*<a [^>]*>(.+?)</a>',
55 webpage, 'uploader', fatal=False)
56 uploader_id = self._html_search_regex(
57 r'by:\s*<a href="/Profile\.aspx\?.*?UserId=(\d+).*?"',
58 webpage, 'uploader id', fatal=False)
59 upload_date = unified_strdate(self._html_search_regex(
60 r'</a> on (.+?) at \d+:\d+',
61 webpage, 'upload date', fatal=False))
62
63 view_count = str_to_int(self._html_search_regex(
64 r'<div id="viewsCounter"><span>([\d,\.]+)</span> views</div>',
65 webpage, 'view count', fatal=False))
66 comment_count = str_to_int(self._html_search_regex(
67 r'Comments<span[^>]+>\s*\(([\d,\.]+)\)</span>',
68 webpage, 'comment count', fatal=False))
69
70 video_urls = list(map(
71 compat_urllib_parse.unquote,
72 re.findall(r'playerData\.cdnPath[0-9]{3,}\s*=\s*["\']([^"\']+)["\']', webpage)))
73 if webpage.find('flashvars\.encrypted = "true"') != -1:
74 password = self._html_search_regex(
75 r'flashvars\.video_title = "([^"]+)',
76 webpage, 'password').replace('+', ' ')
77 video_urls = list(map(
78 lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'),
79 video_urls))
80
81 formats = []
82 for video_url in video_urls:
83 path = compat_urllib_parse_urlparse(video_url).path
84 format = path.split('/')[4].split('_')[:2]
85 resolution, bitrate_str = format
86 format = "-".join(format)
87 height = int(resolution.rstrip('Pp'))
88 tbr = int(bitrate_str.rstrip('Kk'))
89 formats.append({
90 'url': video_url,
91 'resolution': resolution,
92 'format': format,
93 'tbr': tbr,
94 'height': height,
95 'format_id': format,
96 })
97 self._sort_formats(formats)
98
99 age_limit = self._rta_search(webpage)
100
101 return {
102 'id': video_id,
103 'title': title,
104 'description': description,
105 'thumbnail': thumbnail,
106 'uploader': uploader,
107 'uploader_id': uploader_id,
108 'upload_date': upload_date,
109 'view_count': view_count,
110 'comment_count': comment_count,
111 'formats': formats,
112 'age_limit': age_limit,
113 }