]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/spankwire.py
debian/NEWS: Write news about new behavior of youtube-dl.
[youtubedl] / youtube_dl / extractor / spankwire.py
1 from __future__ import unicode_literals
2
3 import os
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 compat_urllib_parse,
11 )
12 from ..aes import (
13 aes_decrypt_text
14 )
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 'file': '103545.mp4',
22 'md5': '1b3f55e345500552dbc252a3e9c1af43',
23 'info_dict': {
24 "uploader": "oreusz",
25 "title": "Buckcherry`s X Rated Music Video Crazy Bitch",
26 "description": "Crazy Bitch X rated music video.",
27 "age_limit": 18,
28 }
29 }
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 video_id = mobj.group('videoid')
34 url = 'http://www.' + mobj.group('url')
35
36 req = compat_urllib_request.Request(url)
37 req.add_header('Cookie', 'age_verified=1')
38 webpage = self._download_webpage(req, video_id)
39
40 video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
41 video_uploader = self._html_search_regex(
42 r'by:\s*<a [^>]*>(.+?)</a>', webpage, 'uploader', fatal=False)
43 thumbnail = self._html_search_regex(
44 r'flashvars\.image_url = "([^"]+)', webpage, 'thumbnail', fatal=False)
45 description = self._html_search_regex(
46 r'<div\s+id="descriptionContent">([^<]+)<', webpage, 'description', fatal=False)
47
48 video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
49 if webpage.find('flashvars\.encrypted = "true"') != -1:
50 password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, 'password').replace('+', ' ')
51 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
52
53 formats = []
54 for video_url in video_urls:
55 path = compat_urllib_parse_urlparse(video_url).path
56 extension = os.path.splitext(path)[1][1:]
57 format = path.split('/')[4].split('_')[:2]
58 resolution, bitrate_str = format
59 format = "-".join(format)
60 height = int(resolution.rstrip('P'))
61 tbr = int(bitrate_str.rstrip('K'))
62
63 formats.append({
64 'url': video_url,
65 'ext': extension,
66 'resolution': resolution,
67 'format': format,
68 'tbr': tbr,
69 'height': height,
70 'format_id': format,
71 })
72 self._sort_formats(formats)
73
74 age_limit = self._rta_search(webpage)
75
76 return {
77 'id': video_id,
78 'uploader': video_uploader,
79 'title': video_title,
80 'thumbnail': thumbnail,
81 'description': description,
82 'formats': formats,
83 'age_limit': age_limit,
84 }