]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/spankwire.py
[youtube] Correct subtitle URL (Fixes #2120)
[yt-dlp.git] / youtube_dl / extractor / spankwire.py
CommitLineData
7b2212e9 1import os
2import re
3
4from .common import InfoExtractor
5from ..utils import (
6 compat_urllib_parse_urlparse,
7 compat_urllib_request,
8 compat_urllib_parse,
7b2212e9 9)
10from ..aes import (
11 aes_decrypt_text
12)
13
14class 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.",
750e9833 24 u"age_limit": 18,
7b2212e9 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')
0ad97bbc
PH
38 video_uploader = self._html_search_regex(
39 r'by:\s*<a [^>]*>(.+?)</a>', webpage, u'uploader', fatal=False)
40 thumbnail = self._html_search_regex(
41 r'flashvars\.image_url = "([^"]+)', webpage, u'thumbnail', fatal=False)
42 description = self._html_search_regex(
ca872a4c 43 r'<div\s+id="descriptionContent">([^<]+)<', webpage, u'description', fatal=False)
7b2212e9 44
45 video_urls = list(map(compat_urllib_parse.unquote , re.findall(r'flashvars\.quality_[0-9]{3}p = "([^"]+)', webpage)))
46 if webpage.find('flashvars\.encrypted = "true"') != -1:
47 password = self._html_search_regex(r'flashvars\.video_title = "([^"]+)', webpage, u'password').replace('+', ' ')
48 video_urls = list(map(lambda s: aes_decrypt_text(s, password, 32).decode('utf-8'), video_urls))
49
50 formats = []
51 for video_url in video_urls:
a56f9de1
JMF
52 path = compat_urllib_parse_urlparse(video_url).path
53 extension = os.path.splitext(path)[1][1:]
7b2212e9 54 format = path.split('/')[4].split('_')[:2]
a56f9de1 55 format = "-".join(format)
7b2212e9 56 formats.append({
57 'url': video_url,
58 'ext': extension,
59 'format': format,
60 'format_id': format,
61 })
62 formats.sort(key=lambda format: list(map(lambda s: s.zfill(6), format['format'].split('-'))))
63
750e9833
FV
64 age_limit = self._rta_search(webpage)
65
7b2212e9 66 return {
67 'id': video_id,
68 'uploader': video_uploader,
69 'title': video_title,
70 'thumbnail': thumbnail,
71 'description': description,
72 'formats': formats,
750e9833 73 'age_limit': age_limit,
7b2212e9 74 }