]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/streamcloud.py
[utils] Move base62 to utils
[youtube-dl] / youtube_dl / extractor / streamcloud.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_parse
8 from ..utils import sanitized_Request
9
10
11 class StreamcloudIE(InfoExtractor):
12     IE_NAME = 'streamcloud.eu'
13     _VALID_URL = r'https?://streamcloud\.eu/(?P<id>[a-zA-Z0-9_-]+)(?:/(?P<fname>[^#?]*)\.html)?'
14
15     _TEST = {
16         'url': 'http://streamcloud.eu/skp9j99s4bpz/youtube-dl_test_video_____________-BaW_jenozKc.mp4.html',
17         'md5': '6bea4c7fa5daaacc2a946b7146286686',
18         'info_dict': {
19             'id': 'skp9j99s4bpz',
20             'ext': 'mp4',
21             'title': 'youtube-dl test video  \'/\\ ä ↭',
22         },
23         'skip': 'Only available from the EU'
24     }
25
26     def _real_extract(self, url):
27         video_id = self._match_id(url)
28         url = 'http://streamcloud.eu/%s' % video_id
29
30         orig_webpage = self._download_webpage(url, video_id)
31
32         fields = re.findall(r'''(?x)<input\s+
33             type="(?:hidden|submit)"\s+
34             name="([^"]+)"\s+
35             (?:id="[^"]+"\s+)?
36             value="([^"]*)"
37             ''', orig_webpage)
38         post = compat_urllib_parse.urlencode(fields)
39
40         self._sleep(12, video_id)
41         headers = {
42             b'Content-Type': b'application/x-www-form-urlencoded',
43         }
44         req = sanitized_Request(url, post, headers)
45
46         webpage = self._download_webpage(
47             req, video_id, note='Downloading video page ...')
48         title = self._html_search_regex(
49             r'<h1[^>]*>([^<]+)<', webpage, 'title')
50         video_url = self._search_regex(
51             r'file:\s*"([^"]+)"', webpage, 'video URL')
52         thumbnail = self._search_regex(
53             r'image:\s*"([^"]+)"', webpage, 'thumbnail URL', fatal=False)
54
55         return {
56             'id': video_id,
57             'title': title,
58             'url': video_url,
59             'thumbnail': thumbnail,
60         }