开发者

Want to remove illegal tags from mp3 file using Python

How to acheive this in my mp3 files.

Artist:www.xyz.com      ----> Artist:

Artist:free downloads,free music,xyzhi.com   ----> Artist:

A开发者_如何学Gortist:Kurukuru Kan (Amma Na) - www.musicxyx.com - ® Danaa collections ®     ----> Artist: Kurukuru Kan (Amma Na)

Artist: Nan Pogiren - - ® Danna collections ®    ----> Artist:Nan Pogiren

I have been using Mutagen to access ID3 tags. How to manipulate the strings in the tags to achieve the above?


First you'll need a library to understand the MP3 format and allow you to edit the tags, maybe: http://id3-py.sourceforge.net/

Beyond that, you'll just need to work on the string replacements.

For the ones you specified (including weird space requirements):

#!/usr/bin/env python
# -*- coding: utf-8 -*-
EXPECTED = {
'Artist:www.xyz.com':'Artist:',
'Artist:free downloads,free music,xyzhi.com':'Artist:',
'Artist:Kurukuru Kan (Amma Na) - www.musicxyx.com - ® Danaa collections ®':'Artist: Kurukuru Kan (Amma Na)',
'Artist: Nan Pogiren - - ® Danna collections ®':'Artist:Nan Pogiren'}

import re

def process(instr):
    assert instr.startswith("Artist:")
    mo = re.match(r"^(Artist:)( ?)(.*?) - .*$",instr)
    if mo:
        spc = mo.group(2)
        if spc == " ":
            spc = ""
        else:
            spc = " "

        return "Artist:"+spc+mo.group(3)
    return "Artist:"

for (instr,outstr) in EXPECTED.iteritems():
    print process(instr),outstr,process(instr) == outstr
    assert process(instr) == outstr
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜