youtube-mp3.org api not working properly, only downloads cached videos

无人久伴 提交于 2020-01-14 06:40:08

问题


Previously i was able to download YouTube videos as mp3 via youtube-mp3.org Using this method:

http://www.youtube-mp3.org/api/pushItem/?item=http%3A//www.youtube.com/watch%3Fv%3D<VIDEOID>&xy=_

Then it returned the video id and they started converting the video on their servers. Then this request would return a JSON string with info about the video and the current conversion status:

http://www.youtube-mp3.org/api/itemInfo/?video_id=<VIDEOID>&adloc=

After repeating the request until the value for status is 'serving' I then started the last request by taking the value for key h from the JSON response from the previous request, and this would download a the mp3 file.

http://www.youtube-mp3.org/get?video_id=<VIDEOID>&h=<JSON string value for h>

Now the first request always returns nothing. The second and third requests only succeed if the requested video is cached on their servers (like popular music videos). If thats not the case then the second request would return nil and so the 3rd request can't be started because of the missing hvalue from the second request. Could anybody help me with getting the website to start a conversion something needs to be wrong with the first URL i just dont know what. Thanks


回答1:


I just tested it. For the first request, you need to send with it a header of:

Accept-Location: *

Otherwise, it will return a 500 (Internal Server Error). But with that header, it will return a string of the youtube video id, and you can use the 2nd api for checking the progress.

Here's the C# code I used for testing:

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("FIRST_API_URL");
wr.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7";
wr.Headers.Add("Accept-Location", "*");
string res = (new StreamReader(wr.GetResponse().GetResponseStream())).ReadToEnd();

Btw, you can keep track of the headers in the browser's Network (Chrome) debug tab.

Regards



来源:https://stackoverflow.com/questions/8763141/youtube-mp3-org-api-not-working-properly-only-downloads-cached-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!