]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/streamcloud.py
Implemented all Youtube Feeds (ytfav, ytwatchlater, ytsubs, ythistory, ytrec) and...
[yt-dlp.git] / youtube_dlc / extractor / streamcloud.py
CommitLineData
02e4ebbb 1# coding: utf-8
71aa656d
S
2from __future__ import unicode_literals
3
02e4ebbb 4import re
02e4ebbb
PH
5
6from .common import InfoExtractor
6e6bc8da 7from ..utils import (
84dcd1c4 8 ExtractorError,
6e6bc8da
S
9 urlencode_postdata,
10)
02e4ebbb
PH
11
12
13class StreamcloudIE(InfoExtractor):
71aa656d 14 IE_NAME = 'streamcloud.eu'
3c6af203 15 _VALID_URL = r'https?://streamcloud\.eu/(?P<id>[a-zA-Z0-9_-]+)(?:/(?P<fname>[^#?]*)\.html)?'
02e4ebbb 16
84dcd1c4 17 _TESTS = [{
cefecac1 18 'url': 'http://streamcloud.eu/skp9j99s4bpz/youtube-dlc_test_video_____________-BaW_jenozKc.mp4.html',
71aa656d
S
19 'md5': '6bea4c7fa5daaacc2a946b7146286686',
20 'info_dict': {
21 'id': 'skp9j99s4bpz',
22 'ext': 'mp4',
cefecac1 23 'title': 'youtube-dlc test video \'/\\ ä ↭',
02e4ebbb 24 },
71aa656d 25 'skip': 'Only available from the EU'
84dcd1c4
S
26 }, {
27 'url': 'http://streamcloud.eu/ua8cmfh1nbe6/NSHIP-148--KUC-NG--H264-.mp4.html',
28 'only_matching': True,
29 }]
02e4ebbb
PH
30
31 def _real_extract(self, url):
3c6af203
NJ
32 video_id = self._match_id(url)
33 url = 'http://streamcloud.eu/%s' % video_id
02e4ebbb
PH
34
35 orig_webpage = self._download_webpage(url, video_id)
36
84dcd1c4
S
37 if '>File Not Found<' in orig_webpage:
38 raise ExtractorError(
39 'Video %s does not exist' % video_id, expected=True)
40
02e4ebbb
PH
41 fields = re.findall(r'''(?x)<input\s+
42 type="(?:hidden|submit)"\s+
43 name="([^"]+)"\s+
44 (?:id="[^"]+"\s+)?
45 value="([^"]*)"
46 ''', orig_webpage)
02e4ebbb 47
186d185b 48 self._sleep(6, video_id)
02e4ebbb
PH
49
50 webpage = self._download_webpage(
feef925f
S
51 url, video_id, data=urlencode_postdata(fields), headers={
52 b'Content-Type': b'application/x-www-form-urlencoded',
53 })
54
55 try:
56 title = self._html_search_regex(
57 r'<h1[^>]*>([^<]+)<', webpage, 'title')
58 video_url = self._search_regex(
59 r'file:\s*"([^"]+)"', webpage, 'video URL')
60 except ExtractorError:
61 message = self._html_search_regex(
62 r'(?s)<div[^>]+class=(["\']).*?msgboxinfo.*?\1[^>]*>(?P<message>.+?)</div>',
63 webpage, 'message', default=None, group='message')
64 if message:
65 raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
66 raise
02e4ebbb 67 thumbnail = self._search_regex(
71aa656d 68 r'image:\s*"([^"]+)"', webpage, 'thumbnail URL', fatal=False)
02e4ebbb
PH
69
70 return {
71 'id': video_id,
72 'title': title,
73 'url': video_url,
02e4ebbb 74 'thumbnail': thumbnail,
b5dec62c
S
75 'http_headers': {
76 'Referer': url,
77 },
02e4ebbb 78 }