这是一个脚本,我将曲目编号放在 mp3 名称之前,以使曲目保持正确的顺序,而不是按字母顺序排列。
除了三个文件夹外,它在所有(100 多个文件夹 / 1300 多首歌曲)上都运行良好。
我不能告诉 wtf 正在这里发生。
任何机构有任何想法?
output =>
输入音乐文件的路径:/n>c:\test
path_name = c:\test\2 - Live Albums\1995 - MTV unplugged\Shooting Star.mp3
02 - 流星.mp3
path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\The Times they are A-Changin'.mp3
04 - The Times They Are A-Changin'.mp 3 path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\Tombstone Blues.mp3 01 - Tombstone Blues.mp3
path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\With God On Our Side.mp3
12 - 与上帝同在.mp3
path_name = c:\test\1 - Studio Albums\1964 - The Times They Are A-Changin\Ballad Of Hollis Brown.mp3
回溯(最近一次通话最后):
文件“C:/Users/Brian/Python Files/track_numbering_mp3.py”,第 45 行,在
music_track_numbering(路径)
文件“C:/Users/Brian/Python Files/track_numbering_mp3.py”,第 39 行,在 music_track_numbering
os.rename(join(root,name),join(root,track_number)) # 重命名文件
WindowsError: [错误 3] 系统找不到指定的路径
进程以退出代码 1 结束
#!usr/bin/env python
__author__ = 'Brian Kane'
"""This scripts takes a path argument to the root directory of the music files (mp3 here) and
adds a padded number corresponding to the track number. It will do this to all of the tracks in the folders
and subfolders. This allows for burning in the track order and not alphabetized. In theory I suppose you could
start at C:'\'"""
import os
from os.path import *
import string
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
def music_track_numbering(path):
nums = []
for i in range(10): # just fills in nums to compare to track name
# to not double number
nums.append(str(i))
for root, dirs, files in os.walk(path): # walks through the data tree to get files
# print 'root = ', root
# print 'dirs = ', dirs
# print 'files = ',files
for name in files:
extension = os.path.splitext(name)[1][1:].strip().lower() # gets the file extension
if name[0] in nums: # don't double number
break
if extension == 'mp3':
# print 'name = ', name # test purposes
path_name = root +'\\' + name # path_name is complete path
print 'path_name = ', path_name # test purposes
track = EasyID3(path_name)['tracknumber'][0] # gets the track number from metadata
track_number = str(track).zfill(2) + ' - ' + name # pads leading zero and adds dash to name
os.rename(join(root,name),join(root,track_number)) # renames the file
print track_number # test purposes
# path = 'C:\\test' # this is a test path
path = raw_input('Enter the path to the music file:/n>')
music_track_numbering(path)