自用分享 - 用ffmpeg将cue文件批量转换成独立的mp3文件
ffmpeg吧
全部回复
仅看楼主
level 8
meoow 楼主
例如cue和wav文件,用这个解析cue文件转换除独立的mp3文件, 并写上id3 tag。
因为是自己应急用写的,所以可能乱了一点。
ffmpeg的路径根据自己情况修改。
2014年03月27日 14点03分 1
level 8
meoow 楼主
为了保持缩进,我把制表符换成全角空格了,记得换回来
#!/usr/bin/env python2.7
import su
bp
rocess as subp
import sys
import os
records = []
filename = ""
album=''
alb_artist=''
with open(sys.argv[1]) as f:
 for l in f:
  l = l.decode('cp936')
  a = l.split()
  if a[0] == "FILE":
   filename = ' '.join(a[1:-1]).strip('\'"')
   if not os.path.exists(filename):
    raise SystemExit("Can not file audio file.")
  elif a[0]=='TRACK':
   records.append({})
   records[-1]['index'] = a[1]
  elif a[0]=='TITLE':
   if len(records)>0:
    records[-1]['title'] = ' '.join(a[1:]).strip('\'"')
   else:
    album = ' '.join(a[1:]).strip('\'"')
  elif a[0]=='INDEX' and a[1]=='01':
   timea = a[2].split(':')
   if int(timea[0])>=60:
    timea.insert(0, str(int(timea[0])/60))
    timea[1] = str(int(timea[1])%60)
   times = '{0}.{1}'.format(':'.join(timea[:-1]), timea[-1])
   records[-1]['start'] = times
  elif a[0]=='PERFORMER':
   if len(records)>1:
    records[-1]['artist'] = ' '.join(a[1:]).strip('\'"')
   else:
    alb_artist = ' '.join(a[1:]).strip('\'"')
for i, j in enumerate(records):
 try:
  j['stop'] = records[i+1]['start']
 except IndexError:
  pass
records[-1]['stop'] = '0'
for i in records:
 commandline = ['/Users/leon/bin/ffmpeg', '-i', filename,
 u'-acodec', 'libmp3lame', '-aq', '0',
 u'-ss', i['start'], '-to', i['stop'],
 u'-metadata', u'title={0}'.format(i['title']),
 u'-metadata', u'artist={0}'.format(i.get('artist', '')),
 u'-metadata', u'performer={0}'.format(i.get('artist', '')),
 u'-metadata', u'album={0}'.format(album),
 u'-metadata', u'track={0}/{1}'.format(i['index'], len(records)),
 u'-metadata', u'album_artist={0}'.format(alb_artist),
 u'-metadata', u'composer={0}'.format(alb_artist),
 u'-metadata', u'encoder=Meow',
 u'-id3v2_version', '3', '-write_id3v1', '1',
 i['index'] +' - '+ i['title']+'.mp3']
 print u'\033[92m' + u' '.join(commandline) + u'\033[0m'
 subp.call(commandline)
2014年03月27日 14点03分 2
level 8
meoow 楼主
太棒了,大家很高兴
2014年04月02日 01点04分 3
level 8
meoow 楼主
太好了吧,谢谢楼主
2014年04月03日 18点04分 4
level 8
meoow 楼主
非常感谢
2014年05月06日 00点05分 5
level 8
meoow 楼主
不客气
2014年05月06日 00点05分 6
level 12
自言自语!!!
多少你也写几个注视嘛,!
2014年05月30日 07点05分 7
level 1
楼主辛苦了,但是我想说的是这种工具多如牛毛,估计没人会愿意用你这样的半成品,功能单一,或许有潜在的bug,甚至还要另外安装Python的解释器环境……话说的难听,楼主别往心里去
2014年11月12日 06点11分 8
1