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