]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mixch.py
[mixch] Add `MixchArchiveIE` (#2373)
[yt-dlp.git] / yt_dlp / extractor / mixch.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 traverse_obj,
7 )
8
9
10 class MixchIE(InfoExtractor):
11 IE_NAME = 'mixch'
12 _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)'
13
14 _TESTS = [{
15 'url': 'https://mixch.tv/u/16236849/live',
16 'skip': 'don\'t know if this live persists',
17 'info_dict': {
18 'id': '16236849',
19 'title': '24配信シェア⭕️投票🙏💦',
20 'comment_count': 13145,
21 'view_count': 28348,
22 'timestamp': 1636189377,
23 'uploader': '🦥伊咲👶🏻#フレアワ',
24 'uploader_id': '16236849',
25 }
26 }, {
27 'url': 'https://mixch.tv/u/16137876/live',
28 'only_matching': True,
29 }]
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 webpage = self._download_webpage(f'https://mixch.tv/u/{video_id}/live', video_id)
34
35 initial_js_state = self._parse_json(self._search_regex(
36 r'(?m)^\s*window\.__INITIAL_JS_STATE__\s*=\s*(\{.+?\});\s*$', webpage, 'initial JS state'), video_id)
37 if not initial_js_state.get('liveInfo'):
38 raise ExtractorError('Livestream has ended.', expected=True)
39
40 return {
41 'id': video_id,
42 'title': traverse_obj(initial_js_state, ('liveInfo', 'title')),
43 'comment_count': traverse_obj(initial_js_state, ('liveInfo', 'comments')),
44 'view_count': traverse_obj(initial_js_state, ('liveInfo', 'visitor')),
45 'timestamp': traverse_obj(initial_js_state, ('liveInfo', 'created')),
46 'uploader': traverse_obj(initial_js_state, ('broadcasterInfo', 'name')),
47 'uploader_id': video_id,
48 'formats': [{
49 'format_id': 'hls',
50 'url': traverse_obj(initial_js_state, ('liveInfo', 'hls')) or 'https://d1hd0ww6piyb43.cloudfront.net/hls/torte_%s.m3u8' % video_id,
51 'ext': 'mp4',
52 'protocol': 'm3u8',
53 }],
54 'is_live': True,
55 }
56
57
58 class MixchArchiveIE(InfoExtractor):
59 IE_NAME = 'mixch:archive'
60 _VALID_URL = r'https?://(?:www\.)?mixch\.tv/archive/(?P<id>\d+)'
61
62 _TESTS = [{
63 'url': 'https://mixch.tv/archive/421',
64 'skip': 'paid video, no DRM. expires at Jan 23',
65 'info_dict': {
66 'id': '421',
67 'title': '96NEKO SHOW TIME',
68 }
69 }]
70
71 def _real_extract(self, url):
72 video_id = self._match_id(url)
73 webpage = self._download_webpage(url, video_id)
74
75 html5_videos = self._parse_html5_media_entries(
76 url, webpage.replace('video-js', 'video'), video_id, 'hls')
77 if not html5_videos:
78 self.raise_login_required(method='cookies')
79 infodict = html5_videos[0]
80 infodict.update({
81 'id': video_id,
82 'title': self._html_search_regex(r'class="archive-title">(.+?)</', webpage, 'title')
83 })
84
85 return infodict