]>
Commit | Line | Data |
---|---|---|
15dfb392 LNO |
1 | import threading |
2 | ||
3 | from .common import FileDownloader | |
4 | from .external import FFmpegFD | |
5 | ||
6 | ||
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 | """ | |
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(): | |
69b59b4b L |
21 | if heartbeat_state[1] < 0: |
22 | return | |
23 | ||
15dfb392 LNO |
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') | |
29 | ||
30 | with heartbeat_lock: | |
31 | heartbeat_state[0] = threading.Timer(30, heartbeat) | |
32 | heartbeat_state[0]._daemonic = True | |
33 | heartbeat_state[0].start() | |
34 | ||
35 | heartbeat() | |
36 | ||
37 | new_info_dict = info_dict.copy() | |
38 | new_info_dict.update({ | |
39 | 'ws': None, | |
40 | 'protocol': 'live_ffmpeg', | |
41 | }) | |
69b59b4b L |
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 |