这是我用来将曲目编号放在mp3名称之前的脚本,以使曲目保持正确的顺序而不是按字母顺序排列。
除了三个文件夹外,它在所有(100多个文件夹/ 1300多首歌曲)上运行良好。
我不知道wtf是在这里发生的。
任何人都有任何想法吗?
output =>
输入音乐文件的路径:/ n> c:\ test
path_name = c:\ test \ 2 - Live Albums \ 1995 - MTV unplugged \ Shooting Star.mp3
02 - 射击Star.mp3
path_name = c:\ test \ 2 - Live Albums \ 1995 - MTV Unplugged \ The Times他们是A-Changin' .mp3
04 - 他们是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他们是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)