Want to bulk modify the file name of the MP3 mind? Python to help you solve!

Source: Internet
Author: User
Tags id3

I usually like to put "rom thinking" MP3 in the mobile phone, easy to listen to the road. However, the MP3 downloaded on the internet is a bit bad, its name will have a long prefix of the site name, such as "" "Free Village www.zizaicun.com finishing" 44 people say the Republic good. mp3 ", the problem is that when I look at the file on my phone, I see the Picture:



When I want to select a collection, I do not know which one to choose, I can only open the file, waiting for the title note slowly moved over, I can see the name of the program, as shown. And the wait time is up to 12 seconds! I can't stand it! Sometimes I have to spend two minutes looking for a show I haven't seen.




The solution, of course, is some, the most simple and brutal manual modification, but for me to learn computer, this method is too low-level, another way is the next special radio software to listen to, but I do not want to see ads, so I finally decided to use Python to solve the problem.


Try one: Modify the file name

My first idea, of course, is to batch modify the file name, this is very simple, a lot of online tutorials, I will post my code:

# Coding=gbkimport Os,re,sysdef renamefiles (srcdir):      srcfiles = Os.listdir (srcdir) for       srcfile in Srcfiles:          srcfilename = srcfile.partition (' "') #我用" as the identifier, after which the string is truncated as the new file name        DestFile = srcfilename[2]        os.rename ( Srcdir+os.sep+srcfile, srcdir+os.sep+destfile)        srcdir = "d:\\09 recording \ \ Rom thinking"  #这里填windows上的路径名, Be sure to use Renamefiles (Srcdir)


The result seems to be good, the file name is all right, but after the import of mobile phone found still unchanged! The original Apple phone by default Mp3tag title information as the first choice of display name, only when there is no tag title will display the file name. So the first attempt ended in failure.


Try two: Mutagen great show of Divinity!

The next step is to find a way for Python to modify the mp3 tag information, about the processing of audio files, Python has a third-party package mutagen can be used. However, before installing the mutagen, it is best to install the Easy_install, convenient for later management of third-party packages.


Easy_install installation is very simple, Baidu a bit on the line, but ... When I installed it, I ran the ez_setup.py, but it showed Unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xd7 in position 1:ordinal not in range (12 8) Such an error message, resulting in the script folder can not be installed, I searched the internet for a long time, finally found a solution, see this article for details.


After loading the easy_install, simply enter the Easy_install mutagen in cmd to install the mutagen directly.


The next thing to mutagen solved, my practice is to directly all the MP3 file tag information is deleted, the code is as follows:

#coding =gbkimport os,re,sysfrom Mutagen.mp3 import mp3from mutagen.id3 import id3def Deletetag (srcdir):      srcfiles = Os.listdir (Srcdir) for       srcfile in srcfiles:          audio = ID3 (srcdir+os.sep+srcfile)        audio.delete ()        Srcdir = "d:\\09 recording \ \ Rom thinking" Deletetag (Srcdir)

Done! Finally put the file into the phone, it will be able to see the interface very smoothly ~ There is a lot more refreshing than before ~ ~







Want to bulk modify the file name of the MP3 mind? Python to help you solve!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.