]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/spankwire.py
Clean up unused imports and other minor mistakes
[yt-dlp.git] / youtube_dl / extractor / spankwire.py
1 import os
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 compat_urllib_parse_urlparse,
7 compat_urllib_request,
8 compat_urllib_parse,
9 )
10 from ..aes import (
11 aes_decrypt_text
12 )
13
14 class SpankwireIE(InfoExtractor):
15 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>spankwire\.com/[^/]*/video(?P<videoid>[0-9]+)/?)'
16 _TEST = {
17 u'url': u'http://www.spankwire.com/Buckcherry-s-X-Rated-Music-Video-Crazy-Bitch/video103545/',
18 u'file': u'103545.mp4',
19 u'md5': u'1b3f55e345500552dbc252a3e9c1af43',
20 u'info_dict': {
21 u"uploader": u"oreusz",
22 u"title": u"Buckcherry`s X Rated Music Video Crazy Bitch",
23 u"description": u"Crazy Bitch X rated music video.",
24 u"age_limit": 18,
25 }
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('videoid')
31 url = 'http://www.' + mobj.group('url')
32
33 req = compat_urllib_request.Request(url)
34 req.add_header('Cookie', 'age_verified=1')
35 webpage = self._download_webpage(req, video_id)
36
37 video_title = self._html_search_regex(r'<h1>([^<]+)', webpage, u'title')
38 video_uploader = self._html_search_regex(r'by:\s*<a [^>]*>(.+?)</a>', webpage, u'uploader', fatal=False)
39 thumbnail = self._html_search_regex(r'flashvars\.image_url = "([^"]+)', webpage, u'thumbnail', fatal=False)
40 description = self._html_search_regex(r'>\s*Description:</div>\s*<[^>]*>([^<]+)', webpage, u'description', fatal=False)
41 if len(description) == 0:
42 description = None
43
44 video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
45 if webpage.find('flashvars\.encrypted = "true"') != -1:
46 password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, u'password').replace('+', ' ')
47 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
48
49 formats = []
50 for video_url in video_urls:
51 path = compat_urllib_parse_urlparse(video_url).path
52 extension = os.path.splitext(path)[1][1:]
53 format = path.split('/')[4].split('_')[:2]
54 format = "-".join(format)
55 formats.append({
56 'url': video_url,
57 'ext': extension,
58 'format': format,
59 'format_id': format,
60 })
61 formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
62
63 age_limit = self._rta_search(webpage)
64
65 return {
66 'id': video_id,
67 'uploader': video_uploader,
68 'title': video_title,
69 'thumbnail': thumbnail,
70 'description': description,
71 'formats': formats,
72 'age_limit': age_limit,
73 }