]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/wasdtv.py
bf1ad65b233d66cc2fbe1b6bed63205e6ee7705a
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')
40 self
._sort
_formats
(formats
)
43 'title': container
.get('media_container_name') or self
._og
_search
_title
(self
._download
_webpage
(url
, video_id
)),
44 'description': container
.get('media_container_description'),
45 'thumbnails': self
._extract
_thumbnails
(media_meta
.get('media_preview_images')),
46 'timestamp': parse_iso8601(container
.get('created_at')),
47 'view_count': int_or_none(stream
.get('stream_current_viewers' if is_live
else 'stream_total_viewers')),
50 'subtitles': subtitles
,
53 def _get_container(self
, url
):
54 raise NotImplementedError('Subclass for get media container')
56 def _get_media_url(self
, media_meta
):
57 raise NotImplementedError('Subclass for get media url')
60 class WASDTVStreamIE(WASDTVBaseIE
):
61 IE_NAME
= 'wasdtv:stream'
62 _VALID_URL
= r
'https?://wasd\.tv/(?P<id>[^/#?]+)$'
64 'url': 'https://wasd.tv/24_7',
68 'title': 'Live 24/7 Music',
69 'description': '24/7 Music',
71 'upload_date': r
're:^\d{8}$',
77 def _get_container(self
, url
):
78 nickname
= self
._match
_id
(url
)
79 channel
= self
._fetch
(f
'channels/nicknames/{nickname}', video_id
=nickname
, description
='channel')
80 channel_id
= channel
.get('channel_id')
81 containers
= self
._fetch
(
82 'v2/media-containers', channel_id
, 'running media containers',
84 'channel_id': channel_id
,
85 'media_container_type': 'SINGLE',
86 'media_container_status': 'RUNNING',
89 raise ExtractorError(f
'{nickname} is offline', expected
=True)
92 def _get_media_url(self
, media_meta
):
93 return media_meta
['media_url'], True
96 class WASDTVRecordIE(WASDTVBaseIE
):
97 IE_NAME
= 'wasdtv:record'
98 _VALID_URL
= r
'https?://wasd\.tv/[^/#?]+/videos\?record=(?P<id>\d+)$'
100 'url': 'https://wasd.tv/spacemita/videos?record=907755',
101 'md5': 'c9899dd85be4cc997816ff9f9ca516ce',
105 'title': 'Музыкальный',
106 'description': 'md5:f510388d929ff60ae61d4c3cab3137cc',
107 'timestamp': 1645812079,
108 'upload_date': '20220225',
109 'thumbnail': r
're:^https?://.+\.jpg',
115 def _get_container(self
, url
):
116 container_id
= self
._match
_id
(url
)
118 f
'v2/media-containers/{container_id}', container_id
, 'media container')
120 def _get_media_url(self
, media_meta
):
121 media_archive_url
= media_meta
.get('media_archive_url')
122 if media_archive_url
:
123 return media_archive_url
, False
124 return media_meta
['media_url'], True
127 class WASDTVClipIE(WASDTVBaseIE
):
128 IE_NAME
= 'wasdtv:clip'
129 _VALID_URL
= r
'https?://wasd\.tv/[^/#?]+/clips\?clip=(?P<id>\d+)$'
131 'url': 'https://wasd.tv/spacemita/clips?clip=26804',
132 'md5': '818885e720143d7a4e776ff66fcff148',
136 'title': 'Пуш флексит на голове стримера',
137 'timestamp': 1646682908,
138 'upload_date': '20220307',
139 'thumbnail': r
're:^https?://.+\.jpg',
144 def _real_extract(self
, url
):
145 clip_id
= self
._match
_id
(url
)
146 clip
= self
._fetch
(f
'v2/clips/{clip_id}', video_id
=clip_id
, description
='clip')
147 clip_data
= clip
.get('clip_data')
148 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(clip_data
.get('url'), video_id
=clip_id
, ext
='mp4')
149 self
._sort
_formats
(formats
)
152 'title': clip
.get('clip_title') or self
._og
_search
_title
(self
._download
_webpage
(url
, clip_id
, fatal
=False)),
153 'thumbnails': self
._extract
_thumbnails
(clip_data
.get('preview')),
154 'timestamp': parse_iso8601(clip
.get('created_at')),
155 'view_count': int_or_none(clip
.get('clip_views_count')),
157 'subtitles': subtitles
,