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