Minisoyo社区's Archiver

欢迎注册泡面三国

Holdsky 发表于 2008-5-19 22:35

id3标签

下面代码从nokia论坛python板块转载
原文:
There's no function for getting info about a mp3 file. So there's a function to this use.

def getID3(filename):
  fp=open(filename, 'r')
  fp.seek(-128, 2)
  fp.read(3)# TAG
  inizialetitle=fp.read(30)
  artist=fp.read(30)
  album=fp.read(30)
  year=fp.read(4)
  comment=fp.read(28)
  fp.close()
  return {'title':title, 'artist':artist, 'album':album, 'year':year}

我借上面代码说下mp3的id3标签
fp.seek(-128, 2),相对文件尾定位在128字节处
fp.read(3),相对当前读3个字节
inizialetitle=fp.read(30),读标题,30个字节
artist=fp.read(30),读艺术家,30个字节
album=fp.read(30),读专集,30个字节
year=fp.read(4),读年份,4个字节
comment=fp.read(28),读描述内容,28个字节

根据上面的文件格式,出现乱码时就可以自己手动解决了。

柯南 发表于 2008-5-19 22:57

PY,我不懂...关注下

Holdsky 发表于 2008-5-19 23:03

[quote]原帖由 [i]柯南[/i] 于 2008-5-19 22:57 发表 [url=http://www.minisoyo.com/redirect.php?goto=findpost&pid=2614006&ptid=129695][img]http://www.minisoyo.com/images/common/back.gif[/img][/url]
PY,我不懂...关注下 [/quote]

这个和python没关系,是一种文件格式,id3标签的存储格式。上面的只是借python语言翻译了这种格式,其实只要支持二进制读写,任何软件都可以利用这种格式

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.