首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >想要使用Python从mp3文件中删除非法标记

想要使用Python从mp3文件中删除非法标记
EN

Stack Overflow用户
提问于 2010-11-26 09:07:30
回答 1查看 465关注 0票数 1

如何在我的mp3文件中实现这一点。

Artist:www.xyz.com高等级->艺术家:

艺人:免费下载,免费音乐,xyzhi.com ->艺术家:

艺人:菅直人(Amma Na) - www.musicxyx.com - Danaa收藏品

艺人:南·波吉伦

我一直在使用诱变剂来访问ID3标签。如何操纵标签中的字符串以达到上述目的?

EN

回答 1

Stack Overflow用户

发布于 2010-11-26 09:30:15

首先,您需要一个库来理解MP3格式,并允许您编辑标记,例如:http://id3-py.sourceforge.net/

除此之外,您只需要处理字符串替换。

对于您指定的文件(包括奇怪的空间要求):

代码语言:javascript
复制
#!/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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4283868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档