]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/minhateca.py
release 2014.12.04.1
[yt-dlp.git] / youtube_dl / extractor / minhateca.py
CommitLineData
4349c07d
PH
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..compat import (
6 compat_urllib_parse,
7 compat_urllib_request,
8)
9from ..utils import (
10 int_or_none,
11 parse_filesize,
12)
13
14
15class MinhatecaIE(InfoExtractor):
16 _VALID_URL = r'https?://minhateca\.com\.br/[^?#]+,(?P<id>[0-9]+)\.'
17 _TEST = {
18 'url': 'http://minhateca.com.br/pereba/misc/youtube-dl+test+video,125848331.mp4(video)',
19 'info_dict': {
20 'id': '125848331',
21 'ext': 'mp4',
22 'title': 'youtube-dl test video',
23 'thumbnail': 're:^https?://.*\.jpg$',
24 'filesize_approx': 1530000,
25 'duration': 9,
26 'view_count': int,
27 }
28 }
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32 webpage = self._download_webpage(url, video_id)
33
34 token = self._html_search_regex(
35 r'<input name="__RequestVerificationToken".*?value="([^"]+)"',
36 webpage, 'request token')
37 token_data = [
38 ('fileId', video_id),
39 ('__RequestVerificationToken', token),
40 ]
41 req = compat_urllib_request.Request(
42 'http://minhateca.com.br/action/License/Download',
43 data=compat_urllib_parse.urlencode(token_data))
44 req.add_header('Content-Type', 'application/x-www-form-urlencoded')
45 data = self._download_json(
46 req, video_id, note='Downloading metadata')
47
48 video_url = data['redirectUrl']
49 title_str = self._html_search_regex(
50 r'<h1.*?>(.*?)</h1>', webpage, 'title')
51 title, _, ext = title_str.rpartition('.')
52 filesize_approx = parse_filesize(self._html_search_regex(
53 r'<p class="fileSize">(.*?)</p>',
54 webpage, 'file size approximation', fatal=False))
55 duration = int_or_none(self._html_search_regex(
56 r'(?s)<p class="fileLeng[ht][th]">.*?([0-9]+)\s*s',
57 webpage, 'duration', fatal=False))
58 view_count = int_or_none(self._html_search_regex(
59 r'<p class="downloadsCounter">([0-9]+)</p>',
60 webpage, 'view count', fatal=False))
61
62 return {
63 'id': video_id,
64 'url': video_url,
65 'title': title,
66 'ext': ext,
67 'filesize_approx': filesize_approx,
68 'duration': duration,
69 'view_count': view_count,
70 'thumbnail': self._og_search_thumbnail(webpage),
71 }