Fandom

Music Player Daemon Community Wiki

Hack:rg.py

525pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

A wrapper around mp3gain that adds ReplayGain info to ID3v2 tags instead of APEv2 tags. Also see Hack:ape2id3.py.

Requires mp3gain and pyid3lib. Note: Neither are available as packages in Ubuntu.

Also available from [1].

#! /usr/bin/env python

import os
import sys

from subprocess import Popen, PIPE

import pyid3lib

files = []
mp3gain = ["mp3gain", "-o", "-s", "s"]

cmd = mp3gain + sys.argv[1:]
pipe = Popen(cmd, stdout=PIPE).stdout
pipe.next()
for line in pipe:
   parts = line.rstrip("\n").split("\t")
   if parts[0] != '"Album"':
       files.append(parts)
   else:
       for file in files:
           frames = {
               "replaygain_track_gain": "%.2f dB" % (float(file[2])),
               "replaygain_album_gain": "%.2f dB" % (float(parts[2])),
               "replaygain_track_peak": "%.6f" % (float(file[3])/32768.0),
               "replaygain_album_peak": "%.6f" % (float(parts[3])/32768.0),
           }
           tag = pyid3lib.tag(file[0])
           for key, value in frames.iteritems():
               frame = {
                   "frameid": "TXXX",
                   "textenc": 1,
                   "description": key,
                   "text": value,
               }
               changed = False
               for i in range(0, len(tag)):
                   if tag[i]["frameid"] == "TXXX":
                       if tag[i]["description"] == key:
                           tag[i] = frame
                           changed = True
               if not changed:
                   tag.append(frame)
           tag.update()
       files = []

Also on Fandom

Random Wiki