python批量修改文件名称及文件属性

最近super simple song很火,本人有sss的mp4视频文件和歌词本,为了让歌词本可以点读,需要自制毛毛虫点读的音频,但是sss的歌曲有180多首,所以想通过程序批量完成。
毛毛虫自制音频需要将音频名称保存成RECxxxx格式(这种格式不方便自己区分音频内容),为了自己区分方便,需要将音频歌曲名称写入音频文件属性详细信息的标题中。

因此要达到目的,需要完成以下需求:
1)MP4文件批量转换成MP3文件,通过魔影工厂即可批量转换的。
2)MP3文件改名
3)MP3文件属性修改
下面的程序及是批量完成文件改名和属性修改

import os
import eyed3

# artist 参与创作的艺术家
# album 专辑,唱片集
# title 标题
def modifyMP3Property(path, artist, album, title):
    filename = os.path.basename(path).split('.')[0]
    try:
        audiofile = eyed3.load(path)
        if audiofile != None:
            audiofile.initTag()
            audiofile.tag.artist = u'%s' % artist
            audiofile.tag.album = u'%s' % album
            audiofile.tag.title = u'%s' % title
            audiofile.tag.save()
    finally:
        print()

def reName():
    path=input("请输入路径(例如D:\\\\picture):")
    name=input("请输入开头名:")
    start=input("请输入开始数:")
    fileType=input("请输入后缀名(如 .jpg、.txt等等):")
    print("正在生成以"+name+start+fileType+"迭代的文件名")
    count=0
    filelist=os.listdir(path)
    filelist.sort(key=lambda filename:int(filename.split('.')[0]))
    for files in filelist:
        oldPath=os.path.join(path,files)
        if os.path.isdir(oldPath):
            continue
        modifyMP3Property(oldPath, title=files, artist=files, album=files)
        newPath=os.path.join(path,name+str(count+int(start))+fileType)
        os.rename(oldPath,newPath)
        count+=1
    print("共修改了"+str(count)+"个文件")

reName()

程序运行界面如下
《python批量修改文件名称及文件属性》
sss文件修改前
《python批量修改文件名称及文件属性》
sss文件修改后
《python批量修改文件名称及文件属性》

    原文作者:风水月
    原文地址: https://blog.csdn.net/fengshuiyue/article/details/112107507
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞