这是我做的一个脚本,把曲目编号放在MP3名称之前,以保持曲目的正确顺序,而不是按字母顺序排列。你知道吗
除了三个文件夹外,它在所有文件夹(100多个文件夹/1300多首歌曲)上都运行良好。你知道吗
我不知道世跆联在这里发生了什么。你知道吗
有人有什么想法吗?你知道吗
output =>
输入音乐文件的路径:/n>;c:\test
路径\u name=c:\test\2-直播相册\1995-MTV未插电\拍摄星星.mp3你知道吗
02-拍摄星星.mp3你知道吗
path_name=c:\test\2-现场专辑\1995-MTV未插电\The Times They A-Changin'.mp3
04年的今天,《泰晤士报》报道了他们的变化 三 路径\u name=c:\test\2-Live Albums\1995-MTV Unplugged\Tombstone蓝调.mp3 01-墓碑蓝调.mp3你知道吗
path_name=c:\test\2-现场专辑\1995-MTV未插电\上帝在我们的侧边.mp3你知道吗
12-上帝保佑我们侧边.mp3你知道吗
path_name=c:\test\1-录音棚专辑\1964-泰晤士报他们是张茵\霍利斯民谣棕色.mp3你知道吗
回溯(最近一次呼叫):
文件“C:/Users/Brian/Python Files/track\u numbering\u mp3.py”,第45行,in
音乐曲目编号(路径)
文件“C:/Users/Brian/Python Files/track\u numbering\u mp3.py”,第39行,在music\u track\u numbering中
在操作系统重命名(join(root,name),join(root,track#u 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)
目前没有回答
相关问题 更多 >
编程相关推荐