youtubeinmp3 APIを使用して複数のyoutubeビデオをmp3ファイルとしてダウンロードするための独自のPythonコードを作成しようとしました。ほとんどのファイルでうまくいきましたが、mp3の代わりに46KbのHTMLページがありました。私のコードでこの問題を単独で解決できるようにする方法はありますか?youtubeinmp3のapiダイレクトリンクは、mp3ファイルの代わりにhtmlページを返します
はここでスクリプトを行く:
import urllib, json, re
#List of Youtube Video IDs to download
ListofURL = open("list.txt","r")
Ids = [url.strip().replace('https://www.youtube.com/watch?v=','') for url in ListofURL.readlines()]
#Base url
url = "http://www.youtubeinmp3.com/fetch/format=JSON&video=https://www.youtube.com/watch?v="
for id in Ids:
#Getting the API's download link as json response
response = urllib.urlopen(url+id)
data = json.loads("{" + re.findall('\{(.*?)\}', response.read())[0] + "}")
#Creating a file to download the song to
target = open(data["title"]+".mp3", 'wb')
#Downloading the mp3
mresponse = urllib.urlopen(data["link"])
mdata = mresponse.read()
#saving Data to the created file
target.write(mdata)
#closing the created file
target.close()
スクリプトは、この形式のファイルからユーチューブアドレスを読み取ります
https://www.youtube.com/watch?v=uzpa6ACrZaQ
https://www.youtube.com/watch?v=_B_3g_9gtFQ
https://www.youtube.com/watch?v=ex0Hli7kMRs
あなたの質問を編集し、これらのHTMLページがコードをどのように壊すかを示しますか? – stovfl