Skip to content

Commit

Permalink
Changed subprocess output handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
10se1ucgo committed Mar 13, 2016
1 parent facd15f commit a69d1df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ def run(self):
logger.debug("FFmpeg converter: Total converted so far: {total}".format(total=self.converted // 2))
logger.debug("FFmpeg converter: Remaining: {r}".format(r=len(self.songs) - self.converted // 2))
logger.debug("Converting {track} with params: rate: {rate} volume: {vol}".format(track=track,
rate=self.rate,
vol=self.vol))
convert = convert_audio(track, file, self.rate, self.vol)
if convert != 0:
rate=self.rate,
vol=self.vol))
try:
logger.info(convert_audio(track, file, self.rate, self.vol))
except subprocess.CalledProcessError:
errors.append(track)
# File's headers aren't stripped, which normally would increase self.converted by 1.
self.converted += 1
Expand Down Expand Up @@ -329,4 +330,4 @@ def convert_audio(file, dest, rate, vol, codec="pcm_s16le"):
# type: (str, any, any, any, any) -> int
cmd = '{ff} -y -i "{i}" -map_metadata -1 -ac 1 -aq 100 -acodec {codec} -ar {rate} -af volume={vol} "{dest}.wav"'
cmd = cmd.format(ff=find(), i=file, codec=codec, rate=rate, vol=vol / 100, dest=dest)
return subprocess.call(cmd)
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
10 changes: 5 additions & 5 deletions jam_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def write_configs(path, tracks, play_key, relay_key, use_aliases):
# Lazy debugging stuff:
# logger.write = lambda x: logger.debug(x)
# cfg = logger
with open(os.path.normpath(os.path.join(path, "cfg/jam.cfg")), 'w') as cfg:
with open(os.path.normpath(os.path.join(path, "cfg/jam.cfg")), 'w', errors='ignore') as cfg:
cfg.write('bind {play_key} jam_play\n'.format(play_key=play_key))
cfg.write('alias jam_play jam_on\n')
cfg.write('alias jam_on "voice_inputfromfile 1; voice_loopback 1; +voicerecord; alias jam_play jam_off"\n')
Expand Down Expand Up @@ -352,14 +352,14 @@ def write_configs(path, tracks, play_key, relay_key, use_aliases):
cfg.write('con_enable 1; showconsole\n')
cfg.write('echo "pyjam v{v} loaded. Type "la" or "jam_listaudio" for a list of tracks.\n'.format(v=__version__))
logger.info("Wrote jam.cfg to {path}".format(path=cfg.name))
with open(os.path.normpath(os.path.join(path, "cfg/jam_la.cfg")), 'w') as cfg:
with open(os.path.normpath(os.path.join(path, "cfg/jam_la.cfg")), 'w', errors='ignore') as cfg:
for x, track in enumerate(tracks):
cfg.write('echo "{x}. {name}. Aliases: {aliases}"\n'.format(x=x, name=track.name, aliases=track.aliases))
logger.info("Wrote jam_la.cfg to {path}".format(path=cfg.name))
with open(os.path.normpath(os.path.join(path, "cfg/jam_curtrack.cfg")), 'w') as cfg:
with open(os.path.normpath(os.path.join(path, "cfg/jam_curtrack.cfg")), 'w', errors='ignore') as cfg:
cfg.write('echo "pyjam :: No song loaded"\n')
logger.info("Wrote jam_curtrack.cfg to {path}".format(path=cfg.name))
with open(os.path.normpath(os.path.join(path, "cfg/jam_saycurtrack.cfg")), 'w') as cfg:
with open(os.path.normpath(os.path.join(path, "cfg/jam_saycurtrack.cfg")), 'w', errors='ignore') as cfg:
cfg.write('say "pyjam :: No song loaded"\n')
logger.info("Wrote jam_saycurtrack.cfg to {path}".format(path=cfg.name))

Expand Down Expand Up @@ -419,7 +419,7 @@ def filter_aliases(alias_or_name):
filtered_name += char.lower()
elif char in punctuation and not "'":
filtered_name += ' '
return filtered_name
return filtered_name.encode('ascii', 'ignore')


def get_steam_path():
Expand Down

0 comments on commit a69d1df

Please sign in to comment.