Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2012-08-31 17:21:48 -04:00
commit 886888a958
7 changed files with 102 additions and 74 deletions

View file

@ -161,6 +161,7 @@ class Metadata(Loggable):
# Forcing the unicode through
try : fpath = fpath.decode("utf-8")
except : pass
if not mmp.file_playable(fpath): raise BadSongFile(fpath)
try : full_mutagen = mutagen.File(fpath, easy=True)
except Exception : raise BadSongFile(fpath)
self.path = fpath

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import copy
import subprocess
import os
import shutil
import re
@ -449,6 +450,21 @@ def owner_id(original_path):
except Exception: raise
return owner_id
def file_playable(pathname):
#when there is an single apostrophe inside of a string quoted by
#apostrophes, we can only escape it by replace that apostrophe with '\''.
#This breaks the string into two, and inserts an escaped single quote in
#between them. We run the command as pypo because otherwise the target file
#is opened with write permissions, and this causes an inotify ON_CLOSE_WRITE
#event to be fired :/
command = ("sudo -u pypo airtime-liquidsoap -c 'output.dummy" + \
"(audio_to_stereo(single(\"%s\")))' > /dev/null 2>&1") % \
pathname.replace("'", "'\\''")
return_code = subprocess.call(command, shell=True)
return (return_code == 0)
if __name__ == '__main__':
import doctest
doctest.testmod()

View file

@ -87,34 +87,34 @@ def calculate_replay_gain(file_path):
temp_file_path = duplicate_file(file_path)
file_type = get_file_type(file_path)
nice_level = '15'
if file_type:
if file_type == 'mp3':
if run_process("which mp3gain > /dev/null") == 0:
out = get_process_output('mp3gain -q "%s" 2> /dev/null' % temp_file_path)
out = get_process_output('nice -n %s mp3gain -q "%s" 2> /dev/null' % (nice_level, temp_file_path))
search = re.search(r'Recommended "Track" dB change: (.*)', out)
else:
logger.warn("mp3gain not found")
elif file_type == 'vorbis':
if run_process("which vorbisgain > /dev/null && which ogginfo > /dev/null") == 0:
run_process('vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % temp_file_path)
run_process('nice -n %s vorbisgain -q -f "%s" 2>/dev/null >/dev/null' % (nice_level,temp_file_path))
out = get_process_output('ogginfo "%s"' % temp_file_path)
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
logger.warn("vorbisgain/ogginfo not found")
elif file_type == 'flac':
if run_process("which metaflac > /dev/null") == 0:
out = get_process_output('metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % temp_file_path)
out = get_process_output('nice -n %s metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "%s"' % (nice_level, temp_file_path))
search = re.search(r'REPLAYGAIN_TRACK_GAIN=(.*) dB', out)
else:
logger.warn("metaflac not found")
else:
pass
else: logger.warn("metaflac not found")
#no longer need the temp, file simply remove it.
os.remove(temp_file_path)
except Exception, e:
logger.error(str(e))
finally:
#no longer need the temp, file simply remove it.
try: os.remove(temp_file_path)
except: pass
replay_gain = 0
if search: