[GH-ISSUE #154] How i can add new torrent from magnet link? #343

Closed
opened 2026-03-15 03:04:21 +03:00 by kerem · 11 comments
Owner

Originally created by @MindOnFire93 on GitHub (Oct 9, 2018).
Original GitHub issue: https://github.com/asapach/peerflix-server/issues/154

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

Originally created by @MindOnFire93 on GitHub (Oct 9, 2018). Original GitHub issue: https://github.com/asapach/peerflix-server/issues/154 How i can add new torrent using the magnet link from shell command or php cli?
kerem 2026-03-15 03:04:21 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@asapach commented on GitHub (Oct 9, 2018):

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.

<!-- gh-comment-id:428121467 --> @asapach commented on GitHub (Oct 9, 2018): Try using [REST API](https://github.com/asapach/peerflix-server/blob/master/REST.md) - `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.
Author
Owner

@MindOnFire93 commented on GitHub (Oct 10, 2018):

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

<!-- gh-comment-id:428565884 --> @MindOnFire93 commented on GitHub (Oct 10, 2018): 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
Author
Owner

@asapach commented on GitHub (Oct 10, 2018):

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: github.com/asapach/peerflix-server@733b6c22b1/server/index.js (L69)

<!-- gh-comment-id:428576521 --> @asapach commented on GitHub (Oct 10, 2018): 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
Author
Owner

@MindOnFire93 commented on GitHub (Oct 10, 2018):

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

'magnet:?xt=urn:btih:hash_info' ); $json = json_encode($data); $client = new Zend_Http_Client($uri); $client->setRawData($json, 'application/json')->request('POST'); ?>
<!-- gh-comment-id:428693083 --> @MindOnFire93 commented on GitHub (Oct 10, 2018): 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'); ?>
Author
Owner

@asapach commented on GitHub (Oct 10, 2018):

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.

<!-- gh-comment-id:428727165 --> @asapach commented on GitHub (Oct 10, 2018): I've tried your original example and it worked fine for me: ```js 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.
Author
Owner

@MindOnFire93 commented on GitHub (Oct 10, 2018):

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..

<!-- gh-comment-id:428744529 --> @MindOnFire93 commented on GitHub (Oct 10, 2018): 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..
Author
Owner

@MindOnFire93 commented on GitHub (Oct 10, 2018):

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

<!-- gh-comment-id:428747845 --> @MindOnFire93 commented on GitHub (Oct 10, 2018): Fine it finally work, i wrong to call the function, Thanks you a lot :)..
Author
Owner

@asapach commented on GitHub (Oct 10, 2018):

No problem.

<!-- gh-comment-id:428755149 --> @asapach commented on GitHub (Oct 10, 2018): No problem.
Author
Owner

@MindOnFire93 commented on GitHub (Oct 10, 2018):

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

<!-- gh-comment-id:428766411 --> @MindOnFire93 commented on GitHub (Oct 10, 2018): 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_
Author
Owner

@asapach commented on GitHub (Oct 10, 2018):

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

<!-- gh-comment-id:428767921 --> @asapach commented on GitHub (Oct 10, 2018): 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](https://github.com/asapach/peerflix-server#configuration)
Author
Owner

@MindOnFire93 commented on GitHub (Oct 11, 2018):

Thank you so much. Have a nice day :)

<!-- gh-comment-id:428772916 --> @MindOnFire93 commented on GitHub (Oct 11, 2018): Thank you so much. Have a nice day :)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/peerflix-server#343
No description provided.