def get_md_from_file(self, filepath): """ Returns None if error retrieving metadata. Otherwise returns a dictionary representing the file's metadata """ self.logger.info("getting info from filepath %s", filepath) md = {} replay_gain_val = replaygain.calculate_replay_gain(filepath) self.logger.info('ReplayGain calculated as %s for %s' % (replay_gain_val, filepath)) md['MDATA_KEY_REPLAYGAIN'] = replay_gain_val try: md5 = self.get_md5(filepath) md['MDATA_KEY_MD5'] = md5 file_info = mutagen.File(filepath, easy=True) except Exception, e: self.logger.error("failed getting metadata from %s", filepath) self.logger.error("Exception %s", e) return None
def main(self): raw_response = self.api_client.list_all_watched_dirs() if 'dirs' not in raw_response: self.logger.error("Could not get a list of watched directories \ with a dirs attribute. Printing full request:") self.logger.error(raw_response) return directories = raw_response['dirs'] for dir_id, dir_path in directories.iteritems(): try: # keep getting few rows at a time for current music_dir (stor # or watched folder). total = 0 while True: # return a list of pairs where the first value is the # file's database row id and the second value is the # filepath files = self.api_client.get_files_without_replay_gain_value( dir_id) processed_data = [] for f in files: full_path = os.path.join(dir_path, f['fp']) processed_data.append( (f['id'], replaygain.calculate_replay_gain(full_path))) total += 1 try: if len(processed_data): self.api_client.update_replay_gain_values( processed_data) except Exception as e: self.logger.error(e) self.logger.debug(traceback.format_exc()) if len(files) == 0: break self.logger.info("Processed: %d songs" % total) except Exception, e: self.logger.error(e) self.logger.debug(traceback.format_exc())
def main(self): raw_response = self.api_client.list_all_watched_dirs() if 'dirs' not in raw_response: self.logger.error("Could not get a list of watched directories \ with a dirs attribute. Printing full request:") self.logger.error( raw_response ) return directories = raw_response['dirs'] for dir_id, dir_path in directories.iteritems(): try: # keep getting few rows at a time for current music_dir (stor # or watched folder). total = 0 while True: # return a list of pairs where the first value is the # file's database row id and the second value is the # filepath files = self.api_client.get_files_without_replay_gain_value(dir_id) processed_data = [] for f in files: full_path = os.path.join(dir_path, f['fp']) processed_data.append((f['id'], replaygain.calculate_replay_gain(full_path))) total += 1 try: if len(processed_data): self.api_client.update_replay_gain_values(processed_data) except Exception as e: self.logger.error(e) self.logger.debug(traceback.format_exc()) if len(files) == 0: break self.logger.info("Processed: %d songs" % total) except Exception, e: self.logger.error(e) self.logger.debug(traceback.format_exc())
def get_md_from_file(self, filepath): """ Returns None if error retrieving metadata. Otherwise returns a dictionary representing the file's metadata """ self.logger.info("getting info from filepath %s", filepath) md = {} replay_gain_val = replaygain.calculate_replay_gain(filepath) self.logger.info("ReplayGain calculated as %s for %s" % (replay_gain_val, filepath)) md["MDATA_KEY_REPLAYGAIN"] = replay_gain_val try: md5 = self.get_md5(filepath) md["MDATA_KEY_MD5"] = md5 file_info = mutagen.File(filepath, easy=True) except Exception, e: self.logger.error("failed getting metadata from %s", filepath) self.logger.error("Exception %s", e) return None