乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Python 修改MP3 - 代碼分享 - 開(kāi)源中國(guó)社區(qū)

       ganame 2011-02-13
      Python 修改MP3
      Sephiroth 發(fā)布于 2010年11月16日 13時(shí) (0評(píng)) 1人收藏此代碼, 我要收藏(?)
      用這個(gè)程序修改后的MP3比原來(lái)要小一些了,因?yàn)橐粡垐D片被刪除了,起到了給MP3"瘦身"的作用。在一些mp3中,每個(gè)都有一張400多K的圖片,10幾個(gè)MP3,就相當(dāng)一個(gè)普通MP3文件的大小了。
      標(biāo)簽: MP3

      代碼片段(1)

      [代碼] [Python]代碼

      001 # -*- coding: cp936 -*-
      002 """
      003 將MP3文件中的ID3V2.3部分去掉,以便在MP3機(jī)上播放
      004 用法:mp3lcear [源mp3目錄](méi) [生成的mp3目錄](méi)
      005 """
      006 import sys
      007 import os
      008 import string
      009 import shutil
      010 import struct
      011 import thread
      012 import threading
      013 import time
      014   
      015 mp3suffix = 'mp3'
      016   
      017 class Process(threading.Thread):
      018 """
      019 簡(jiǎn)單地在運(yùn)行的過(guò)程中顯示進(jìn)度
      020 """
      021 def __init__(self,msg,sleepTime):
      022 threading.Thread.__init__(self)
      023 self.msg = msg
      024 self.running = True
      025 self.sleepTime = sleepTime
      026 def setPause(self,pause):
      027 self.pause = pause
      028 def setRunning(self,running):
      029 self.running = running
      030 def run (self):
      031 while(self.running):
      032 self.pause.wait()
      033 print self.msg,
      034 time.sleep(self.sleepTime)
      035   
      036 def usage(code, msg=''):
      037 """
      038 程序的使用方法
      039 """
      040 print >> sys.stderr, __doc__
      041 if msg:
      042 print >> sys.stderr, msg
      043 sys.exit(code)
      044   
      045 def checkDir(argDir,create=False):
      046 """
      047 檢查目錄是否存在,如果create為Ture,則新建一個(gè)目錄
      048 """
      049 tempDir = None
      050 if(not os.path.isdir(argDir)):
      051 currentDir = os.path.abspath(os.curdir)
      052 tempDir = os.path.join(currentDir,argDir)
      053 if(not os.path.isdir(tempDir) and create):
      054 os.mkdir(tempDir)
      055 else:
      056 usage(1,"目錄"+argDir+"不存在")
      057 else:
      058 tempDir = os.path.abspath(argDir)
      059 return tempDir
      060   
      061 def clearMp3(srcFile,destFile):
      062 """
      063 修改mp3文件,并將其創(chuàng)建到destFile所指定的地址
      064 """
      065 global process
      066 srcfp = None
      067 filesize = os.path.getsize(srcFile)
      068 try:
      069 srcfp = open(srcFile,'rb')
      070 head = srcfp.read(3)
      071 if(head=='ID3'):
      072 srcfp.seek(3,1)
      073 size = srcfp.read(4)
      074 if(not len(size)==4):
      075 print srcFile+'文件格式錯(cuò)誤'
      076 else:
      077 size0 = struct.unpack('b',size[0])[0]
      078 size1 = struct.unpack('b',size[1])[0]
      079 size2 = struct.unpack('b',size[2])[0]
      080 size3 = struct.unpack('b',size[3])[0]
      081 headSize =(((size0&0x7f)<<21) | ((size1&0x7f)<<14) | ((size2&0x7f)<<7) | (size3&0x7f))
      082 filesize = filesize - headSize
      083 destfp = None
      084 try:
      085 dataLen = 0
      086 destfp = open(destFile,'wb')
      087 srcfp.seek(headSize,1)
      088 data=srcfp.read(1024)
      089 while (data!= ''):
      090 destfp.write(data)
      091 data=srcfp.read(1024)
      092 except Exception,e:
      093 print '創(chuàng)建文件'+destFile+'錯(cuò)誤',e
      094 try:
      095 if (destfp != None):
      096 destfp.close
      097 except Exception,de:
      098 print de
      099 else:
      100 print srcFile+'不需要修改 拷貝',
      101 try:
      102 shutil.copyfile(srcFile,destFile)
      103 except Exception, ce:
      104 print ce
      105 except Exception,oe:
      106 print '修改中出錯(cuò)',oe
      107 try:
      108 if (srcfp != None):
      109 srcfp.close()
      110 except Exception,se:
      111 print de
      112   
      113    
      114   
      115 if __name__ == "__main__":
      116 if(len(sys.argv)<3):
      117 usage(1)
      118 global process
      119   
      120 sourceDir = checkDir(sys.argv[1])
      121 destDir = checkDir(sys.argv[2],True)
      122   
      123 print 'Mp3源目錄',sourceDir
      124 print 'Mp3目的目錄',destDir
      125   
      126 process = Process('...',1)
      127 pause = threading.Event()
      128 process.setPause(pause)
      129   
      130 process.start()
      131   
      132 for filename in os.listdir(sourceDir):
      133 srcPath = os.path.join(sourceDir, filename)
      134 destPath = os.path.join(destDir, filename)
      135 if os.path.isfile(srcPath):
      136 print '開(kāi)始處理 '+filename,
      137 tempfilename = filename.lower()
      138 if(not tempfilename.endswith(mp3suffix)):
      139 print filename+'不是一個(gè)mp3文件\n'
      140 else:
      141 pause.set()
      142 clearMp3(srcPath,destPath)
      143 pause.clear()
      144 print '結(jié)束 \n'
      145 pause.set()
      146 process.running = False
      147 sys.exit(0)

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多