Esempio n. 1
0
def main():
    """
    Executes `mp3gainer` entry point.
    """
    bn = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    mp3s = filter(pymp3utils.is_mp3, args)
    id3_to_ape(mp3s)
    cmd = [_find_exec()]
    if '-v' in args or '-h' in args or len(args) == 0:
        print '%s version %s, wrapping:' % (bn, pymp3utils.__version__)

    id3version = None

    for ver in [eyeD3.ID3_V2_2, eyeD3.ID3_V2_3, eyeD3.ID3_V2_4]:
        verstr = '.'.join([str(num) for num in eyeD3.utils.constantToVersions(
            ver)[0:-1]])
        arg = 'v'.join(['--id3', verstr])
        if arg in args:
            args.remove(arg)
            id3version = ver
    cmd.extend(args)
    subprocess.call(cmd)
    ape_to_id3(mp3s, id3version)
    for m in mp3s:
        tag = pymp3utils.get_tag(m)
        if  pymp3utils.itunes.update_soundcheck(tag) > 0:
            tag.update()
Esempio n. 2
0
def set_sum_frame(target, hash):
    """
    Store mp3sum in target

    :param target: object to act on
    :param hash: hashlib object populated with audio data frames from `target`
    """
    tag = get_tag(target)
    key = get_key(hash.name)
    tag.addUserTextFrame(key, hash.hexdigest())
Esempio n. 3
0
def remove_sum_frame(target, hash_type=hash_type_default):
    """
    Remove mp3sum user text frame for given hash type, if present.

    :param target: object to act on
    :param hash_type: hash to retrieve (optional)
    :type hash_type: string
    """

    tag = get_tag(target)
    key = get_key(hash_type)
    tag.addUniqueFileID(key, None)
    tag.removeUserTextFrame(key)
Esempio n. 4
0
def get_sum_frame(target, hash_type=hash_type_default):
    """
    Retrieve mp3sum user text frame for given hash type.

    :param target: object to act on
    :param hash_type: hash to retrieve (optional)
    :type hash_type: string
    :returns: frame containing mp3sum for given hash or `None`
    :rtype: `eyeD3.tag.UserTextFrame`
    """
    tag = get_tag(target)
    key = get_key(hash_type)
    for utf in tag.getUserTextFrames():
        if utf.description == key:
            return utf

    return None
Esempio n. 5
0
def update_soundcheck(target):
    """
    """

    tag = get_tag(target)

    count = 0

    gain = find_frame(tag, 'REPLAYGAIN_TRACK_GAIN', 'TXXX')
    if not gain:
        gain = find_frame(tag, 'replaygain_track_gain', 'TXXX')
    peak = find_frame(tag, 'REPLAYGAIN_TRACK_PEAK', 'TXXX')
    if not peak:
            peak = find_frame(tag, 'replaygain_track_peak', 'TXXX')

    if gain != None and peak != None:
        soundcheck = []
        soundcheck.append(gain2sc(gain.text, 1000))
        soundcheck.append(soundcheck[0])
        soundcheck.append(gain2sc(gain.text, 2500))
        soundcheck.append(soundcheck[2])
        soundcheck.append('00024CA8')
        soundcheck.append(soundcheck[4])
        soundcheck.append('00007FFF')
        soundcheck.append(soundcheck[6])
        soundcheck.append(soundcheck[4])
        soundcheck.append(soundcheck[4])

        newval = ' '.join(soundcheck)

        iTunNORM = find_frame(tag, 'iTunNORM', 'COMM')

        if iTunNORM == None:
            header = eyeD3.frames.FrameHeader()
            header.id = 'COMM'
            header.compressed = 0
            iTunNORM = eyeD3.frames.CommentFrame(header, None, '',
                    u'iTunNORM')
            tag.frames.addFrame(iTunNORM)

        if iTunNORM.comment != newval:
            count += 1
            iTunNORM.comment = newval

    return count
Esempio n. 6
0
def validate_sum(target):
    """
    Validates all mp3sums found stored on target.
    
    :param target: object to act on
    :rtype: list of tuples
    :returns: hashes found in target, with validation status
    """
    tag = get_tag(target)
    sums = []
    results = []
    for utf in tag.getUserTextFrames():
        if utf.description.startswith(_owner_id_prefix):
            hash_type = utf.description.split('_')[1]
            sums.append((hash_type, utf.text))
    for (hash_type, sum_data) in sums:
        calc = build_hash(target, hash_type)
        results.append((hash_type, calc.hexdigest() == sum_data))
    return results
Esempio n. 7
0
def _update_files(
    files,
    verbose,
    sum_types,
    add,
    remove,
    quiet,
    version = eyeD3.ID3_ANY_VERSION,
    v1 = False
    ):

    for f in files:
        if verbose:
            print f
        update = False
        tag = pymp3utils.get_tag(f)
        for s in sum_types:
            if remove:
                if get_sum_frame(tag, s) != None:
                    if verbose:
                        print '  removing %s' % s
                    remove_sum_frame(tag, s)
                    update = True
            if add:
                if get_sum_frame(tag, s) == None:
                    if verbose:
                        print '  adding %s' % s
                    try:
                        cs = build_hash(f, s)
                    except MP3Error, v:
                        print "ERROR in '%s': %s" % (f, v.args[0])
                        continue

                    set_sum_frame(tag, cs)
                    update = True
        if update:
            if verbose:
                print ' updating file'
            pymp3utils.set_id3_version(tag, version, v1)