There is a website which includes a JS code. Normally, when the page is opened by a user this JS code starts manually and provides a link about 10 seconds.
I am trying to catch this link. In PHP, I call this page with file_get_contents function, however as you predict link is not there.
Is there any way to make a HTTP request to this page and wait until javascript code started. Or can I invoke this JS function by using JQuery maybe?
If the question is not clear, I can provide more details. Thanks in advance.
I’d suggest looking into the javascript on the page and reverse-engineer how the link is dynamically generated. Then you can use regex to extract that info from the string returned by file_get_contents.
I can probably help you on the reverse-engineering if you can provide extra information on the page in question (or similar).
UPDATE:
After some reversing, I found that the mp3 ripper site uses 2 api’s: one to push a video to get processed, and one to poke at the current status.
First api:
Second api:
XXXXXXXX is the youtube video id. The 2nd api returns JSONP where the padding is a variable assignment (info = {…};). In the json, there’s a “h” member that returns a long hash which can be used to ultimately construct the mp3 download file link.
But to be a bit ethical, may I suggest looking into another approach (if allowed by your hosting environment)? You can use FFmpeg to convert the video on your own. There’s a wrapper class here: YouTube-to-MP3 conversion class