asapach / peerflix-server

Streaming torrent client for Node.js with web ui.
MIT License
1.31k stars 586 forks source link

How i can add new torrent from magnet link? #154

Closed MindOnFire93 closed 6 years ago

MindOnFire93 commented 6 years ago

How i can add new torrent using the magnet link from shell command or php cli?

asapach commented 6 years ago

Try using REST API - POST /torrents PHP must have an HTTP client, so you can send the request that way. Otherwise you could use something like curl from the shell.

MindOnFire93 commented 6 years ago

Hello, i try to send the POST through html, using JSON, like that code:

function show_alert() { alert("Sending Request"); var xhr = new XMLHttpRequest(); xhr.open(form.method, form.action, true); xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); var j = { "link":"magnet:?xt=urn:btih:hash", }; xhr.send(JSON.stringify(j)); }

but i got the error page;

" TypeError: path must be a string or Buffer at TypeError (native) at Object.fs.readFile (fs.js:305:11) at readTorrent (/usr/lib/node_modules/peerflix-server/node_modules/read-torrent/index.js:54:8) at EventEmitter.add (/usr/lib/node_modules/peerflix-server/server/store.js:36:5) at /usr/lib/node_modules/peerflix-server/server/index.js:69:9 at callbacks (/usr/lib/node_modules/peerflix-server/node_modules/express/lib/router/index.js:164:37) at param (/usr/lib/node_modules/peerflix-server/node_modules/express/lib/router/index.js:138:11) at pass (/usr/lib/node_modules/peerflix-server/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/usr/lib/node_modules/peerflix-server/node_modules/express/lib/router/index.js:173:5) at Object.router (/usr/lib/node_modules/peerflix-server/node_modules/express/lib/router/index.js:33:10)"

so please help me understand how to send it the magnet link data, or using shell or php-cli or simple post from input box.. Thanks

asapach commented 6 years ago

Judging by the stacktrace it's not able to parse the magnet link. Are you sure it's valid? If you can debug locally try adding a console log here to see what the value of req.body.link is: https://github.com/asapach/peerflix-server/blob/733b6c22b1dc30de7b15065ba0aa4fa1ba86de5a/server/index.js#L69

MindOnFire93 commented 6 years ago

exaple i try post like this, but nothing, what is the syntax of this magnet.. <?php

$data = array( 'link' => 'magnet:?xt=urn:btih:hash_info' );

$json = json_encode($data);

$client = new Zend_Http_Client($uri); $client->setRawData($json, 'application/json')->request('POST');

?>

asapach commented 6 years ago

I've tried your original example and it worked fine for me:

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:9000/torrents', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
var j = {
    "link":"magnet:?xt=urn:btih:a7883604bd5fa7b02f3766a24f4e4f805aa436b3",
};
xhr.send(JSON.stringify(j));

Unfortunately I'm not familiar with PHP to help you with your http client.

MindOnFire93 commented 6 years ago

I can do it in html page too, sending it with input box and function, i try, but it don't work..., i don't have some experience with JSON, probably i call it in wrong way :( Really idk..

MindOnFire93 commented 6 years ago

Fine it finally work, i wrong to call the function, Thanks you a lot :)..

asapach commented 6 years ago

No problem.

MindOnFire93 commented 6 years ago

Antoher question, the download and upload of peer-flix can be limited, I MEAN THE SEED AND LEECH of any file, like utorrent, speed limit to max (number)? And if how to config this? Maybe if you send me the configuration syntax in one url, I would be grateful to you. Thanks, Mind

asapach commented 6 years ago

There's no way to throttle the speed, unfortunately. The only things you can configure are (https://github.com/mafintosh/torrent-stream#full-api): connections and uploads. You can set them using the configuration file

MindOnFire93 commented 6 years ago

Thank you so much. Have a nice day :)