Class: QbtClient::WebUI
- Inherits:
-
Object
- Object
- QbtClient::WebUI
- Includes:
- HTTParty
- Defined in:
- lib/qbt_client/web_ui.rb
Instance Method Summary collapse
-
#add_trackers(torrent_hash, urls) ⇒ Object
Add one or more trackers to a torrent.
-
#authenticate ⇒ Object
Authenticate with the server.
-
#contents(torrent_hash) ⇒ Object
Get torrent contents (files data).
-
#decrease_priority(torrent_hashes) ⇒ Object
Decrease the priority of one or more torrents.
-
#delete(torrent_hashes) ⇒ Object
Delete one or more torrents (doesn’t delete their data).
-
#delete_torrent_and_data(torrent_hashes) ⇒ Object
Delete one or more torrents AND THEIR DATA.
-
#download(urls) ⇒ Object
Begin downloading one or more torrents.
-
#download_limit(torrent_hash) ⇒ Object
Get a torrent’s download limit.
-
#global_download_limit ⇒ Object
Get the application’s global download limit.
-
#global_upload_limit ⇒ Object
Get the application’s global upload limit.
-
#increase_priority(torrent_hashes) ⇒ Object
Increase the priority of one or more torrents.
-
#initialize(ip, port, user, pass) ⇒ WebUI
constructor
constructor.
-
#maximize_priority(torrent_hashes) ⇒ Object
Increase the priority of one or more torrents to the maximum value.
-
#minimize_priority(torrent_hashes) ⇒ Object
Decrease the priority of one or more torrents to the minimum value.
-
#pause(torrent_hash) ⇒ Object
Pause a torrent.
-
#pause_all ⇒ Object
Pause all torrents.
-
#preferences ⇒ Object
Get application preferences (options).
-
#properties(torrent_hash) ⇒ Object
Get properties of a torrent (different data than what’s returned in #torrent_list).
-
#recheck(torrent_hash) ⇒ Object
Recheck a torrent.
-
#resume(torrent_hash) ⇒ Object
Resume downloading/seeding of a torrent.
-
#resume_all ⇒ Object
Resume downloading/seeding of all torrents.
-
#set_download_limit(torrent_hash, limit) ⇒ Object
Set a torrent’s download limit.
-
#set_file_priority(torrent_hash, file_id, priority) ⇒ Object
Set the download priority of a file within a torrent.
-
#set_global_download_limit(limit) ⇒ Object
Set the application’s global download limit.
-
#set_global_upload_limit(limit) ⇒ Object
Set the application’s global upload limit.
-
#set_preferences(pref_hash) ⇒ Object
Set application preferences.
-
#set_upload_limit(torrent_hash, limit) ⇒ Object
Set a torrent’s upload limit.
- #torrent_data(torrent_hash) ⇒ Object
-
#torrent_list ⇒ Object
Get array of all torrents.
-
#trackers(torrent_hash) ⇒ Object
Get tracker data for a torrent.
-
#transfer_info ⇒ Object
Get application transfer info.
-
#upload_limit(torrent_hash) ⇒ Object
Get a torrent’s upload limit.
Constructor Details
#initialize(ip, port, user, pass) ⇒ WebUI
constructor
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/qbt_client/web_ui.rb', line 27 def initialize(ip, port, user, pass) @ip = ip @port = port @user = user @pass = pass @sid = nil #self.class.digest_auth(user, pass) self.class.base_uri "#{ip}:#{port}" authenticate self.class..(@sid) end |
Instance Method Details
#add_trackers(torrent_hash, urls) ⇒ Object
Add one or more trackers to a torrent
If passing mulitple urls, pass them as an array.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/qbt_client/web_ui.rb', line 179 def add_trackers torrent_hash, urls urls = Array(urls) # Ampersands in urls must be escaped. urls = urls.map { |url| url.gsub('&', '%26') } urls = urls.join('%0A') = { body: "hash=#{torrent_hash}&urls=#{urls}" } self.class.post('/command/addTrackers', ) end |
#authenticate ⇒ Object
Authenticate with the server
Login with username and password. Store returned SID cookie value used as auth token for later calls.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/qbt_client/web_ui.rb', line 47 def authenticate = { body: "username=#{@user}&password=#{@pass}" } # Have to clear out the cookies or the old SID gets sent while requesting # the new SID (and it fails). self.class..clear res = self.class.post('/login', ) if res.success? token = res.headers["Set-Cookie"] raise "Login failed" if token.nil? token = token.split(";")[0] #token = token.split("SID=")[1] @sid = token end end |
#contents(torrent_hash) ⇒ Object
Get torrent contents (files data)
Example response:
[
{
"is_seed"=>false,
"name"=>"Grimm.S04E12.720p.HDTV.X264-DIMENSION.mkv",
"priority"=>1,
"progress"=>0.0,
"size"=>"825.4 MiB"
}
]
206 207 208 209 |
# File 'lib/qbt_client/web_ui.rb', line 206 def contents torrent_hash self.class.format :json self.class.get('/query/propertiesFiles/' + torrent_hash).parsed_response end |
#decrease_priority(torrent_hashes) ⇒ Object
Decrease the priority of one or more torrents
If passing multiple torrent hashes, pass them as an array. Note: This does nothing unless queueing has been enabled via preferences.
443 444 445 446 447 448 449 450 451 452 |
# File 'lib/qbt_client/web_ui.rb', line 443 def decrease_priority torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/decreasePrio', ) end |
#delete(torrent_hashes) ⇒ Object
Delete one or more torrents (doesn’t delete their data)
If passing multiple torrent hashes, pass them as an array.
396 397 398 399 400 401 402 403 404 405 |
# File 'lib/qbt_client/web_ui.rb', line 396 def delete torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/delete', ) end |
#delete_torrent_and_data(torrent_hashes) ⇒ Object
Delete one or more torrents AND THEIR DATA
If passing multiple torrent hashes, pass them as an array.
380 381 382 383 384 385 386 387 388 389 |
# File 'lib/qbt_client/web_ui.rb', line 380 def delete_torrent_and_data torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/deletePerm', ) end |
#download(urls) ⇒ Object
Begin downloading one or more torrents.
If passing mulitple urls, pass them as an array.
364 365 366 367 368 369 370 371 372 373 |
# File 'lib/qbt_client/web_ui.rb', line 364 def download urls urls = Array(urls) urls = urls.join('%0A') = { body: "urls=#{urls}" } self.class.post('/command/download', ) end |
#download_limit(torrent_hash) ⇒ Object
Get a torrent’s download limit
A limit of 0 means unlimited.
Returns an integer (bytes)
570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/qbt_client/web_ui.rb', line 570 def download_limit torrent_hash self.class.format :json = { body: "hashes=#{torrent_hash}" } self.class .post('/command/getTorrentsDlLimit', ) .parsed_response[torrent_hash] end |
#global_download_limit ⇒ Object
Get the application’s global download limit
A limit of 0 means unlimited.
Returns an integer (bytes)
512 513 514 515 |
# File 'lib/qbt_client/web_ui.rb', line 512 def global_download_limit self.class.format :json self.class.post('/command/getGlobalDlLimit').parsed_response end |
#global_upload_limit ⇒ Object
Get the application’s global upload limit
A limit of 0 means unlimited.
Returns an integer (bytes)
541 542 543 544 |
# File 'lib/qbt_client/web_ui.rb', line 541 def global_upload_limit self.class.format :json self.class.post('/command/getGlobalUpLimit').parsed_response end |
#increase_priority(torrent_hashes) ⇒ Object
Increase the priority of one or more torrents
If passing multiple torrent hashes, pass them as an array. Note: This does nothing unless queueing has been enabled via preferences.
425 426 427 428 429 430 431 432 433 434 |
# File 'lib/qbt_client/web_ui.rb', line 425 def increase_priority torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/increasePrio', ) end |
#maximize_priority(torrent_hashes) ⇒ Object
Increase the priority of one or more torrents to the maximum value
If passing multiple torrent hashes, pass them as an array. Note: This does nothing unless queueing has been enabled via preferences.
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/qbt_client/web_ui.rb', line 461 def maximize_priority torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/topPrio', ) end |
#minimize_priority(torrent_hashes) ⇒ Object
Decrease the priority of one or more torrents to the minimum value
If passing multiple torrent hashes, pass them as an array. Note: This does nothing unless queueing has been enabled via preferences.
479 480 481 482 483 484 485 486 487 488 |
# File 'lib/qbt_client/web_ui.rb', line 479 def minimize_priority torrent_hashes torrent_hashes = Array(torrent_hashes) torrent_hashes = torrent_hashes.join('|') = { body: "hashes=#{torrent_hashes}" } self.class.post('/command/bottomPrio', ) end |
#pause(torrent_hash) ⇒ Object
Pause a torrent
326 327 328 329 330 331 332 |
# File 'lib/qbt_client/web_ui.rb', line 326 def pause torrent_hash = { body: "hash=#{torrent_hash}" } self.class.post('/command/pause', ) end |
#pause_all ⇒ Object
Pause all torrents
337 338 339 |
# File 'lib/qbt_client/web_ui.rb', line 337 def pause_all self.class.post('/command/pauseAll') end |
#preferences ⇒ Object
Get application preferences (options)
Example response:
{
"alt_dl_limit"=>10,
"alt_up_limit"=>10,
"anonymous_mode"=>false,
"autorun_enabled"=>false,
"autorun_program"=>"",
"bypass_local_auth"=>false,
"dht"=>true,
"dhtSameAsBT"=>true,
"dht_port"=>6881,
"dl_limit"=>-1,
"dont_count_slow_torrents"=>false,
"download_in_scan_dirs"=>[],
"dyndns_domain"=>"changeme.dyndns.org",
"dyndns_enabled"=>false,
"dyndns_password"=>"",
"dyndns_service"=>0,
"dyndns_username"=>"",
"enable_utp"=>true,
"encryption"=>0,
"export_dir"=>"",
"export_dir_enabled"=>false,
"incomplete_files_ext"=>false,
"ip_filter_enabled"=>false,
"ip_filter_path"=>"",
"limit_tcp_overhead"=>false,
"limit_utp_rate"=>true,
"listen_port"=>6881,
"locale"=>"en_US",
"lsd"=>true,
"mail_notification_auth_enabled"=>false,
"mail_notification_email"=>"",
"mail_notification_enabled"=>false,
"mail_notification_password"=>"",
"mail_notification_smtp"=>"smtp.changeme.com",
"mail_notification_ssl_enabled"=>false,
"mail_notification_username"=>"",
"max_active_downloads"=>3,
"max_active_torrents"=>5,
"max_active_uploads"=>3,
"max_connec"=>500,
"max_connec_per_torrent"=>100,
"max_uploads_per_torrent"=>4,
"pex"=>true,
"preallocate_all"=>false,
"proxy_auth_enabled"=>false,
"proxy_ip"=>"0.0.0.0",
"proxy_password"=>"",
"proxy_peer_connections"=>false,
"proxy_port"=>8080,
"proxy_type"=>-1,
"proxy_username"=>"",
"queueing_enabled"=>false,
"save_path"=>"/home/jeff/Downloads",
"scan_dirs"=>[],
"schedule_from_hour"=>8,
"schedule_from_min"=>0,
"schedule_to_hour"=>20,
"schedule_to_min"=>0,
"scheduler_days"=>0,
"scheduler_enabled"=>false,
"ssl_cert"=>"",
"ssl_key"=>"",
"temp_path"=>"/home/jeff/Downloads/temp",
"temp_path_enabled"=>false,
"up_limit"=>50,
"upnp"=>true,
"use_https"=>false,
"web_ui_password"=>"ae150cdc82b40c4373d2e15e0ffe8f67",
"web_ui_port"=>8083,
"web_ui_username"=>"admin"
}
302 303 304 305 |
# File 'lib/qbt_client/web_ui.rb', line 302 def preferences self.class.format :json self.class.get('/query/preferences').parsed_response end |
#properties(torrent_hash) ⇒ Object
Get properties of a torrent (different data than what’s returned in #torrent_list).
Example response:
{
"comment"=>"Visit us: https://eztv.ch/ - Bitcoin: 1EZTVaGQ6UsjYJ9fwqGnd45oZ6HGT7WKZd",
"creation_date"=>"Friday, February 6, 2015 8:01:22 PM MST",
"dl_limit"=>"∞",
"nb_connections"=>"0 (100 max)",
"piece_size"=>"512.0 KiB",
"save_path"=>"/home/jeff/Downloads/",
"share_ratio"=>"0.0",
"time_elapsed"=>"< 1m",
"total_downloaded"=>"646.8 KiB (657.8 KiB this session)",
"total_uploaded"=>"0 B (0 B this session)",
"total_wasted"=>"428 B",
"up_limit"=>"∞"
}
137 138 139 140 |
# File 'lib/qbt_client/web_ui.rb', line 137 def properties torrent_hash self.class.format :json self.class.get('/query/propertiesGeneral/' + torrent_hash).parsed_response end |
#recheck(torrent_hash) ⇒ Object
Recheck a torrent
410 411 412 413 414 415 416 |
# File 'lib/qbt_client/web_ui.rb', line 410 def recheck torrent_hash = { body: "hash=#{torrent_hash}" } self.class.post('/command/recheck', ) end |
#resume(torrent_hash) ⇒ Object
Resume downloading/seeding of a torrent
344 345 346 347 348 349 350 |
# File 'lib/qbt_client/web_ui.rb', line 344 def resume torrent_hash = { body: "hash=#{torrent_hash}" } self.class.post('/command/resume', ) end |
#resume_all ⇒ Object
Resume downloading/seeding of all torrents
355 356 357 |
# File 'lib/qbt_client/web_ui.rb', line 355 def resume_all self.class.post('/command/resumeAll') end |
#set_download_limit(torrent_hash, limit) ⇒ Object
Set a torrent’s download limit
A limit of 0 means unlimited.
torrent_hash: string limit: integer (bytes)
590 591 592 593 594 595 596 597 598 |
# File 'lib/qbt_client/web_ui.rb', line 590 def set_download_limit torrent_hash, limit query = ["hashes=#{torrent_hash}", "limit=#{limit}"] = { body: query.join('&') } self.class.post('/command/setTorrentsDlLimit', ) end |
#set_file_priority(torrent_hash, file_id, priority) ⇒ Object
Set the download priority of a file within a torrent
file_id is a 0 based position of the file within the torrent
495 496 497 498 499 500 501 502 503 |
# File 'lib/qbt_client/web_ui.rb', line 495 def set_file_priority torrent_hash, file_id, priority query = ["hash=#{torrent_hash}", "id=#{file_id}", "priority=#{priority}"] = { body: query.join('&') } self.class.post('/command/setFilePrio', ) end |
#set_global_download_limit(limit) ⇒ Object
Set the application’s global download limit
A limit of 0 means unlimited.
limit: integer (bytes)
524 525 526 527 528 529 530 531 532 |
# File 'lib/qbt_client/web_ui.rb', line 524 def set_global_download_limit limit query = "limit=#{limit}" = { body: query } self.class.post('/command/setGlobalDlLimit', ) end |
#set_global_upload_limit(limit) ⇒ Object
Set the application’s global upload limit
A limit of 0 means unlimited.
limit: integer (bytes)
553 554 555 556 557 558 559 560 561 |
# File 'lib/qbt_client/web_ui.rb', line 553 def set_global_upload_limit limit query = "limit=#{limit}" = { body: query } self.class.post('/command/setGlobalUpLimit', ) end |
#set_preferences(pref_hash) ⇒ Object
Set application preferences
Note: When setting password, pass it as plain text. You can send only the key/value pairs you want to change (in a hash), rather than the entire set of data.
314 315 316 317 318 319 320 321 |
# File 'lib/qbt_client/web_ui.rb', line 314 def set_preferences pref_hash pref_hash = Hash(pref_hash) = { body: "json=#{pref_hash.to_json}" } self.class.post('/command/setPreferences', ) end |
#set_upload_limit(torrent_hash, limit) ⇒ Object
Set a torrent’s upload limit
A limit of 0 means unlimited.
torrent_hash: string limit: integer (bytes)
627 628 629 630 631 632 633 634 635 |
# File 'lib/qbt_client/web_ui.rb', line 627 def set_upload_limit torrent_hash, limit query = ["hashes=#{torrent_hash}", "limit=#{limit}"] = { body: query.join('&') } self.class.post('/command/setTorrentsUpLimit', ) end |
#torrent_data(torrent_hash) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/qbt_client/web_ui.rb', line 107 def torrent_data torrent_hash torrents = torrent_list torrents.each do |t| if t["hash"] == torrent_hash return t end end end |
#torrent_list ⇒ Object
Get array of all torrents
Example response:
[
{
"dlspeed"=>"3.1 MiB/s",
"eta"=>"9m",
"hash"=>"156b69b8643bd11849a5d8f2122e13fbb61bd041",
"name"=>"slackware64-14.1-iso",
"num_leechs"=>"1 (14)",
"num_seeds"=>"97 (270)",
"priority"=>"*",
"progress"=>0.172291,
"ratio"=>"0.0",
"size"=>"2.2 GiB",
"state"=>"downloading",
"upspeed"=>"0 B/s"
},
{
"dlspeed"=>"1.8 KiB/s",
"eta"=>"28d 1h",
"hash"=>"1fe5775d32d3e58e48b3a96dd2883c5250882cda",
"name"=>"Grimm.S04E12.720p.HDTV.X264-DIMENSION.mkv",
"num_leechs"=>"7 (471)",
"num_seeds"=>"15 (1866)",
"priority"=>"*",
"progress"=>1.53669e-07,
"ratio"=>"0.0",
"size"=>"825.4 MiB",
"state"=>"downloading",
"upspeed"=>"0 B/s"
}
]
102 103 104 105 |
# File 'lib/qbt_client/web_ui.rb', line 102 def torrent_list self.class.format :json self.class.get('/query/torrents').parsed_response end |
#trackers(torrent_hash) ⇒ Object
Get tracker data for a torrent
Example response:
[
{
"msg"=>"",
"num_peers"=>"0",
"status"=>"Working",
"url"=>"udp://open.demonii.com:1337"},
{
"msg"=>"",
"num_peers"=>"0",
"status"=>"Not contacted yet",
"url"=>"udp://tracker.coppersurfer.tk:6969"},
{
"msg"=>"",
"num_peers"=>"0",
"status"=>"Not contacted yet",
"url"=>"udp://tracker.leechers-paradise.org:6969"},
{
"msg"=>"",
"num_peers"=>"0",
"status"=>"Not contacted yet",
"url"=>"udp://exodus.desync.com:6969"}
]
169 170 171 172 |
# File 'lib/qbt_client/web_ui.rb', line 169 def trackers torrent_hash self.class.format :json self.class.get('/query/propertiesTrackers/' + torrent_hash).parsed_response end |
#transfer_info ⇒ Object
Get application transfer info
Example response:
{
"dl_info"=>"D: 0 B/s/s - T: 657.8 KiB",
"up_info"=>"U: 0 B/s/s - T: 0 B"
}
220 221 222 223 |
# File 'lib/qbt_client/web_ui.rb', line 220 def transfer_info self.class.format :json self.class.get('/query/transferInfo').parsed_response end |
#upload_limit(torrent_hash) ⇒ Object
Get a torrent’s upload limit
A limit of 0 means unlimited.
Returns an integer (bytes)
607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/qbt_client/web_ui.rb', line 607 def upload_limit torrent_hash self.class.format :json = { body: "hashes=#{torrent_hash}" } self.class .post('/command/getTorrentsUpLimit', ) .parsed_response[torrent_hash] end |