Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pause/resume, refactored code, improved command line interface, etc #514

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

added getBySearch method

  • Loading branch information
whitef0x0 committed Nov 27, 2015
commit 01a685aa8f4ce326cc93285000b97bcb94cceabc
@@ -1,5 +1,7 @@
#!/usr/bin/env node

var search = require('search-kat.ph')
var choices = require('choices')
var clivas = require('clivas')
var cp = require('child_process')
var createTorrent = require('create-torrent')
@@ -142,6 +144,8 @@ if (command === 'help' || argv.help) {
runDownload(/* torrentId */ argv._[1])
} else if (command === 'seed') {
runSeed(/* input */ argv._[1])
} else if (command === 'search'){
runSearch(/* query */ argv._[1])
} else if (command) {
// assume command is "download" when not specified
runDownload(/* torrentId */ command)
@@ -462,6 +466,39 @@ function runDownload (torrentId) {
}
}

function runSearch (input_query) {
if(!input_query) {
var showUsage = function showUsage() {
var pathToBin = path.join(
path.relative(
process.cwd(),
path.dirname(process.argv[1])
),
path.basename(process.argv[1])
);

clivas.line('{green:Usage: }')
clivas.line('{green: '+process.argv[0] + ' ' + pathToBin + ' "query"'+'}')
};
}else{
search(input_query).then(function(search_results) {
choices('Select your torrent (by index)', search_results.slice(0, 9).filter(function(r){ if(r.torrent || r.magnet) return }).map(function(r) { return r.name + ' [' + r.size + ' / ' + r.files + ' files] ' + r.seeds + '/' + r.leech; }), function(index) {
if (index === null) {
return
}

console.log(search_results[index])
if(/^magnet:/.test(search_results[index].magnet)) {
runDownload(search_results[index].magnet)
}else {
return
}

});
});
}
}

function runSeed (input) {
if (path.extname(input).toLowerCase() === '.torrent' || /^magnet:/.test(input)) {
// `webtorrent seed` is meant for creating a new torrent based on a file or folder
@@ -1,5 +1,6 @@
module.exports = WebTorrent

var search = require('kat-search.ph')
var createTorrent = require('create-torrent')
var debug = require('debug')('webtorrent')
var DHT = require('bittorrent-dht/client') // browser exclude
@@ -107,6 +108,16 @@ Object.defineProperty(WebTorrent.prototype, 'ratio', {
}
})

WebTorrent.prototype.getBySearch = function (query) {
var self = this
if(!query) return

search(query).then(function(search_results) {
search_results = search_results.slice(0, 9).filter(function(r){ if(r.torrent || r.magnet) return })
return self.get(search_results[0].magnet)
}
}

/**
* Returns the torrent with the given `torrentId`. Convenience method. Easier than
* searching through the `client.torrents` array. Returns `null` if no matching torrent
@@ -25,6 +25,7 @@
"bitfield": "^1.0.2",
"bittorrent-dht": "^3.0.0",
"bittorrent-swarm": "^5.0.0",
"choices": "^0.1.3",
"chunk-store-stream": "^2.0.0",
"clivas": "^0.2.0",
"create-torrent": "^3.4.0",
@@ -54,6 +55,7 @@
"range-parser": "^1.0.2",
"re-emitter": "^1.0.0",
"run-parallel": "^1.0.0",
"search-kat.ph": "github:whitef0x0/search-kat.ph",
"simple-sha1": "^2.0.0",
"speedometer": "^0.1.2",
"thunky": "^0.1.0",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.