CC-430: Audio normalization (Replaygain Support)
make code simpler (don't download database to file)
This commit is contained in:
parent
0e98bc75c8
commit
b4f1cc13c0
6 changed files with 31 additions and 39 deletions
|
@ -12,10 +12,10 @@ import replaygain
|
|||
class ReplayGainUpdater(Thread):
|
||||
"""
|
||||
The purpose of the class is to query the server for a list of files which do not have a ReplayGain
|
||||
value calculated. This class will iterate over the list calculate the values, update the server and
|
||||
value calculated. This class will iterate over the list calculate the values, update the server and
|
||||
repeat the process until the the server reports there are no files left.
|
||||
|
||||
This class will see heavy activity right after a 2.1->2.2 upgrade since 2.2 introduces ReplayGain
|
||||
|
||||
This class will see heavy activity right after a 2.1->2.2 upgrade since 2.2 introduces ReplayGain
|
||||
normalization. A fresh install of Airtime 2.2 will see this class not used at all since a file
|
||||
imported in 2.2 will automatically have its ReplayGain value calculated.
|
||||
"""
|
||||
|
@ -27,42 +27,35 @@ class ReplayGainUpdater(Thread):
|
|||
|
||||
def main(self):
|
||||
|
||||
#TODO
|
||||
#TODO make sure object has 'dirs' attr
|
||||
directories = self.api_client.list_all_watched_dirs()['dirs']
|
||||
|
||||
for dir_id, dir_path in directories.iteritems():
|
||||
try:
|
||||
processed_data = []
|
||||
|
||||
#keep getting 100 rows at a time for current music_dir (stor or watched folder).
|
||||
#When we get a response with 0 rows, then we will set response to True.
|
||||
#keep getting few rows at a time for current music_dir (stor or watched folder).
|
||||
#When we get a response with 0 rows, then we will set 'finished' to True.
|
||||
finished = False
|
||||
|
||||
while not finished:
|
||||
# return a list of pairs where the first value is the file's database row id
|
||||
# and the second value is the filepath
|
||||
file_path = self.api_client.get_files_without_replay_gain_value(dir_id)
|
||||
print "temp file saved to %s" % file_path
|
||||
files = self.api_client.get_files_without_replay_gain_value(dir_id)
|
||||
self.logger.debug(files)
|
||||
|
||||
num_lines = 0
|
||||
for f in files:
|
||||
full_path = os.path.join(dir_path, f['fp'])
|
||||
processed_data.append((f['id'], replaygain.calculate_replay_gain(full_path)))
|
||||
|
||||
with open(file_path) as f:
|
||||
for line in f:
|
||||
num_lines += 1
|
||||
data = json.loads(line.strip())
|
||||
track_path = os.path.join(dir_path, data['fp'])
|
||||
processed_data.append((data['id'], replaygain.calculate_replay_gain(track_path)))
|
||||
|
||||
if num_lines == 0:
|
||||
finished = True
|
||||
|
||||
os.remove(file_path)
|
||||
#finished = (len(files) == 0)
|
||||
finished = True
|
||||
|
||||
#send data here
|
||||
pass
|
||||
print processed_data
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
print traceback.format_exc()
|
||||
def run(self):
|
||||
try: self.main()
|
||||
except Exception, e:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue