def item_imported(self, lib, item, config): try: self.write_album = False mf = MediaFile(syspath(item.path)) if self.requires_gain(mf): track_data, album_data = rgcalc.calculate([syspath(mf.path)], True, self.ref_level) self.write_gain(mf, track_data, None) except (FileTypeError, UnreadableFileError, TypeError, ValueError), e: log.error("failed to calculate replaygain: %s ", e)
def item_imported(self, lib, item): try: self.write_album = False print_("Tagging Replay Gain: %s - %s" % (item.artist, item.title)) mf = MediaFile(item.path) if self.requires_gain(mf): track_data, album_data = rgcalc.calculate([mf.path], True, self.ref_level) self.write_gain(mf, track_data, None) except (FileTypeError, UnreadableFileError, TypeError, ValueError), e: log.error("failed to calculate replaygain: %s ", e)
def test_custom_ref_level(self): f = os.path.join(DATA_PATH, "no-tags.flac") t, a = rgcalc.calculate([f], ref_lvl=105) self.assertAlmostEqual(a.gain, 80.82, 5) self.assertAlmostEqual(a.peak, 0.000244, 5) self.assertEqual(a.ref_level, 105) self.assertEqual(a.gain_type, GainData.TP_ALBUM) self.assertEqual(len(t), 1) for k in t: self.assertEqual(k, f) gain = t[k] self.assertAlmostEqual(gain.gain, 80.82, 5) self.assertAlmostEqual(gain.peak, 0.000244, 5) self.assertEqual(gain.ref_level, 105) self.assertEqual(gain.gain_type, GainData.TP_TRACK)
def album_imported(self, lib, album): self.write_album = True print_("Tagging Replay Gain: %s - %s" % (album.albumartist, album.album)) try: media_files = [MediaFile(item.path) for item in album.items()] media_files = [mf for mf in media_files if self.requires_gain(mf)] # calculate gain. Return value - track_data: array dictionary indexed by filename track_data, album_data = rgcalc.calculate([mf.path for mf in media_files], True, self.ref_level) for mf in media_files: self.write_gain(mf, track_data, album_data) except (FileTypeError, UnreadableFileError, TypeError, ValueError), e: log.error("failed to calculate replaygain: %s ", e)
def test_silence(self): f = os.path.join(DATA_PATH, "no-tags.flac") t, a = rgcalc.calculate([f]) # Gain and peak determined experimentally for this file. self.assertAlmostEqual(a.gain, 64.82, 5) self.assertAlmostEqual(a.peak, 0.000244, 5) self.assertEqual(a.ref_level, 89) self.assertEqual(a.gain_type, GainData.TP_ALBUM) self.assertEqual(len(t), 1) for k in t: self.assertEqual(k, f) gain = t[k] self.assertAlmostEqual(gain.gain, 64.82, 5) self.assertAlmostEqual(gain.peak, 0.000244, 5) self.assertEqual(gain.ref_level, 89) self.assertEqual(gain.gain_type, GainData.TP_TRACK)
def main(): # XXX: Crash fix for rgain ≤ 1.0.2, https://bitbucket.org/fk/rgain/issue/4 gobject.threads_init() req = yaml.load(sys.stdin) paths = req['paths'] force = req['force'] ref_level = req['ref_level'] (tracks_rg, album_rg) = \ rgcalc.calculate(paths, force=force, ref_lvl=ref_level) res = { 'tracks': map_dict(unpack_gaindata, tracks_rg), 'album': unpack_gaindata(album_rg), } yaml.dump(res, sys.stdout)
def album_imported(self, lib, album): self.write_album = True print_("Tagging Replay Gain: %s - %s" % (album.albumartist, album.album)) try: media_files = [MediaFile(item.path) for item in album.items()] media_files = [mf for mf in media_files if self.requires_gain(mf)] #calculate gain. Return value - track_data: array dictionary indexed by filename track_data, album_data = rgcalc.calculate( [mf.path for mf in media_files], True, self.ref_level) for mf in media_files: self.write_gain(mf, track_data, album_data) except (FileTypeError, UnreadableFileError, TypeError, ValueError), e: log.error("failed to calculate replaygain: %s ", e)
def test_no_files(self): with self.assertRaises(ValueError): rgcalc.calculate([])