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