Skip to content

Commit

Permalink
Fix --extract-audio on Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
phihag committed Dec 16, 2012
1 parent b375c8b commit 5910e21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions youtube_dl/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def get_audio_codec(self, path):
if not self._exes['ffprobe'] and not self._exes['avprobe']: return None
try:
cmd = [self._exes['avprobe'] or self._exes['ffprobe'], '-show_streams', '--', encodeFilename(path)]
handle = subprocess.Popen(cmd, stderr=file(os.path.devnull, 'w'), stdout=subprocess.PIPE)
handle = subprocess.Popen(cmd, stderr=compat_subprocess_get_DEVNULL(), stdout=subprocess.PIPE)
output = handle.communicate()[0]
if handle.wait() != 0:
return None
except (IOError, OSError):
return None
audio_codec = None
for line in output.split('\n'):
for line in output.decode('ascii', 'ignore').split('\n'):
if line.startswith('codec_name='):
audio_codec = line.split('=')[1].strip()
elif line.strip() == 'codec_type=audio' and audio_codec is not None:
Expand Down
6 changes: 6 additions & 0 deletions youtube_dl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
except ImportError: # Python 2
import httplib as compat_http_client

try:
from subprocess import DEVNULL
compat_subprocess_get_DEVNULL = lambda: DEVNULL
except ImportError:
compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')

try:
from urllib.parse import parse_qs as compat_parse_qs
except ImportError: # Python 2
Expand Down

0 comments on commit 5910e21

Please sign in to comment.