]>
Commit | Line | Data |
---|---|---|
ae6cae78 S |
1 | from __future__ import unicode_literals |
2 | ||
03635e2a MK |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
1cc79574 | 6 | from ..compat import ( |
ae6cae78 | 7 | compat_urllib_request, |
1cc79574 PH |
8 | ) |
9 | from ..utils import ( | |
e77c5b4f | 10 | clean_html, |
1cc79574 PH |
11 | parse_duration, |
12 | str_to_int, | |
13 | unified_strdate, | |
ae6cae78 | 14 | ) |
ae6cae78 | 15 | |
03635e2a MK |
16 | |
17 | class FourTubeIE(InfoExtractor): | |
18 | IE_NAME = '4tube' | |
ae6cae78 | 19 | _VALID_URL = r'https?://(?:www\.)?4tube\.com/videos/(?P<id>\d+)' |
03635e2a MK |
20 | |
21 | _TEST = { | |
ae6cae78 S |
22 | 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black', |
23 | 'md5': '6516c8ac63b03de06bc8eac14362db4f', | |
24 | 'info_dict': { | |
25 | 'id': '209733', | |
26 | 'ext': 'mp4', | |
27 | 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black', | |
28 | 'uploader': 'WCP Club', | |
29 | 'uploader_id': 'wcp-club', | |
30 | 'upload_date': '20131031', | |
31 | 'duration': 583, | |
32 | } | |
33 | } | |
03635e2a MK |
34 | |
35 | def _real_extract(self, url): | |
1cc79574 | 36 | video_id = self._match_id(url) |
03635e2a MK |
37 | webpage_url = 'http://www.4tube.com/videos/' + video_id |
38 | webpage = self._download_webpage(webpage_url, video_id) | |
39 | ||
40 | self.report_extraction(video_id) | |
41 | ||
ae6cae78 S |
42 | playlist_json = self._html_search_regex(r'var playerConfigPlaylist\s+=\s+([^;]+)', webpage, 'Playlist') |
43 | media_id = self._search_regex(r'idMedia:\s*(\d+)', playlist_json, 'Media Id') | |
44 | sources = self._search_regex(r'sources:\s*\[([^\]]*)\]', playlist_json, 'Sources').split(',') | |
45 | title = self._search_regex(r'title:\s*"([^"]*)', playlist_json, 'Title') | |
46 | thumbnail_url = self._search_regex(r'image:\s*"([^"]*)', playlist_json, 'Thumbnail', fatal=False) | |
47 | ||
48 | uploader_str = self._search_regex(r'<span>Uploaded by</span>(.*?)<span>', webpage, 'uploader', fatal=False) | |
49 | mobj = re.search(r'<a href="/sites/(?P<id>[^"]+)"><strong>(?P<name>[^<]+)</strong></a>', uploader_str) | |
50 | (uploader, uploader_id) = (mobj.group('name'), mobj.group('id')) if mobj else (clean_html(uploader_str), None) | |
51 | ||
52 | upload_date = None | |
53 | view_count = None | |
54 | duration = None | |
55 | description = self._html_search_meta('description', webpage, 'description') | |
56 | if description: | |
57 | upload_date = self._search_regex(r'Published Date: (\d{2} [a-zA-Z]{3} \d{4})', description, 'upload date', | |
9e1a5b84 | 58 | fatal=False) |
ae6cae78 S |
59 | if upload_date: |
60 | upload_date = unified_strdate(upload_date) | |
61 | view_count = self._search_regex(r'Views: ([\d,\.]+)', description, 'view count', fatal=False) | |
62 | if view_count: | |
63 | view_count = str_to_int(view_count) | |
64 | duration = parse_duration(self._search_regex(r'Length: (\d+m\d+s)', description, 'duration', fatal=False)) | |
03635e2a MK |
65 | |
66 | token_url = "http://tkn.4tube.com/{0}/desktop/{1}".format(media_id, "+".join(sources)) | |
67 | headers = { | |
b74e86f4 PH |
68 | b'Content-Type': b'application/x-www-form-urlencoded', |
69 | b'Origin': b'http://www.4tube.com', | |
70 | } | |
03635e2a MK |
71 | token_req = compat_urllib_request.Request(token_url, b'{}', headers) |
72 | tokens = self._download_json(token_req, video_id) | |
73 | ||
74 | formats = [{ | |
75 | 'url': tokens[format]['token'], | |
76 | 'format_id': format + 'p', | |
77 | 'resolution': format + 'p', | |
78 | 'quality': int(format), | |
b74e86f4 | 79 | } for format in sources] |
03635e2a | 80 | |
ae6cae78 S |
81 | self._sort_formats(formats) |
82 | ||
83 | return { | |
03635e2a MK |
84 | 'id': video_id, |
85 | 'title': title, | |
86 | 'formats': formats, | |
87 | 'thumbnail': thumbnail_url, | |
ae6cae78 S |
88 | 'uploader': uploader, |
89 | 'uploader_id': uploader_id, | |
90 | 'upload_date': upload_date, | |
91 | 'view_count': view_count, | |
92 | 'duration': duration, | |
03635e2a MK |
93 | 'age_limit': 18, |
94 | 'webpage_url': webpage_url, | |
5f6a1245 | 95 | } |