]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tube8.py
08a48c05acf34b6cd190ba52d58189935fe6b20f
[youtubedl] / youtube_dl / extractor / tube8.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urllib_parse_urlparse,
9 compat_urllib_request,
10 int_or_none,
11 str_to_int,
12 )
13 from ..aes import aes_decrypt_text
14
15
16 class Tube8IE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?tube8\.com/(?:[^/]+/){2}(?P<id>\d+)'
18 _TEST = {
19 'url': 'http://www.tube8.com/teen/kasia-music-video/229795/',
20 'md5': '44bf12b98313827dd52d35b8706a4ea0',
21 'info_dict': {
22 'id': '229795',
23 'ext': 'mp4',
24 'description': 'hot teen Kasia grinding',
25 'uploader': 'unknown',
26 'title': 'Kasia music video',
27 'age_limit': 18,
28 }
29 }
30
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 video_id = mobj.group('id')
34
35 req = compat_urllib_request.Request(url)
36 req.add_header('Cookie', 'age_verified=1')
37 webpage = self._download_webpage(req, video_id)
38
39 flashvars = json.loads(self._html_search_regex(
40 r'var flashvars\s*=\s*({.+?})', webpage, 'flashvars'))
41
42 video_url = flashvars['video_url']
43 if flashvars.get('encrypted') is True:
44 video_url = aes_decrypt_text(video_url, flashvars['video_title'], 32).decode('utf-8')
45 path = compat_urllib_parse_urlparse(video_url).path
46 format_id = '-'.join(path.split('/')[4].split('_')[:2])
47
48 thumbnail = flashvars.get('image_url')
49
50 title = self._html_search_regex(
51 r'videotitle\s*=\s*"([^"]+)', webpage, 'title')
52 description = self._html_search_regex(
53 r'>Description:</strong>(.+?)<', webpage, 'description', fatal=False)
54 uploader = self._html_search_regex(
55 r'<strong class="video-username">(?:<a href="[^"]+">)?([^<]+)(?:</a>)?</strong>',
56 webpage, 'uploader', fatal=False)
57
58 like_count = int_or_none(self._html_search_regex(
59 r"rupVar\s*=\s*'(\d+)'", webpage, 'like count', fatal=False))
60 dislike_count = int_or_none(self._html_search_regex(
61 r"rdownVar\s*=\s*'(\d+)'", webpage, 'dislike count', fatal=False))
62 view_count = self._html_search_regex(
63 r'<strong>Views: </strong>([\d,\.]+)</li>', webpage, 'view count', fatal=False)
64 if view_count:
65 view_count = str_to_int(view_count)
66 comment_count = self._html_search_regex(
67 r'<span id="allCommentsCount">(\d+)</span>', webpage, 'comment count', fatal=False)
68 if comment_count:
69 comment_count = str_to_int(comment_count)
70
71 return {
72 'id': video_id,
73 'url': video_url,
74 'title': title,
75 'description': description,
76 'thumbnail': thumbnail,
77 'uploader': uploader,
78 'format_id': format_id,
79 'view_count': view_count,
80 'like_count': like_count,
81 'dislike_count': dislike_count,
82 'comment_count': comment_count,
83 'age_limit': 18,
84 }