]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/fourtube.py
Merge remote-tracking branch 'duncankl/airmozilla'
[yt-dlp.git] / youtube_dl / extractor / fourtube.py
CommitLineData
ae6cae78
S
1from __future__ import unicode_literals
2
03635e2a
MK
3import re
4
5from .common import InfoExtractor
1cc79574 6from ..compat import (
ae6cae78 7 compat_urllib_request,
1cc79574
PH
8)
9from ..utils import (
1cc79574 10 parse_duration,
9d22a7df 11 parse_iso8601,
1cc79574 12 str_to_int,
ae6cae78 13)
ae6cae78 14
03635e2a
MK
15
16class FourTubeIE(InfoExtractor):
17 IE_NAME = '4tube'
ae6cae78 18 _VALID_URL = r'https?://(?:www\.)?4tube\.com/videos/(?P<id>\d+)'
03635e2a
MK
19
20 _TEST = {
ae6cae78
S
21 'url': 'http://www.4tube.com/videos/209733/hot-babe-holly-michaels-gets-her-ass-stuffed-by-black',
22 'md5': '6516c8ac63b03de06bc8eac14362db4f',
23 'info_dict': {
24 'id': '209733',
25 'ext': 'mp4',
26 'title': 'Hot Babe Holly Michaels gets her ass stuffed by black',
27 'uploader': 'WCP Club',
28 'uploader_id': 'wcp-club',
29 'upload_date': '20131031',
9d22a7df 30 'timestamp': 1383263892,
ae6cae78 31 'duration': 583,
9d22a7df
PH
32 'view_count': int,
33 'like_count': int,
34 'categories': list,
ae6cae78
S
35 }
36 }
03635e2a
MK
37
38 def _real_extract(self, url):
1cc79574 39 video_id = self._match_id(url)
9d22a7df 40 webpage = self._download_webpage(url, video_id)
03635e2a 41
9d22a7df
PH
42 title = self._html_search_meta('name', webpage)
43 timestamp = parse_iso8601(self._html_search_meta(
44 'uploadDate', webpage))
45 thumbnail = self._html_search_meta('thumbnailUrl', webpage)
46 uploader_id = self._html_search_regex(
47 r'<a class="img-avatar" href="[^"]+/channels/([^/"]+)" title="Go to [^"]+ page">',
48 webpage, 'uploader id')
49 uploader = self._html_search_regex(
50 r'<a class="img-avatar" href="[^"]+/channels/[^/"]+" title="Go to ([^"]+) page">',
51 webpage, 'uploader')
03635e2a 52
9d22a7df
PH
53 categories_html = self._search_regex(
54 r'(?s)><i class="icon icon-tag"></i>\s*Categories / Tags\s*.*?<ul class="list">(.*?)</ul>',
55 webpage, 'categories', fatal=False)
56 categories = None
57 if categories_html:
58 categories = [
59 c.strip() for c in re.findall(
60 r'(?s)<li><a.*?>(.*?)</a>', categories_html)]
ae6cae78 61
9d22a7df
PH
62 view_count = str_to_int(self._search_regex(
63 r'<meta itemprop="interactionCount" content="UserPlays:([0-9,]+)">',
64 webpage, 'view count', fatal=False))
65 like_count = str_to_int(self._search_regex(
66 r'<meta itemprop="interactionCount" content="UserLikes:([0-9,]+)">',
67 webpage, 'like count', fatal=False))
68 duration = parse_duration(self._html_search_meta('duration', webpage))
ae6cae78 69
9d22a7df
PH
70 params_js = self._search_regex(
71 r'\$\.ajax\(url,\ opts\);\s*\}\s*\}\)\(([0-9,\[\] ]+)\)',
72 webpage, 'initialization parameters'
73 )
74 params = self._parse_json('[%s]' % params_js, video_id)
75 media_id = params[0]
76 sources = ['%s' % p for p in params[2]]
03635e2a 77
9d22a7df
PH
78 token_url = 'http://tkn.4tube.com/{0}/desktop/{1}'.format(
79 media_id, '+'.join(sources))
03635e2a 80 headers = {
b74e86f4
PH
81 b'Content-Type': b'application/x-www-form-urlencoded',
82 b'Origin': b'http://www.4tube.com',
83 }
03635e2a
MK
84 token_req = compat_urllib_request.Request(token_url, b'{}', headers)
85 tokens = self._download_json(token_req, video_id)
03635e2a
MK
86 formats = [{
87 'url': tokens[format]['token'],
88 'format_id': format + 'p',
89 'resolution': format + 'p',
90 'quality': int(format),
b74e86f4 91 } for format in sources]
ae6cae78
S
92 self._sort_formats(formats)
93
94 return {
03635e2a
MK
95 'id': video_id,
96 'title': title,
97 'formats': formats,
9d22a7df
PH
98 'categories': categories,
99 'thumbnail': thumbnail,
ae6cae78
S
100 'uploader': uploader,
101 'uploader_id': uploader_id,
9d22a7df
PH
102 'timestamp': timestamp,
103 'like_count': like_count,
ae6cae78
S
104 'view_count': view_count,
105 'duration': duration,
03635e2a 106 'age_limit': 18,
5f6a1245 107 }