]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tube8.py
debian/control: Add dependency on python-pkg-resources.
[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 compat_urllib_parse,
9 unescapeHTML,
10 )
11 from ..aes import (
12 aes_decrypt_text
13 )
14
15 class 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 u"age_limit": 18,
26 }
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('videoid')
32 url = 'http://www.' + mobj.group('url')
33
34 req = compat_urllib_request.Request(url)
35 req.add_header('Cookie', 'age_verified=1')
36 webpage = self._download_webpage(req, video_id)
37
38 video_title = self._html_search_regex(r'videotitle ="([^"]+)', webpage, u'title')
39 video_description = self._html_search_regex(r'>Description:</strong>(.+?)<', webpage, u'description', fatal=False)
40 video_uploader = self._html_search_regex(r'>Submitted by:</strong>(?:\s|<[^>]*>)*(.+?)<', webpage, u'uploader', fatal=False)
41 thumbnail = self._html_search_regex(r'"image_url":"([^"]+)', webpage, u'thumbnail', fatal=False)
42 if thumbnail:
43 thumbnail = thumbnail.replace('\\/', '/')
44
45 video_url = self._html_search_regex(r'"video_url":"([^"]+)', webpage, u'video_url')
46 if webpage.find('"encrypted":true')!=-1:
47 password = self._html_search_regex(r'"video_title":"([^"]+)', webpage, u'password')
48 video_url = aes_decrypt_text(video_url, password, 32).decode('utf-8')
49 path = compat_urllib_parse_urlparse(video_url).path
50 extension = os.path.splitext(path)[1][1:]
51 format = path.split('/')[4].split('_')[:2]
52 format = "-".join(format)
53
54 return {
55 'id': video_id,
56 'uploader': video_uploader,
57 'title': video_title,
58 'thumbnail': thumbnail,
59 'description': video_description,
60 'url': video_url,
61 'ext': extension,
62 'format': format,
63 'format_id': format,
64 'age_limit': 18,
65 }