Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Openload: extract download URL using PhantomJS
// Usage: phantomjs openload.js <video_url>
// if that doesn't work try: phantomjs --ssl-protocol=any openload.js <video_url>
var separator = ' | ';
var page = require('webpage').create(),
system = require('system'),
id, match;
if(system.args.length < 2) {
console.error('No URL provided');
phantom.exit(1);
}
match = system.args[1].match(
/https?:\/\/(?:openload\.(?:co|io)|oload\.tv)\/(?:f|embed)\/([\w\-]+)/);
if(match === null) {
console.error('Could not find video ID in provided URL');
phantom.exit(2);
}
id = match[1];
// thanks @Mello-Yello :)
page.onInitialized = function() {
page.evaluate(function() {
delete window._phantom;
delete window.callPhantom;
});
};
page.settings.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
page.open('https://openload.co/embed/' + id + '/', function(status) {
var info = page.evaluate(function() {
return {
decoded_id: document.getElementById('streamuri').innerHTML,
title: document.querySelector('meta[name="og:title"],'
+ 'meta[name=description]').content
};
});
var url = 'https://openload.co/stream/' + info.decoded_id + '?mime=true';
console.log(url + separator + info.title);
phantom.exit();
});
@xEmily911
Copy link

xEmily911 commented Sep 11, 2017

Does this have method restricted by API downloads? I plan to use this to mount Openload streams into JWPlayer.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Sep 11, 2017

It's the same URL as when you watch something on Openload in your browser. That means it won't work for different IP. It will probably expire too but don't know after how long. I was downloading something for 2-3h and it worked fine.

@f0nZ
Copy link

f0nZ commented Nov 5, 2017

Just a little question, when a client goes to my website and does "phantomjs openload.js <video_url>" via exec(), the ip shown on openload url is my machine's IP, not my visitor/client IP. How can I fix this? Do you have any idea? Cheers.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Nov 5, 2017

You've got two options:

  • stream the video through your server; downside: huge traffic on your server,
  • run the code on clients side; downside: client has to download phantomjs and run the code for themselves.

@dammysky
Copy link

dammysky commented Nov 15, 2017

Hi,
Thanks for this.
I will like to ask a few questions,
I added this line to my edited version of the code page.settings.resourceTimeout = 3000; hoping that should in case the page takes time to load it should timeout.
I use a Python subprocess to execute the JS. it works as expected but in some cases when I call the communicate() function the application just freezes and have to start all over.
Is there a better approach you will advise to handle this?
Thanks a lot.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Nov 15, 2017

This snippet works fine for me:

import subprocess

try:
   my_input = raw_input
except NameError:
   my_input = input

url = my_input('Enter URL: ')

p = subprocess.Popen(['phantomjs', '--ssl-protocol=any', 'openload.js',
    url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print(out)

Both in Python 2 and 3.

@DarbyCrash
Copy link

DarbyCrash commented Jan 6, 2018

This is not working again. You must change streamuri with streamurj.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Jan 6, 2018

See, when I update it they will change it again. So I'm not gonna bother.

@gonubana
Copy link

gonubana commented Jan 17, 2018

It seems like it does not work anymore even after running
sed -e "32 s/getElementById..streamur./querySelector('*[id^=streamur]/"
on this openload.js file.

I'm of course getting a similar link to "https://openload.co/stream/miEoI5oT8JE~1516281189~184.73.0.0~ImWW-Wbq?mime=true | bunny HTTP/1.1" but GETting this link only gets me a "HTTP/1.1 400 Bad Request" type response.

Is this only me or they somehow changed something else somewhere.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Jan 17, 2018

@gonubana just tested and
curl -L -k -o <filename> <generated URL>
works perfectly fine.

@Tithen-Firion
Copy link
Author

Tithen-Firion commented Jan 26, 2018

Just read 4 comments above before saying "it doesn't work".

@lawchihon
Copy link

lawchihon commented Apr 7, 2018

I don't think it is working anymore
`
TypeError: null is not an object (evaluating 'document.getElementById('streamuri').innerHTML')

undefined:3
:7
`

@JeelsBoobz
Copy link

JeelsBoobz commented Apr 10, 2018

Not work anymore :(

@aaronzolla
Copy link

aaronzolla commented May 5, 2018

#streamuri and #streamurl have been empty for a couple of weeks now.

@Narendra-WAL
Copy link

Narendra-WAL commented May 11, 2018

Did anyone find a solution for this?

@gonubana
Copy link

gonubana commented May 18, 2018

This is the current magic:
console.log('https://openload.co/stream/' + page.content.match(/\w+\d+\d+.\d+.\d+.\d+~\w+/)[0] + '?mime=true');

@feryw
Copy link

feryw commented Jul 17, 2018

it should be
console.log('https://oload.stream/stream/' + page.content.match(/\w+~\d+~\d+.\d+.\d+.\d+~\w+/)[0] + '?mime=true');
for more clear

@giuliano-oliveira
Copy link

giuliano-oliveira commented Jul 17, 2018

Since there is a domain oload.download, regex should be
/https?:\/\/(?:openload\.(?:co|io)|oload\.tv|oload\.download)\/(?:f|embed)\/([\w\-]+)/)

And, i was looking into the deobfuscated jsnice code of the source and i saw this line

if ("toString" in sin && sin.toString().indexOf("[native code") != -1 && document.getElementById.toString().indexOf("[native code") == -1 || window.callPhantom || /Phantom/.test(navigator.userAgent) || window.__phantomas || next() || window.domAutomation || window.webdriver || document.documentElement.getAttribute("webdriver"))

I guess there is some anti-measure phantomjs in the site, but aparently its not working, because @gonubana comment does captures the download URL...

@feryw
Copy link

feryw commented Jul 18, 2018

reduce regex complexity
console.log('https://oload.stream/stream/' + page.content.match(/\w+~\d+~[\d\.]+~\w+/)[0] + '?mime=true');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment