]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/tube8.py
Add support for http://www.tube8.com
[yt-dlp.git] / youtube_dl / extractor / tube8.py
CommitLineData
1d45a23b 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,
9 unescapeHTML,
10)
11from ..aes import (
12 aes_decrypt_text
13)
14
15class Tube8IE(InfoExtractor):
16 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>tube8.com/[^/]+/[^/]+/(?P<videoid>[0-9]+)/?)'
17 _TEST = {
18 u'url': u'http://www.tube8.com/teen/kasia-music-video/229795/',
19 u'file': u'229795.mp4',
20 u'md5': u'e9e0b0c86734e5e3766e653509475db0',
21 u'info_dict': {
22 u"description": u"hot teen Kasia grinding",
23 u"uploader": u"unknown",
24 u"title": u"Kasia music video",
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'videotitle ="([^"]+)', webpage, u'title')
38 video_description = self._html_search_regex(r'>Description:</strong>(.+?)<', webpage, u'description', fatal=False)
39 video_uploader = self._html_search_regex(r'>Submitted by:</strong>(?:\w|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
40 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False)
41 if thumbnail:
42 thumbnail = thumbnail.replace('\\/', '/')
43
44 video_url = self._html_search_regex(r'"video_url":"([^"]+)', webpage, u'video_url')
45 if webpage.find('"encrypted":true')!=-1:
46 password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password')
47 video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
48 path = compat_urllib_parse_urlparse( video_url ).path
49 extension = os.path.splitext( path )[1][1:]
50 format = path.split('/')[4].split('_')[:2]
51 format = "-".join( format )
52
53 return {
54 'id': video_id,
55 'uploader': video_uploader,
56 'title': video_title,
57 'thumbnail': thumbnail,
58 'description': video_description,
59 'url': video_url,
60 'ext': extension,
61 'format': format,
62 'format_id': format,
63 }