2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..downloader
.websocket
import has_websockets
26 class TwitCastingIE(InfoExtractor
):
27 _VALID_URL
= r
'https?://(?:[^/]+\.)?twitcasting\.tv/(?P<uploader_id>[^/]+)/(?:movie|twplayer)/(?P<id>\d+)'
29 'Origin': 'https://twitcasting.tv',
30 'Referer': 'https://twitcasting.tv/',
33 'url': 'https://twitcasting.tv/ivetesangalo/movie/2357609',
34 'md5': '745243cad58c4681dc752490f7540d7f',
38 'title': 'Live #2357609',
39 'uploader_id': 'ivetesangalo',
40 'description': 'Twitter Oficial da cantora brasileira Ivete Sangalo.',
41 'thumbnail': r
're:^https?://.*\.jpg$',
42 'upload_date': '20110822',
43 'timestamp': 1314010824,
48 'skip_download': True,
51 'url': 'https://twitcasting.tv/mttbernardini/movie/3689740',
55 'title': 'Live playing something #3689740',
56 'uploader_id': 'mttbernardini',
57 'description': 'Salve, io sono Matto (ma con la e). Questa è la mia presentazione, in quanto sono letteralmente matto (nel senso di strano), con qualcosa in più.',
58 'thumbnail': r
're:^https?://.*\.jpg$',
59 'upload_date': '20120212',
60 'timestamp': 1329028024,
65 'skip_download': True,
66 'videopassword': 'abc',
69 'note': 'archive is split in 2 parts',
70 'url': 'https://twitcasting.tv/loft_heaven/movie/685979292',
74 'title': '南波一海のhear_here “ナタリー望月哲さんに聞く編集と「渋谷系狂騒曲」”',
75 'duration': 6964.599334,
77 'playlist_mincount': 2,
80 def _real_extract(self
, url
):
81 uploader_id
, video_id
= self
._match
_valid
_url
(url
).groups()
83 video_password
= self
.get_param('videopassword')
86 request_data
= urlencode_postdata({
87 'password': video_password
,
89 webpage
, urlh
= self
._download
_webpage
_handle
(
90 url
, video_id
, data
=request_data
,
91 headers
={'Origin': 'https://twitcasting.tv'}
)
92 if urlh
.geturl() != url
and request_data
:
93 webpage
= self
._download
_webpage
(
94 urlh
.geturl(), video_id
, data
=request_data
,
95 headers
={'Origin': 'https://twitcasting.tv'}
,
96 note
='Retrying authentication')
98 title
= (clean_html(get_element_by_id('movietitle', webpage
))
99 or self
._html
_search
_meta
(['og:title', 'twitter:title'], webpage
, fatal
=True))
101 video_js_data
= try_get(
103 lambda x
: self
._parse
_json
(self
._search
_regex
(
104 r
'data-movie-playlist=\'([^
\']+?
)\'',
105 x, 'movie playlist
', default=None), video_id)['2'], list)
107 thumbnail = traverse_obj(video_js_data, (0, 'thumbnailUrl
')) or self._og_search_thumbnail(webpage)
108 description = clean_html(get_element_by_id(
109 'authorcomment
', webpage)) or self._html_search_meta(
110 ['description
', 'og
:description
', 'twitter
:description
'], webpage)
111 duration = (try_get(video_js_data, lambda x: sum(float_or_none(y.get('duration
')) for y in x) / 1000)
112 or parse_duration(clean_html(get_element_by_class('tw
-player
-duration
-time
', webpage))))
113 view_count = str_to_int(self._search_regex(
114 (r'Total\s
*:\s
*([\d
,]+)\s
*Views
', r'総視聴者\s
*:\s
*([\d
,]+)\s
*</'), webpage, 'views
', None))
115 timestamp = unified_timestamp(self._search_regex(
116 r'data
-toggle
="true"[^
>]+datetime
="([^"]+)"',
117 webpage, 'datetime', None))
119 stream_server_data = self._download_json(
120 'https://twitcasting.tv/streamserver.php?target=%s&mode=client' % uploader_id, video_id,
121 'Downloading live info', fatal=False)
123 is_live = 'data-status="online
"' in webpage
124 if not traverse_obj(stream_server_data, 'llfmp4') and is_live:
125 self.raise_login_required(method='cookies')
129 'description': description,
130 'thumbnail': thumbnail,
131 'timestamp': timestamp,
132 'uploader_id': uploader_id,
133 'duration': duration,
134 'view_count': view_count,
139 data_movie_url = self._search_regex(
140 r'data-movie-url=(["\'])(?P
<url
>(?
:(?
!\
1).)+)\
1',
141 x, 'm3u8 url
', group='url
', default=None)
143 return [data_movie_url]
145 m3u8_urls = (try_get(webpage, find_dmu, list)
146 or traverse_obj(video_js_data, (..., 'source
', 'url
'))
147 or ([f'https
://twitcasting
.tv
/{uploader_id}
/metastream
.m3u8
'] if is_live else None))
149 raise ExtractorError('Failed to get m3u8 playlist
')
152 m3u8_url = m3u8_urls[0]
153 formats = self._extract_m3u8_formats(
154 m3u8_url, video_id, ext='mp4
', m3u8_id='hls
',
155 live=True, headers=self._M3U8_HEADERS)
157 if traverse_obj(stream_server_data, ('hls
', 'source
')):
158 formats.extend(self._extract_m3u8_formats(
159 m3u8_url, video_id, ext='mp4
', m3u8_id='source
',
160 live=True, query={'mode': 'source'},
161 note='Downloading source quality m3u8
',
162 headers=self._M3U8_HEADERS, fatal=False))
165 qq = qualities(['base
', 'mobilesource
', 'main
'])
166 streams = traverse_obj(stream_server_data, ('llfmp4
', 'streams
')) or {}
167 for mode, ws_url in streams.items():
170 'format_id
': 'ws
-%s' % mode,
173 'source_preference
': -10,
174 # TwitCasting simply sends moof atom directly over WS
175 'protocol
': 'websocket_frag
',
178 self._sort_formats(formats, ('source
',))
185 '_type
': 'multi_video
',
187 'id': f'{video_id}
-{num}
',
190 # Requesting the manifests here will cause download to fail.
191 # So use ffmpeg instead. See: https://github.com/yt-dlp/yt-dlp/issues/382
193 'http_headers
': self._M3U8_HEADERS,
195 } for (num, m3u8_url) in enumerate(m3u8_urls)],
205 class TwitCastingLiveIE(InfoExtractor):
206 _VALID_URL = r'https?
://(?
:[^
/]+\
.)?twitcasting\
.tv
/(?P
<id>[^
/]+)/?
(?
:[#?]|$)'
208 'url': 'https://twitcasting.tv/ivetesangalo',
209 'only_matching': True,
212 def _real_extract(self
, url
):
213 uploader_id
= self
._match
_id
(url
)
215 'Downloading live video of user {0}. '
216 'Pass "https://twitcasting.tv/{0}/show" to download the history'.format(uploader_id
))
218 webpage
= self
._download
_webpage
(url
, uploader_id
)
219 current_live
= self
._search
_regex
(
220 (r
'data-type="movie" data-id="(\d+)">',
221 r
'tw-sound-flag-open-link" data-id="(\d+)" style=',),
222 webpage
, 'current live ID', default
=None)
224 # fetch unfiltered /show to find running livestreams; we can't get ID of the password-protected livestream above
225 webpage
= self
._download
_webpage
(
226 f
'https://twitcasting.tv/{uploader_id}/show/', uploader_id
,
227 note
='Downloading live history')
228 is_live
= self
._search
_regex
(r
'(?s)(<span\s*class="tw-movie-thumbnail-badge"\s*data-status="live">\s*LIVE)', webpage
, 'is live?', default
=None)
230 # get the first live; running live is always at the first
231 current_live
= self
._search
_regex
(
232 r
'(?s)<a\s+class="tw-movie-thumbnail"\s*href="/[^/]+/movie/(?P<video_id>\d+)"\s*>.+?</a>',
233 webpage
, 'current live ID 2', default
=None, group
='video_id')
235 raise ExtractorError('The user is not currently live')
236 return self
.url_result('https://twitcasting.tv/%s/movie/%s' % (uploader_id
, current_live
))
239 class TwitCastingUserIE(InfoExtractor
):
240 _VALID_URL
= r
'https?://(?:[^/]+\.)?twitcasting\.tv/(?P<id>[^/]+)/show/?(?:[#?]|$)'
242 'url': 'https://twitcasting.tv/noriyukicas/show',
243 'only_matching': True,
246 def _entries(self
, uploader_id
):
247 base_url
= next_url
= 'https://twitcasting.tv/%s/show' % uploader_id
248 for page_num
in itertools
.count(1):
249 webpage
= self
._download
_webpage
(
250 next_url
, uploader_id
, query
={'filter': 'watchable'}
, note
='Downloading page %d' % page_num
)
251 matches
= re
.finditer(
252 r
'''(?isx)<a\s+class="tw-movie-thumbnail"\s*href="(?P<url>/[^/]+/movie/\d+)"\s*>.+?</a>''',
255 yield self
.url_result(urljoin(base_url
, mobj
.group('url')))
257 next_url
= self
._search
_regex
(
258 r
'<a href="(/%s/show/%d-\d+)[?"]' % (re
.escape(uploader_id
), page_num
),
259 webpage
, 'next url', default
=None)
260 next_url
= urljoin(base_url
, next_url
)
264 def _real_extract(self
, url
):
265 uploader_id
= self
._match
_id
(url
)
266 return self
.playlist_result(
267 self
._entries
(uploader_id
), uploader_id
, '%s - Live History' % uploader_id
)