]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wasdtv.py
1 from .common
import InfoExtractor
11 class WASDTVBaseIE(InfoExtractor
):
13 def _fetch(self
, path
, video_id
, description
, query
={}):
14 response
= self
._download
_json
(
15 f
'https://wasd.tv/api/{path}', video_id
, query
=query
,
16 note
=f
'Downloading {description} metadata',
17 errnote
=f
'Unable to download {description} metadata')
18 error
= response
.get('error')
20 raise ExtractorError(f
'{self.IE_NAME} returned error: {error}', expected
=True)
21 return response
.get('result')
23 def _extract_thumbnails(self
, thumbnails_dict
):
27 } for index
, url
in enumerate(
28 traverse_obj(thumbnails_dict
, (('small', 'medium', 'large'),))) if url
]
30 def _real_extract(self
, url
):
31 container
= self
._get
_container
(url
)
32 stream
= traverse_obj(container
, ('media_container_streams', 0))
33 media
= try_get(stream
, lambda x
: x
['stream_media'][0])
35 raise ExtractorError('Can not extract media data.', expected
=True)
36 media_meta
= media
.get('media_meta')
37 media_url
, is_live
= self
._get
_media
_url
(media_meta
)
38 video_id
= media
.get('media_id') or container
.get('media_container_id')
39 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(media_url
, video_id
, 'mp4')
42 'title': container
.get('media_container_name') or self
._og
_search
_title
(self
._download
_webpage
(url
, video_id
)),
43 'description': container
.get('media_container_description'),
44 'thumbnails': self
._extract
_thumbnails
(media_meta
.get('media_preview_images')),
45 'timestamp': parse_iso8601(container
.get('created_at')),
46 'view_count': int_or_none(stream
.get('stream_current_viewers' if is_live
else 'stream_total_viewers')),
49 'subtitles': subtitles
,
52 def _get_container(self
, url
):
53 raise NotImplementedError('Subclass for get media container')
55 def _get_media_url(self
, media_meta
):
56 raise NotImplementedError('Subclass for get media url')
59 class WASDTVStreamIE(WASDTVBaseIE
):
60 IE_NAME
= 'wasdtv:stream'
61 _VALID_URL
= r
'https?://wasd\.tv/(?P<id>[^/#?]+)$'
63 'url': 'https://wasd.tv/24_7',
67 'title': 'Live 24/7 Music',
68 'description': '24/7 Music',
70 'upload_date': r
're:^\d{8}$',
76 def _get_container(self
, url
):
77 nickname
= self
._match
_id
(url
)
78 channel
= self
._fetch
(f
'channels/nicknames/{nickname}', video_id
=nickname
, description
='channel')
79 channel_id
= channel
.get('channel_id')
80 containers
= self
._fetch
(
81 'v2/media-containers', channel_id
, 'running media containers',
83 'channel_id': channel_id
,
84 'media_container_type': 'SINGLE',
85 'media_container_status': 'RUNNING',
88 raise ExtractorError(f
'{nickname} is offline', expected
=True)
91 def _get_media_url(self
, media_meta
):
92 return media_meta
['media_url'], True
95 class WASDTVRecordIE(WASDTVBaseIE
):
96 IE_NAME
= 'wasdtv:record'
97 _VALID_URL
= r
'https?://wasd\.tv/[^/#?]+(?:/videos)?\?record=(?P<id>\d+)$'
99 'url': 'https://wasd.tv/spacemita/videos?record=907755',
100 'md5': 'c9899dd85be4cc997816ff9f9ca516ce',
104 'title': 'Музыкальный',
105 'description': 'md5:f510388d929ff60ae61d4c3cab3137cc',
106 'timestamp': 1645812079,
107 'upload_date': '20220225',
108 'thumbnail': r
're:^https?://.+\.jpg',
113 'url': 'https://wasd.tv/spacemita?record=907755',
114 'only_matching': True,
117 def _get_container(self
, url
):
118 container_id
= self
._match
_id
(url
)
120 f
'v2/media-containers/{container_id}', container_id
, 'media container')
122 def _get_media_url(self
, media_meta
):
123 media_archive_url
= media_meta
.get('media_archive_url')
124 if media_archive_url
:
125 return media_archive_url
, False
126 return media_meta
['media_url'], True
129 class WASDTVClipIE(WASDTVBaseIE
):
130 IE_NAME
= 'wasdtv:clip'
131 _VALID_URL
= r
'https?://wasd\.tv/[^/#?]+/clips\?clip=(?P<id>\d+)$'
133 'url': 'https://wasd.tv/spacemita/clips?clip=26804',
134 'md5': '818885e720143d7a4e776ff66fcff148',
138 'title': 'Пуш флексит на голове стримера',
139 'timestamp': 1646682908,
140 'upload_date': '20220307',
141 'thumbnail': r
're:^https?://.+\.jpg',
146 def _real_extract(self
, url
):
147 clip_id
= self
._match
_id
(url
)
148 clip
= self
._fetch
(f
'v2/clips/{clip_id}', video_id
=clip_id
, description
='clip')
149 clip_data
= clip
.get('clip_data')
150 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(clip_data
.get('url'), video_id
=clip_id
, ext
='mp4')
153 'title': clip
.get('clip_title') or self
._og
_search
_title
(self
._download
_webpage
(url
, clip_id
, fatal
=False)),
154 'thumbnails': self
._extract
_thumbnails
(clip_data
.get('preview')),
155 'timestamp': parse_iso8601(clip
.get('created_at')),
156 'view_count': int_or_none(clip
.get('clip_views_count')),
158 'subtitles': subtitles
,