Skip to content

Instantly share code, notes, and snippets.

@gitcrtn
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitcrtn/01e32dd71c998a58d425 to your computer and use it in GitHub Desktop.
Save gitcrtn/01e32dd71c998a58d425 to your computer and use it in GitHub Desktop.
音楽CDをwavやmp3ファイルにする(主にMixCD向け)
# main.py
import sys
import os
import os.path
import subprocess
import datetime
musicdir = 'C:\\music\\VLC'
vlc = 'C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe'
ffmpeg = 'C:\\bin\\ffmpeg.exe'
wav_cmd = '"%s" -I http cdda:///%%s --cdda-track=%%s :sout=#transcode{acodec=s16l,channels=2,samplerate=44100}:std{access=file,mux=wav,dst=%%s} vlc://quit' % vlc
mp3_cmd = '"%s" %%s -filter_complex "concat=n=%%s:v=0:a=1" -codec:a libmp3lame -qscale:a 2 "%%s"' % ffmpeg
def print_percent(n,m):
pct = int(100.0 * float(n) / float(m))
bar = int(float(pct) / 5.0)
print '[' + '=' * bar + ' ' * (20-bar) + '] ' + str(pct) + '%\r',
def execCmd(cmd):
p = subprocess.Popen(cmd,stdout=subprocess.PIPE)
ret = None
while p.poll() is None:
line = p.stdout.readline().strip()
if line: print line
retcode = p.wait()
return ret
def main():
if len(sys.argv) not in (2,3): return
drive = sys.argv[1]
toMp3 = (len(sys.argv)==3)
if not ':' in drive: drive += ':'
if not '\\' in drive: drive += '\\'
if not os.path.isdir(drive): return
print 'drive:', drive
track_cnt = len(filter(lambda n:'.cda' in n, os.listdir(drive)))
d = musicdir + '\\' + datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
if not os.path.isdir(d):
os.makedirs(d)
print 'output dir:', d
print 'converting from cd to wav...'
in_wavs = []
for i in xrange(track_cnt):
n = i + 1
print_percent(i,track_cnt)
f = '%s\\%04d.wav' % (d,n)
c = wav_cmd % (drive,n,f)
p = subprocess.Popen(c)
p.wait()
print_percent(n,track_cnt)
in_wavs.append(f)
if toMp3:
print 'converting from all wavs to mp3...'
f = '%s\\all.mp3' % d
c = mp3_cmd % (' '.join(map(lambda n:'-i '+n, in_wavs)),track_cnt,f)
execCmd(c)
if __name__=='__main__': main()
set /p DRVLTR="input drive letter: "
C:\Python27\python.exe main.py %DRVLTR% mp3
pause
set /p DRVLTR="input drive letter: "
C:\Python27\python.exe main.py %DRVLTR%
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment