]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/spankwire.py
release 2014.02.21.1
[yt-dlp.git] / youtube_dl / extractor / spankwire.py
CommitLineData
9ac0a675
PH
1from __future__ import unicode_literals
2
7b2212e9 3import os
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 compat_urllib_parse,
7b2212e9 11)
12from ..aes import (
13 aes_decrypt_text
14)
15
9ac0a675 16
7b2212e9 17class SpankwireIE(InfoExtractor):
18 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
19 _TEST = {
9ac0a675
PH
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,
7b2212e9 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
9ac0a675 40 video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
0ad97bbc 41 video_uploader = self._html_search_regex(
9ac0a675 42 r'by:\s*<a [^>]*>(.+?)</a>', webpage, 'uploader', fatal=False)
0ad97bbc 43 thumbnail = self._html_search_regex(
9ac0a675 44 r'flashvars\.image_url = "([^"]+)', webpage, 'thumbnail', fatal=False)
0ad97bbc 45 description = self._html_search_regex(
9ac0a675 46 r'<div\s+id="descriptionContent">([^<]+)<', webpage, 'description', fatal=False)
7b2212e9 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:
9ac0a675 50 password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, 'password').replace('+', ' ')
7b2212e9 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:
a56f9de1
JMF
55 path = compat_urllib_parse_urlparse(video_url).path
56 extension = os.path.splitext(path)[1][1:]
7b2212e9 57 format = path.split('/')[4].split('_')[:2]
9ac0a675 58 resolution, bitrate_str = format
a56f9de1 59 format = "-".join(format)
9ac0a675
PH
60 height = int(resolution.rstrip('P'))
61 tbr = int(bitrate_str.rstrip('K'))
62
7b2212e9 63 formats.append({
64 'url': video_url,
65 'ext': extension,
9ac0a675 66 'resolution': resolution,
7b2212e9 67 'format': format,
9ac0a675
PH
68 'tbr': tbr,
69 'height': height,
7b2212e9 70 'format_id': format,
71 })
9ac0a675 72 self._sort_formats(formats)
7b2212e9 73
750e9833
FV
74 age_limit = self._rta_search(webpage)
75
7b2212e9 76 return {
77 'id': video_id,
78 'uploader': video_uploader,
79 'title': video_title,
80 'thumbnail': thumbnail,
81 'description': description,
82 'formats': formats,
750e9833 83 'age_limit': age_limit,
7b2212e9 84 }