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