How Python writes data to a MP3 file

Source: Internet
Author: User
The example in this article describes how Python writes data to a MP3 file. Share to everyone for your reference. The specific analysis is as follows:

The correct name of the Mp3 file is corrected by Mp3 the data in the ID3v1 data section, but sometimes the data in the data break is empty, so writing a function that modifies the data of the ID3v1 data segment is also an exercise.

How to use:

writemp3header[Songname] = ' Test song name ' writemp3header[songpeople] = ' no idle ' writemp3header[Zhuanji] = ' album ' writemp3header[Y Ear] = ' writemp3header[Bak] = ' Memo test ' Setmp3header (R ' E:\test.mp3 ')

The Python code is as follows:

Writemp3header = {   "songname": "",   "songpeople": "",   "Zhuanji": "",   "Year": "",   "Bak": "   } def setmp3header (mp3file):   mp3id3v1 = {         "songname": -125,     "songpeople": -95,     "Zhuanji": -65,     " Year ": -35,     " Bak ": -31     }   tags = [' songname ', ' songpeople ', ' Zhuanji ', ' bak ']   f = open (Mp3file, ' r+ ')   Try:     f.seek ( -128,2)     try:       tempstr = F.read (3)       if TempStr = = ' TAG ': for         Tag,startpos in Mp3id3v1.items ():           if writemp3header[tag]! = ":             f.seek (startpos,2)             if tag in tags:               if len ( Writemp3header[tag]) >:                  f.write (writemp3header[tag][:30])               else:                 f.write (Writemp3header[tag] )             Print Startpos,tag,writemp3header[tag]       else:         print ' is not a mp3file '     except IOError:       print ' read error '   finally:     f.close ()

Hopefully this article will help you with Python programming.

  • 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.