Release 2024.07.16
[yt-dlp.git] / yt_dlp / downloader / fc2.py
blobf9763debbe831018da64bb780611150f67cb599a
1 import threading
3 from .common import FileDownloader
4 from .external import FFmpegFD
7 class 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 """
14 def real_download(self, filename, info_dict):
15 ws = info_dict['ws']
17 heartbeat_lock = threading.Lock()
18 heartbeat_state = [None, 1]
20 def heartbeat():
21 if heartbeat_state[1] < 0:
22 return
24 try:
25 heartbeat_state[1] += 1
26 ws.send('{"name":"heartbeat","arguments":{},"id":%d}' % heartbeat_state[1])
27 except Exception:
28 self.to_screen('[fc2:live] Heartbeat failed')
30 with heartbeat_lock:
31 heartbeat_state[0] = threading.Timer(30, heartbeat)
32 heartbeat_state[0]._daemonic = True
33 heartbeat_state[0].start()
35 heartbeat()
37 new_info_dict = info_dict.copy()
38 new_info_dict.update({
39 'ws': None,
40 'protocol': 'live_ffmpeg',
42 try:
43 return FFmpegFD(self.ydl, self.params or {}).download(filename, new_info_dict)
44 finally:
45 # stop heartbeating
46 heartbeat_state[1] = -1