]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/openrec.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
13 from ..compat
import compat_str
16 class OpenRecBaseIE(InfoExtractor
):
17 def _extract_pagestore(self
, webpage
, video_id
):
18 return self
._parse
_json
(
19 self
._search
_regex
(r
'(?m)window\.pageStore\s*=\s*(\{.+?\});$', webpage
, 'window.pageStore'), video_id
)
21 def _extract_movie(self
, webpage
, video_id
, name
, is_live
):
22 window_stores
= self
._extract
_pagestore
(webpage
, video_id
)
24 # extract all three important data (most of data are duplicated each other, but slightly different!)
25 traverse_obj(window_stores
, ('v8', 'state', 'movie'), expected_type
=dict),
26 traverse_obj(window_stores
, ('v8', 'movie'), expected_type
=dict),
27 traverse_obj(window_stores
, 'movieStore', expected_type
=dict),
29 if not any(movie_stores
):
30 raise ExtractorError(f
'Failed to extract {name} info')
32 m3u8_playlists
= get_first(movie_stores
, 'media') or {}
34 for name
, m3u8_url
in m3u8_playlists
.items():
37 formats
.extend(self
._extract
_m
3u8_formats
(
38 m3u8_url
, video_id
, ext
='mp4', live
=is_live
, m3u8_id
=name
))
40 self
._sort
_formats
(formats
)
44 'title': get_first(movie_stores
, 'title'),
45 'description': get_first(movie_stores
, 'introduction'),
46 'thumbnail': get_first(movie_stores
, 'thumbnailUrl'),
48 'uploader': get_first(movie_stores
, ('channel', 'user', 'name')),
49 'uploader_id': get_first(movie_stores
, ('channel', 'user', 'id')),
50 'timestamp': int_or_none(get_first(movie_stores
, ['publishedAt', 'time']), scale
=1000) or unified_timestamp(get_first(movie_stores
, 'publishedAt')),
55 class OpenRecIE(OpenRecBaseIE
):
57 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/live/(?P<id>[^/]+)'
59 'url': 'https://www.openrec.tv/live/2p8v31qe4zy',
60 'only_matching': True,
62 'url': 'https://www.openrec.tv/live/wez93eqvjzl',
63 'only_matching': True,
66 def _real_extract(self
, url
):
67 video_id
= self
._match
_id
(url
)
68 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/live/{video_id}', video_id
)
70 return self
._extract
_movie
(webpage
, video_id
, 'live', True)
73 class OpenRecCaptureIE(OpenRecBaseIE
):
74 IE_NAME
= 'openrec:capture'
75 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/capture/(?P<id>[^/]+)'
77 'url': 'https://www.openrec.tv/capture/l9nk2x4gn14',
78 'only_matching': True,
80 'url': 'https://www.openrec.tv/capture/mldjr82p7qk',
83 'title': 'たいじの恥ずかしい英語力',
84 'uploader': 'たいちゃんねる',
85 'uploader_id': 'Yaritaiji',
86 'upload_date': '20210803',
90 def _real_extract(self
, url
):
91 video_id
= self
._match
_id
(url
)
92 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/capture/{video_id}', video_id
)
94 window_stores
= self
._extract
_pagestore
(webpage
, video_id
)
95 movie_store
= window_stores
.get('movie')
97 capture_data
= window_stores
.get('capture')
99 raise ExtractorError('Cannot extract title')
101 formats
= self
._extract
_m
3u8_formats
(
102 capture_data
.get('source'), video_id
, ext
='mp4')
103 self
._sort
_formats
(formats
)
107 'title': capture_data
.get('title'),
108 'thumbnail': capture_data
.get('thumbnailUrl'),
110 'timestamp': unified_timestamp(traverse_obj(movie_store
, 'createdAt', expected_type
=compat_str
)),
111 'uploader': traverse_obj(movie_store
, ('channel', 'name'), expected_type
=compat_str
),
112 'uploader_id': traverse_obj(movie_store
, ('channel', 'id'), expected_type
=compat_str
),
113 'upload_date': unified_strdate(capture_data
.get('createdAt')),
117 class OpenRecMovieIE(OpenRecBaseIE
):
118 IE_NAME
= 'openrec:movie'
119 _VALID_URL
= r
'https?://(?:www\.)?openrec\.tv/movie/(?P<id>[^/]+)'
121 'url': 'https://www.openrec.tv/movie/nqz5xl5km8v',
124 'title': '限定コミュニティ(Discord)参加方法ご説明動画',
125 'description': 'md5:ebd563e5f5b060cda2f02bf26b14d87f',
126 'thumbnail': r
're:https://.+',
127 'uploader': 'タイキとカズヒロ',
128 'uploader_id': 'taiki_to_kazuhiro',
129 'timestamp': 1638856800,
133 def _real_extract(self
, url
):
134 video_id
= self
._match
_id
(url
)
135 webpage
= self
._download
_webpage
(f
'https://www.openrec.tv/movie/{video_id}', video_id
)
137 return self
._extract
_movie
(webpage
, video_id
, 'movie', False)