Python Programming Method to modify the name of an MP3 file,

Source: Internet
Author: User

Python Programming Method to modify the name of an MP3 file,

This article describes how to modify the name of an MP3 file through Python programming. We will share this with you for your reference. The details are as follows:

I recently started to learn Python. By the way, I wrote a small function that is used to modify the names of mp3 songs downloaded from the Internet. How can I use this function?

ModifyMp3FileInfo (r'e:/music/12345.mp3 ')

Python code:

#! Modifying the downloaded Mp3 file name is called the correct Mp3 file def ModifyMp3FileInfo (filename): mp3Id3V1 = {"tag": {"valuepos" :( 0, 3), "value ":""}, "SongName": {"valuepos" :( 3,33), "value": ""}, "SongPeople": {"valuepos" :( 33,63), "value ":""}, "Zj": {"valuepos" :( 63,93), "value": ""}, "Year": {"valuepos" :( 93,97), "value ":""}, "Bak": {"valuepos" :( 97,125), "value": ""} try: f = open (filename, 'rb') f. seek (-128,2) sdata = f. read (3) if sdata = 'tag': f. seek (-, 2) sdata = f. read (128) for tag, subitem in mp3Id3V1. items (): subitem ["value"] = sdata [subitem ["valuepos"] [0]: subitem ["valuepos"] [1]. replace ('/00 ',''). strip () print '% s =' % tag, '% s' % subitem ["value"],'/N' f. close () import OS if mp3Id3V1 ["SongName"] ["value"]! = '': Test = [OS. path. dirname (filename), '//'] test. append (mp3Id3V1 ["SongName"] ["value"]) test.append('hangzhou') newfilename = ''. join (test) print newfilename if OS. path. exists (newfilename): test = ['filename', newfilename, 'has existed'] print ''. join (test) else: try: OS. rename (filename, newfilename) Doesn't WindowsError, e: if e. winerror: print 'modify filename failed, maybe the file is inuse 'else: print 'unknown error' else: print 'Is not a MP3 file' handle T IOError: print 'open file failed'

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.