]> jfr.im git - yt-dlp.git/blame - yt_dlp/downloader/fc2.py
[downloader/fragment] Make single thread download work for --live-from-start (#3446)
[yt-dlp.git] / yt_dlp / downloader / fc2.py
CommitLineData
15dfb392
LNO
1import threading
2
3from .common import FileDownloader
4from .external import FFmpegFD
5
6
7class FC2LiveFD(FileDownloader):
8 """
9 Downloads FC2 live without being stopped. <br>
10 Note, this is not a part of public API, and will be removed without notice.
11 DO NOT USE
12 """
13
14 def real_download(self, filename, info_dict):
15 ws = info_dict['ws']
16
17 heartbeat_lock = threading.Lock()
18 heartbeat_state = [None, 1]
19
20 def heartbeat():
21 try:
22 heartbeat_state[1] += 1
23 ws.send('{"name":"heartbeat","arguments":{},"id":%d}' % heartbeat_state[1])
24 except Exception:
25 self.to_screen('[fc2:live] Heartbeat failed')
26
27 with heartbeat_lock:
28 heartbeat_state[0] = threading.Timer(30, heartbeat)
29 heartbeat_state[0]._daemonic = True
30 heartbeat_state[0].start()
31
32 heartbeat()
33
34 new_info_dict = info_dict.copy()
35 new_info_dict.update({
36 'ws': None,
37 'protocol': 'live_ffmpeg',
38 })
39 return FFmpegFD(self.ydl, self.params or {}).download(filename, new_info_dict)