]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/shared.py
[twitch:stream] Add support for rebroadcasts (closes #10995)
[yt-dlp.git] / youtube_dl / extractor / shared.py
CommitLineData
916c1452
S
1from __future__ import unicode_literals
2
916c1452
S
3import base64
4
5from .common import InfoExtractor
6from ..utils import (
7 ExtractorError,
916c1452 8 int_or_none,
6e6bc8da 9 urlencode_postdata,
916c1452
S
10)
11
12
13class SharedIE(InfoExtractor):
70113c38 14 IE_DESC = 'shared.sx and vivo.sx'
5886b38d 15 _VALID_URL = r'https?://(?:shared|vivo)\.sx/(?P<id>[\da-z]{10})'
916c1452 16
f62e02c2 17 _TESTS = [{
916c1452 18 'url': 'http://shared.sx/0060718775',
32582633 19 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
916c1452
S
20 'info_dict': {
21 'id': '0060718775',
22 'ext': 'mp4',
32582633 23 'title': 'Bmp4',
f11c3163 24 'filesize': 1720110,
916c1452 25 },
f62e02c2
S
26 }, {
27 'url': 'http://vivo.sx/d7ddda0e78',
28 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
29 'info_dict': {
30 'id': 'd7ddda0e78',
31 'ext': 'mp4',
32 'title': 'Chicken',
33 'filesize': 528031,
34 },
35 }]
916c1452
S
36
37 def _real_extract(self, url):
1cc79574 38 video_id = self._match_id(url)
289a16b4
S
39
40 webpage, urlh = self._download_webpage_handle(url, video_id)
916c1452 41
1cc79574
PH
42 if '>File does not exist<' in webpage:
43 raise ExtractorError(
44 'Video %s does not exist' % video_id, expected=True)
916c1452 45
f8da79f8 46 download_form = self._hidden_inputs(webpage)
289a16b4 47
1cc79574 48 video_page = self._download_webpage(
05c8268c
S
49 urlh.geturl(), video_id, 'Downloading video page',
50 data=urlencode_postdata(download_form),
51 headers={
52 'Content-Type': 'application/x-www-form-urlencoded',
53 'Referer': urlh.geturl(),
54 })
916c1452 55
1cc79574 56 video_url = self._html_search_regex(
05c8268c
S
57 r'data-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
58 video_page, 'video URL', group='url')
1cc79574 59 title = base64.b64decode(self._html_search_meta(
43150d7a 60 'full:title', webpage, 'title').encode('utf-8')).decode('utf-8')
1cc79574
PH
61 filesize = int_or_none(self._html_search_meta(
62 'full:size', webpage, 'file size', fatal=False))
916c1452 63 thumbnail = self._html_search_regex(
05c8268c
S
64 r'data-poster=(["\'])(?P<url>(?:(?!\1).)+)\1',
65 video_page, 'thumbnail', default=None, group='url')
916c1452
S
66
67 return {
68 'id': video_id,
69 'url': video_url,
70 'ext': 'mp4',
71 'filesize': filesize,
72 'title': title,
73 'thumbnail': thumbnail,
5f6a1245 74 }