]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tube8.py
3ec9442c9392fe6168d315925ee83f0df6222b5d
[youtubedl] / youtube_dl / extractor / tube8.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 )
9 from ..aes import (
10 aes_decrypt_text
11 )
12
13 class Tube8IE(InfoExtractor):
14 _VALID_URL = r'^(?:https?://)?(?:www\.)?(?P<url>tube8\.com/.+?/(?P<videoid>\d+)/?)$'
15 _TEST = {
16 u'url': u'http://www.tube8.com/teen/kasia-music-video/229795/',
17 u'file': u'229795.mp4',
18 u'md5': u'e9e0b0c86734e5e3766e653509475db0',
19 u'info_dict': {
20 u"description": u"hot teen Kasia grinding",
21 u"uploader": u"unknown",
22 u"title": u"Kasia music video",
23 u"age_limit": 18,
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('videoid')
30 url = 'http://www.' + mobj.group('url')
31
32 req = compat_urllib_request.Request(url)
33 req.add_header('Cookie', 'age_verified=1')
34 webpage = self._download_webpage(req, video_id)
35
36 video_title = self._html_search_regex(r'videotitle ="([^"]+)', webpage, u'title')
37 video_description = self._html_search_regex(r'>Description:</strong>(.+?)<', webpage, u'description', fatal=False)
38 video_uploader = self._html_search_regex(r'>Submitted by:</strong>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
39 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False)
40 if thumbnail:
41 thumbnail = thumbnail.replace('\\/', '/')
42
43 video_url = self._html_search_regex(r'"video_url":"([^"]+)', webpage, u'video_url')
44 if webpage.find('"encrypted":true')!=-1:
45 password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password')
46 video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
47 path = compat_urllib_parse_urlparse(video_url).path
48 extension = os.path.splitext(path)[1][1:]
49 format = path.split('/')[4].split('_')[:2]
50 format = "-".join(format)
51
52 return {
53 'id': video_id,
54 'uploader': video_uploader,
55 'title': video_title,
56 'thumbnail': thumbnail,
57 'description': video_description,
58 'url': video_url,
59 'ext': extension,
60 'format': format,
61 'format_id': format,
62 'age_limit': 18,
63 }