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