Download audio files from url

43 views Asked by At

I want to download an audio file from a url and split them into separate files of a certain size (so that one part of the program plays audio and the other downloads them).

Please don't say that there are other libraries for this, I have such a task, so I need to use win32inet

I've written some code that downloads and splits files that does this, it's far from perfect, but it does the job, but there are a few issues:

1) Only the first downloaded file is played, so far how many have been downloaded, the others give an error
2) The file contains the size of the full audio and not the part that should be downloaded (That is, the full audio has a time of 07:18, and when I download a part of this file, I would like the file to have a time that is equivalent to the size of the file, but the file contains the full time of 07:18)

I suspect that the problem is that important information about the file is contained in the first bytes of the file, but how can I implement this for my task?

def splitSound2Files():
 curDir = os.getcwd()
 fileCounter = 0
 buff = [] 
 buffSize = 1024*250
 hInet = win32inet.InternetOpen('HTTPGET',0x00000001,'','',0)
 hUrl = win32inet.InternetOpenUrl(hInet, getAudioURL(), '', 0, 0)
 while True:
    f = open(curDir+'\\Beethoven\\'+str(fileCounter)+'.mp3', 'wb')
    buff = win32inet.InternetReadFile(hUrl,buffSize)
    f.write(buff)
    if len(buff) != buffSize:
        break
    fileCounter = fileCounter + 1
 win32inet.InternetCloseHandle(hUrl)
 win32inet.InternetCloseHandle(hInet)
0

There are 0 answers