Skip to content

Commit

Permalink
[downloader/rtmp] Fix arguments encoding and simplify retry logic (Cl…
Browse files Browse the repository at this point in the history
…oses #5528)
  • Loading branch information
dstftw committed Apr 25, 2015
1 parent cd8a07a commit 9e105a8
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions youtube_dl/downloader/rtmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import os
import re
import subprocess
import sys
import time

from .common import FileDownloader
from ..compat import compat_str
from ..utils import (
check_executable,
encodeFilename,
encodeArgument,
get_exe_version,
)

Expand Down Expand Up @@ -121,7 +121,7 @@ def run_rtmpdump(args):
# possible. This is part of rtmpdump's normal usage, AFAIK.
basic_args = [
'rtmpdump', '--verbose', '-r', url,
'-o', encodeFilename(tmpfilename, True)]
'-o', tmpfilename]
if player_url is not None:
basic_args += ['--swfVfy', player_url]
if page_url is not None:
Expand Down Expand Up @@ -154,16 +154,9 @@ def run_rtmpdump(args):
if not live and continue_dl:
args += ['--skip', '1']

if sys.platform == 'win32' and sys.version_info < (3, 0):
# Windows subprocess module does not actually support Unicode
# on Python 2.x
# See http://stackoverflow.com/a/9951851/35070
subprocess_encoding = sys.getfilesystemencoding()
args = [a.encode(subprocess_encoding, 'ignore') for a in args]
else:
subprocess_encoding = None
args = [encodeArgument(a) for a in args]

self._debug_cmd(args, subprocess_encoding, exe='rtmpdump')
self._debug_cmd(args, exe='rtmpdump')

RD_SUCCESS = 0
RD_FAILED = 1
Expand All @@ -180,7 +173,11 @@ def run_rtmpdump(args):
prevsize = os.path.getsize(encodeFilename(tmpfilename))
self.to_screen('[rtmpdump] %s bytes' % prevsize)
time.sleep(5.0) # This seems to be needed
retval = run_rtmpdump(basic_args + ['-e'] + [[], ['-k', '1']][retval == RD_FAILED])
args = basic_args + ['--resume']
if retval == RD_FAILED:
args += ['--skip', '1']
args = [encodeArgument(a) for a in args]
retval = run_rtmpdump(args)
cursize = os.path.getsize(encodeFilename(tmpfilename))
if prevsize == cursize and retval == RD_FAILED:
break
Expand Down

0 comments on commit 9e105a8

Please sign in to comment.