Coder Social home page Coder Social logo

btc's Introduction

BTC

This project enables you to control uTorrent from the command line.

License

BTC is released under the MIT license.

Installation

BTC requires python 2.6.x or 2.7.x and can be installed using pip:

$ pip install -U https://github.com/bittorrent/btc/tarball/master

If you were to make changes to the source code, which is welcome, you can fork the git repository on Github and install a development setup doing:

$ python setup.py develop

You can then use pull requests if you want your changes to be integrated.

Configuration

Located in your home folder, the settings file should be named .btc. This file has to hold a valid JSON dictionary. In order to have BTC talk to uTorrent we need to set host, port, username and password settings properly. All these settings have default values so an empty settings file will be equivalent to:

{
  "host": "127.0.0.1",
  "port": 8080,
  "username": "admin",
  "password": ""
}

In order to keep this file clean you can use btc set to change settings.

$ btc set host 192.168.1.10
$ btc set port 8889

If you want to remove a setting and get the default back, you can use the --delete option to get rid of it.

$ btc set --delete host

Finally if you want to use a configuration file named differently you can set then environment variable BTC_CONFIG_FILE to another absolute path.

Usage

BTC is made to behave in a way that might surprise you at first. It is made to be piped into itself. What does it mean? When you pipe a command into another, say you type ls | grep bittorrent, the output of ls is going to be used as the input of grep and grep will output only the lines with the word bittorrent. BTC leverages this mecanism as its core way of processing data and requesting actions. Everything beggins with the list command.

$ btc list
[
  {
    "name": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "sid": "5deab0a",
    "dl_rate": 0,
    "done": 815997472,
    "peers_connected": 0,
    "seeds_connected": 0,
    "size": 815997472,
    "state": "SEEDING",
    "ul_rate": 0
  },
  {
    "name": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "sid": "5d6264e",
    "dl_rate": 0,
    "done": 477507449,
    "peers_connected": 0,
    "seeds_connected": 0,
    "size": 477507449,
    "state": "SEEDING",
    "ul_rate": 0
  }
]

This command queries uTorrent for the list of all its torrents, and BTC outputs them, using JSON format, as a list of dictionaries each dictionary being a torrent. Each torrent is reported with its name and hash but other information such as peers_connected or current state and so on. This is nice, but what next? This command can then be piped to other commands in order to filter the information you want and have BTC perform the operations you want on your uTorrent client. Let's say you want to stop the torrent named with all these 'A's.

$ btc list "A*" | btc stop

This torrent is not going to be seeded anymore by uTorrent. Don't worry, you can restart it using the start command. This is the right moment to mention that btc list takes an optional argument which filters all the torrents by name allowing glob syntax. The --case-sensitive or the shorter -s options can be used to enforce case sensitivity. Some of you might think that it is a lot more complicated than doing btc stop "A*". Fair enough, but what if you only want to stop torrents with a dl_rate of zero?

$ btc list | btc filter --key dl_rate --numeric-equals 0 | btc stop

As simple as that. The filter command is here to help you select the entries you want and reject the other ones. It can be used to filter anything BTC outputs, not only torrents, but we will see that afterwards. The filter command can have multiple arguments (see btc filter --help) such as --nth N which select the N-th entry in a list or --first N which takes the N first entries of the list. Given a key supplied with --key each entry is going to be selected if:

$ btc list | btc filter --key KEY "X*"  # it matches a string, supporting glob syntax
$ btc list | btc filter --key KEY --numeric-equals X  # its numeric value equals X
$ btc list | btc filter --key KEY --numeric-differs X # its numeric value differs from X
$ btc list | btc filter --key KEY --less X    # its numeric value is less than X
$ btc list | btc filter --key KEY --greater X # its numeric value is greater than X
$ btc list | btc filter --key KEY --true      # it is the boolean value true
$ btc list | btc filter --key KEY --false     # it is the boolean value false
...

Multiple filter commands can be piped one after the other for the output to match exactly what you want.

What about files? A torrent can have multiple files and you can list them using the files command. Hence for one or many torrents outputed by btc list, btc files lists the files inside this or these torrents.

$ btc list "A*" | btc files
[
  {
    "name": "audio_1.mp3",
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "sid": "5deab0a",
    "fileid": 0,
    "downloaded": 6579667,
    "priority": 2,
    "size": 6579667
  },
  {
    "name": "image_1.jpeg",
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "sid": "5deab0a",
    "fileid": 1,
    "downloaded": 384077,
    "priority": 2,
    "size": 384077
  },
  {
    "name": "video_6.mpg",
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "sid": "5deab0a",
    "fileid": 2,
    "downloaded": 809033728,
    "priority": 2,
    "size": 809033728
  }
]

This lists all the files of the torrent(s) given in input. The filter command can be used here again to select some of these files. But let's introduce the sort command. It allows you to sort the results by simply piping them to btc sort. By default, giving it no arguments, it is going to sort the entries by name. Another key can also be specified with the option --key if you were to sort by size for instance. You can also reverse the sort by using the option --reverse.

$ btc list | btc files | btc sort
[
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "audio_1.mp3",
    "priority": 2,
    "downloaded": 6579667,
    "sid": "5deab0a",
    "size": 6579667,
    "fileid": 0
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "image_1.jpeg",
    "priority": 2,
    "downloaded": 384077,
    "sid": "5deab0a",
    "size": 384077,
    "fileid": 1
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "image_2.jpg",
    "priority": 2,
    "downloaded": 3386455,
    "sid": "5d6264e",
    "size": 3386455,
    "fileid": 0
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "video_14.avi",
    "priority": 2,
    "downloaded": 474120994,
    "sid": "5d6264e",
    "size": 474120994,
    "fileid": 1
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "video_6.mpg",
    "priority": 2,
    "downloaded": 809033728,
    "sid": "5deab0a",
    "size": 809033728,
    "fileid": 2
  }
]

$ btc list | btc files | btc sort --key size
[
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "image_1.jpeg",
    "priority": 2,
    "downloaded": 384077,
    "sid": "5deab0a",
    "size": 384077,
    "fileid": 1
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "image_2.jpg",
    "priority": 2,
    "downloaded": 3386455,
    "sid": "5d6264e",
    "size": 3386455,
    "fileid": 0
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "audio_1.mp3",
    "priority": 2,
    "downloaded": 6579667,
    "sid": "5deab0a",
    "size": 6579667,
    "fileid": 0
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "video_14.avi",
    "priority": 2,
    "downloaded": 474120994,
    "sid": "5d6264e",
    "size": 474120994,
    "fileid": 1
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "video_6.mpg",
    "priority": 2,
    "downloaded": 809033728,
    "sid": "5deab0a",
    "size": 809033728,
    "fileid": 2
  }
]

$ btc list | btc files | btc sort --key size --reverse
[
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "video_6.mpg",
    "priority": 2,
    "downloaded": 809033728,
    "sid": "5deab0a",
    "size": 809033728,
    "fileid": 2
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "video_14.avi",
    "priority": 2,
    "downloaded": 474120994,
    "sid": "5d6264e",
    "size": 474120994,
    "fileid": 1
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "audio_1.mp3",
    "priority": 2,
    "downloaded": 6579667,
    "sid": "5deab0a",
    "size": 6579667,
    "fileid": 0
  },
  {
    "hash": "779E32E8D82521A3472FE6F93C0B29984A7FB411",
    "name": "image_2.jpg",
    "priority": 2,
    "downloaded": 3386455,
    "sid": "5d6264e",
    "size": 3386455,
    "fileid": 0
  },
  {
    "hash": "45097EB957FD45EE657A442B16F702251CBB8E35",
    "name": "image_1.jpeg",
    "priority": 2,
    "downloaded": 384077,
    "sid": "5deab0a",
    "size": 384077,
    "fileid": 1
  }
]

You can also download on your disk some files using the download command. Piping a list of files to btc download will download them to the directory from which BTC is run. To change the output directory you can use the --directory option. If you are dealing with a single file you can also rename it using the --output option. Last but not least, if uTorrent is running on Windows you need to add the --windows option so that the backslashes will be converted to forward slashes.

$ btc list | btc files | btc download
downloading: ./audio_1.mp3
downloading: ./image_1.jpeg
downloading: ./image_2.jpg
downloading: ./video_14.avi
downloading: ./video_6.mpg

$ btc list | btc files | btc download --directory /tmp
downloading: /tmp/audio_1.mp3
downloading: /tmp/image_1.jpeg
downloading: /tmp/image_2.jpg
downloading: /tmp/video_14.avi
downloading: /tmp/video_6.mpg

$ btc list | btc files | btc filter --nth 1 | btc download --output /tmp/file
downloading: /tmp/file

Want to stream? No problem, use btc stream. With files as input it will run a stream command with the appropriate streaming url. By default it outputing the stream urls to your terminal. You can provide a streaming command using the --command option.

$ btc list | btc files | btc stream
btc stream: warning: no stream command specified, outputing streaming links
audio_1.mp3: http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=0&service=DOWNLOAD&qos=0&disposition=inline
image_1.jpeg: http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=1&service=DOWNLOAD&qos=0&disposition=inline
image_2.jpg: http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=0&service=DOWNLOAD&qos=0&disposition=inline
video_14.avi: http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=1&service=DOWNLOAD&qos=0&disposition=inline
video_6.mpg: http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=2&service=DOWNLOAD&qos=0&disposition=inline
$ btc list | btc files | btc filter --nth 1 | btc stream --command mplayer
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=0&service=DOWNLOAD&qos=0&disposition=inline
$ btc list | btc files | btc stream --command mplayer
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=0&service=DOWNLOAD&qos=0&disposition=inline
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=1&service=DOWNLOAD&qos=0&disposition=inline
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=0&service=DOWNLOAD&qos=0&disposition=inline
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=1&service=DOWNLOAD&qos=0&disposition=inline
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=2&service=DOWNLOAD&qos=0&disposition=inline

If you want to play all the files using a single instance of the command you may use the option --together which has the following behavior:

$ btc list | btc files | btc stream --command mplayer --together
running: mplayer http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=0&service=DOWNLOAD&qos=0&disposition=inline http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=1&service=DOWNLOAD&qos=0&disposition=inline http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=0&service=DOWNLOAD&qos=0&disposition=inline http://admin:@127.0.0.1:8080/proxy?sid=5d6264e&file=1&service=DOWNLOAD&qos=0&disposition=inline http://admin:@127.0.0.1:8080/proxy?sid=5deab0a&file=2&service=DOWNLOAD&qos=0&disposition=inline

Here is the way to add a torrent by url or using a file on your computer:

$ btc add http://www.clearbits.net/get/547-home-2009.torrent
$ btc add "home project - home 2009.torrent"

And then you can remove the torrent from your downloads keeping or not the torrent file and dropping or not the data:

$ btc list "Home Project - Home 2009" | btc remove
$ btc list "Home Project - Home 2009" | btc remove --keep-torrent
$ btc list "Home Project - Home 2009" | btc remove --drop-data
$ btc list "Home Project - Home 2009" | btc remove --keep-torrent --drop-data

Finally the wait command simply waits for a torrent to complete. You can use that to run a command when the torrent is complete, shutdown for instance...

$ btc list "Home Project - Home 2009" | btc wait && shutdown

btc's People

Contributors

kissiel avatar moussu avatar polosaty avatar qfiard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btc's Issues

btc list: error

(pytorrent_server:2.7)[djalmabr@h32 pytorrent_server]$ btc set host 177.85.98.245
(pytorrent_server:2.7)[djalmabr@h32 pytorrent_server]$ btc set port 8080
(pytorrent_server:2.7)[djalmabr@h32 pytorrent_server]$ btc list
btc list: error: connection failed, try to modify the settings file
note: settings file is: /home/djalmabr/.btc
note: current settings are:
host: 177.85.98.245
password: gauther780
port: 8080
username: admin

Error when filesize is 0

Got exception "float division by zero" when calculating progress of filesize 0.

This can be found in btclient.py line 229.

Add support for getsettings

Perhaps I am missing it, but it seems that it's currently not possible to modify uTorrent's global settings through getsettings Web API with btc. Such option would be very useful.

Cannot add magnet links

It appears that magnet links do not work, as I get the following error:

$ btc add magnet:?xt=urn:btih:91ea15451a642d7ff25485e0441ae869b86b4467&dn=ubuntu-12.04.2-desktop-i386.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337
[1] 30326
[2] 30327
[3] 30328
[4] 30329
[5] 30330
[6] 30331
[2]   Done                    dn=ubuntu-12.04.2-desktop-i386.iso
[3]   Done                    tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80
[4]   Done                    tr=udp%3A%2F%2Ftracker.publicbt.com%3A80
[5]-  Done                    tr=udp%3A%2F%2Ftracker.istole.it%3A6969

scott@box:~/Desktop$ Traceback (most recent call last):
  File "/usr/local/bin/btc", line 8, in <module>
    load_entry_point('btc==0.1', 'console_scripts', 'btc')()
  File "/Library/Python/2.7/site-packages/btc/btc.py", line 169, in main
    module.main()
  File "/Library/Python/2.7/site-packages/btc/btc_add.py", line 27, in main
    torrent = utils.get(args.value, utf8=False)
  File "/Library/Python/2.7/site-packages/btc/utils.py", line 109, in get
    response, content = make_request(h, host + selector, headers=headers)
  File "/Library/Python/2.7/site-packages/btc/utils.py", line 67, in make_request
    return http.request(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/httplib2/__init__.py", line 1454, in request
    proxy_info=proxy_info)
  File "/Library/Python/2.7/site-packages/httplib2/__init__.py", line 860, in __init__
    httplib.HTTPConnection.__init__(self, host, port, strict)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 693, in __init__
    self._set_hostport(host, port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 718, in _set_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: ''

[1]-  Exit 1                  btc add magnet:?xt=urn:btih:91ea15451a642d7ff25485e0441ae869b86b4467
[6]+  Done                    tr=udp%3A%2F%2Ftracker.ccc.de%3A80

tabs in btclient.py file

After installing in python 3 using pip:
pip install -U https://github.com/bittorrent/btc/tarball/master
I get this error when trying to use help for the add command:

$ btc add --help
Traceback (most recent call last):
  File "/usr/local/bin/btc", line 6, in <module>
    from btc.btc import main
  File "/usr/local/lib/python3.7/site-packages/btc/btc.py", line 7, in <module>
    from .btclient import BTClient, BTClientError
  File "/usr/local/lib/python3.7/site-packages/btc/btclient.py", line 233
    f['progress'] = 0.0
                      ^
TabError: inconsistent use of tabs and spaces in indentation

The btclient.py file is the only offender:

drogers@drogers-mbp:~/code/python/btc/btc (master)
$ ls
__init__.py     btc_add.py      btc_filter.py   btc_reduce.py   btc_set.py      btc_start.py    btc_wait.py
bencode.py      btc_download.py btc_list.py     btc_remove.py   btc_show.py     btc_stop.py     btclient.py
btc.py          btc_files.py    btc_recheck.py  btc_select.py   btc_sort.py     btc_stream.py   utils.py
drogers@drogers-mbp:~/code/python/btc/btc (master)
$ egrep '\t' *.py
btclient.py:			f['progress'] = 0.0
btclient.py:			f['progress'] = round(100. * l[2] / l[1], 2)

Add label?

I am sorry I had to go through issues to make contact but I dont know how else to do it. I realise this is hasnt been touched for a while. All I want to know is if there is a way of adding a label using this program? If the function isnt there but can be implemented easily I will try and do it if I can get some pointers on what to modify. Thanks for a handy little program

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.