[downloader/rtmp] Gracefully handle live streams interrupted by user
This commit is contained in:
parent
68217024e8
commit
ddd8486a44
1 changed files with 66 additions and 53 deletions
|
@ -24,10 +24,12 @@ class RtmpFD(FileDownloader):
|
||||||
def real_download(self, filename, info_dict):
|
def real_download(self, filename, info_dict):
|
||||||
def run_rtmpdump(args):
|
def run_rtmpdump(args):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
resume_percent = None
|
|
||||||
resume_downloaded_data_len = None
|
|
||||||
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
|
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
|
||||||
cursor_in_new_line = True
|
cursor_in_new_line = True
|
||||||
|
|
||||||
|
def dl():
|
||||||
|
resume_percent = None
|
||||||
|
resume_downloaded_data_len = None
|
||||||
proc_stderr_closed = False
|
proc_stderr_closed = False
|
||||||
while not proc_stderr_closed:
|
while not proc_stderr_closed:
|
||||||
# read line from stderr
|
# read line from stderr
|
||||||
|
@ -88,7 +90,12 @@ class RtmpFD(FileDownloader):
|
||||||
self.to_screen('')
|
self.to_screen('')
|
||||||
cursor_in_new_line = True
|
cursor_in_new_line = True
|
||||||
self.to_screen('[rtmpdump] ' + line)
|
self.to_screen('[rtmpdump] ' + line)
|
||||||
|
|
||||||
|
try:
|
||||||
|
dl()
|
||||||
|
finally:
|
||||||
proc.wait()
|
proc.wait()
|
||||||
|
|
||||||
if not cursor_in_new_line:
|
if not cursor_in_new_line:
|
||||||
self.to_screen('')
|
self.to_screen('')
|
||||||
return proc.returncode
|
return proc.returncode
|
||||||
|
@ -163,7 +170,13 @@ class RtmpFD(FileDownloader):
|
||||||
RD_INCOMPLETE = 2
|
RD_INCOMPLETE = 2
|
||||||
RD_NO_CONNECT = 3
|
RD_NO_CONNECT = 3
|
||||||
|
|
||||||
|
try:
|
||||||
retval = run_rtmpdump(args)
|
retval = run_rtmpdump(args)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
if not info_dict.get('is_live'):
|
||||||
|
raise
|
||||||
|
retval = RD_SUCCESS
|
||||||
|
self.to_screen('\n[rtmpdump] Interrupted by user')
|
||||||
|
|
||||||
if retval == RD_NO_CONNECT:
|
if retval == RD_NO_CONNECT:
|
||||||
self.report_error('[rtmpdump] Could not connect to RTMP server.')
|
self.report_error('[rtmpdump] Could not connect to RTMP server.')
|
||||||
|
|
Loading…
Reference in a new issue