qbittorrent 1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1a3812a79a260400595e389a56c86f356173b41384e3326f3ad7b0f72777b432
4
+ data.tar.gz: 2123789d9dee0e7e62a842422a5a2c293e403a8fc396493a8d472d99c07aa8c8
5
+ SHA512:
6
+ metadata.gz: 7615e38c3df23ad84596b6536e5dd5c67a918839436b969e73b7c097dbb82416f43c0c152482412c78b059b66c27a5e1186507c1c91355871fd4e2fff633a717
7
+ data.tar.gz: 017f2ee40149c1e06fa388137a75cebc56bb1b1c113e1c0214d2d5efa7ff874c612222e8870d95a520ef7e830a38480f4fb7b3f550c680eb379432e6c6eb2c39
@@ -0,0 +1,22 @@
1
+ name: "Build gem to rubygems.org"
2
+ on:
3
+ push:
4
+ tags:
5
+ - "v*"
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - name: "git"
11
+ uses: actions/checkout@v2
12
+ - name: "publishing gem"
13
+ env:
14
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
15
+ run: |
16
+ mkdir -p $HOME/.gem
17
+ touch $HOME/.gem/credentials
18
+ chmod 0600 $HOME/.gem/credentials
19
+ printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
20
+ cd $GITHUB_WORKSPACE
21
+ gem build *.gemspec
22
+ gem push *.gem
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .byebug_history
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+ NewCops: enable
4
+ Exclude:
5
+ - qbittorrent.gemspec
6
+ Style/Documentation:
7
+ Enabled: false
8
+ Metrics/MethodLength:
9
+ Max: 50
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
12
+ Naming/AccessorMethodName:
13
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qbittorrent.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rubocop', '~> 1.16'
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qbittorrent (1.3)
5
+ http (~> 4.4.1)
6
+ logger (~> 1.4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.2)
14
+ domain_name (0.5.20190701)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ ffi (1.15.4)
17
+ ffi-compiler (1.0.1)
18
+ ffi (>= 1.0.0)
19
+ rake
20
+ http (4.4.1)
21
+ addressable (~> 2.3)
22
+ http-cookie (~> 1.0)
23
+ http-form_data (~> 2.2)
24
+ http-parser (~> 1.2.0)
25
+ http-cookie (1.0.4)
26
+ domain_name (~> 0.5)
27
+ http-form_data (2.3.0)
28
+ http-parser (1.2.3)
29
+ ffi-compiler (>= 1.0, < 2.0)
30
+ logger (1.4.3)
31
+ parallel (1.20.1)
32
+ parser (3.0.1.1)
33
+ ast (~> 2.4.1)
34
+ public_suffix (4.0.6)
35
+ rainbow (3.0.0)
36
+ rake (12.3.3)
37
+ regexp_parser (2.1.1)
38
+ rexml (3.2.5)
39
+ rubocop (1.16.1)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.0.0.0)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml
45
+ rubocop-ast (>= 1.7.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 3.0)
48
+ rubocop-ast (1.7.0)
49
+ parser (>= 3.0.1.1)
50
+ ruby-progressbar (1.11.0)
51
+ unf (0.1.4)
52
+ unf_ext
53
+ unf_ext (0.0.8)
54
+ unicode-display_width (2.0.0)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ qbittorrent!
61
+ rake (~> 12.0)
62
+ rubocop (~> 1.16)
63
+
64
+ BUNDLED WITH
65
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Roy Zheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # QbittorrentClient
2
+
3
+ A Qbittorrent Web API Client, only support [WebUI API (qBittorrent 4.1+)](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)>).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'qbittorrent'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install qbittorrent
20
+
21
+ # Usage
22
+
23
+ ```
24
+ client = QBittorrent::Api.new("http://localhost:8080", "admin", "password")
25
+ ```
26
+
27
+ ## Authentication
28
+
29
+ ### **[Login](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)>)**
30
+
31
+ ```
32
+ client.login
33
+ ```
34
+
35
+ ### **[Logout](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#logout>)**
36
+
37
+ ```
38
+ client.logout
39
+ ```
40
+
41
+ ## Application
42
+
43
+ ### **[Get application version](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-application-version>)**
44
+
45
+ ```
46
+ client.application_version
47
+ ```
48
+
49
+ ### **[Get API version](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-api-version>)**
50
+
51
+ ```
52
+ client.api_version
53
+ ```
54
+
55
+ ### **[Get build info](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-build-info>)**
56
+
57
+ ```
58
+ client.build_info
59
+ ```
60
+
61
+ ### **[Get application preferences](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-application-preferences>)**
62
+
63
+ ```
64
+ client.preferences
65
+ ```
66
+
67
+ ### **[Set application preferences](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#set-application-preferences)**
68
+ ```
69
+ client.set_preferences(options)
70
+ ```
71
+
72
+ ### **[Shutdown application](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#shutdown-application>)**
73
+
74
+ ```
75
+ client.shutdown
76
+ ```
77
+
78
+ ### **[Get default save path](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-default-save-path>)**
79
+
80
+ ```
81
+ client.default_save_path
82
+ ```
83
+
84
+ ### **[Get torrent list](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list)**
85
+ ```
86
+ client.get_torrents(options)
87
+ ```
88
+ ### **[Delete torrents](https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#delete-torrents)**
89
+ ```
90
+ client.delete_torrents(hashes, delete_files)
91
+ ```
92
+ ### **[Add new torrents](<https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#add-new-torrent>)**
93
+
94
+ ```
95
+ client.add_torrents(urls_of_file_path, options)
96
+ ```
97
+
98
+ ## License
99
+
100
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'qbittorrent'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require 'http'
2
+ require 'logger'
3
+ require 'qbittorrent/web_api/response'
4
+ require 'qbittorrent/web_api/core'
5
+ require 'qbittorrent/web_api/authorize'
6
+ require 'qbittorrent/web_api/app'
7
+ require 'qbittorrent/web_api/torrent'
8
+
9
+ module QBittorrent
10
+ class Api
11
+ include QBittorrent::WebApi::Core
12
+ include QBittorrent::WebApi::Authroize
13
+ include QBittorrent::WebApi::App
14
+ include QBittorrent::WebApi::Torrent
15
+
16
+ attr_accessor :host, :username, :password, :cookies, :logger, :global_options
17
+
18
+ def initialize(host, username, password, logger = nil, **global_options)
19
+ @host = host.delete_suffix('/')
20
+ @username = username
21
+ @password = password
22
+ @logger = logger ? Logger.new(logger) : nil
23
+ @global_options = global_options
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module QBittorrent
2
+ VERSION = '1.3'.freeze
3
+ end
@@ -0,0 +1,47 @@
1
+ module QBittorrent
2
+ module WebApi
3
+ module App
4
+ def application_version
5
+ send_request('/app/version') do |api_url|
6
+ api_client.get(api_url)
7
+ end
8
+ end
9
+
10
+ def api_version
11
+ send_request('/app/webapiVersion') do |api_url|
12
+ api_client.get(api_url)
13
+ end
14
+ end
15
+
16
+ def build_info
17
+ send_request('/app/buildInfo') do |api_url|
18
+ api_client.get(api_url)
19
+ end
20
+ end
21
+
22
+ def preferences
23
+ send_request('/app/preferences') do |api_url|
24
+ api_client.get(api_url)
25
+ end
26
+ end
27
+
28
+ def set_preferences(**options)
29
+ send_request('/app/setPreferences') do |api_url|
30
+ api_client.post(api_url, form: { json: options.to_json })
31
+ end
32
+ end
33
+
34
+ def default_save_path
35
+ send_request('/app/defaultSavePath') do |api_url|
36
+ api_client.get(api_url)
37
+ end
38
+ end
39
+
40
+ def shutdown
41
+ send_request('/app/shutdown') do |api_url|
42
+ api_client.post(api_url)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ module QBittorrent
2
+ module WebApi
3
+ module Authroize
4
+ def login
5
+ response = api_client.post("#{host}/api/v2/auth/login", form: {
6
+ username: username,
7
+ password: password
8
+ })
9
+ raise QBittorrent::Error.new('Authroize faild', response) unless response.headers['set-cookie']
10
+
11
+ @cookies = response.headers['set-cookie'].split(';')[0]
12
+ end
13
+
14
+ def logout
15
+ response = api_client.post("#{host}/api/v2/auth/logout")
16
+ @cookies = nil
17
+ response
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module QBittorrent
2
+ module WebApi
3
+ module Core
4
+ private
5
+
6
+ def api_client
7
+ headers = {
8
+ 'Referer' => host
9
+ }
10
+ headers.merge!('Cookie' => cookies) if cookies
11
+ http = HTTP.headers(headers)
12
+ http = http.use(logging: { logger: logger }) if logger
13
+ http = http.timeout(global_options[:timeout]) if global_options[:timeout]
14
+ http
15
+ end
16
+
17
+ def send_request(api_path)
18
+ api_url = "#{host}/api/v2#{api_path}"
19
+ login unless cookies
20
+ response = yield(api_url)
21
+ raise QBittorrent::Error, "Response faild #{response.status.code}" unless response.status.success?
22
+
23
+ QBittorrent::WebApi::Response.new(true, response)
24
+ rescue QBittorrent::Error => e
25
+ QBittorrent::WebApi::Response.new(false, e.response, e.message)
26
+ rescue StandardError => e
27
+ QBittorrent::WebApi::Response.new(false, response, e.message)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module QBittorrent
2
+ module WebApi
3
+ class Response
4
+ attr_accessor :is_success, :response, :message, :data
5
+
6
+ def initialize(is_success, response, message = nil)
7
+ @is_success = is_success
8
+ @response = response
9
+ @message = message
10
+ @data = begin
11
+ JSON.parse(response.to_s)
12
+ rescue StandardError => _e
13
+ response.to_s
14
+ end
15
+ end
16
+
17
+ def success?
18
+ is_success
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ module QBittorrent
2
+ module WebApi
3
+ module Torrent
4
+ def get_torrents(**options)
5
+ send_request('/torrents/info') do |api_url|
6
+ api_client.get(api_url, params: options)
7
+ end
8
+ end
9
+
10
+ def add_torrents(url_or_file_path, **options)
11
+ send_request('/torrents/add') do |api_url|
12
+ url_or_file_path.gsub!(/^\s+|\s+$/, '')
13
+ if %r{^http://|https://|magnet://}i =~ url_or_file_path
14
+ options.merge!(urls: url_or_file_path)
15
+ else
16
+ options.merge!(torrents: HTTP::FormData::File.new(url_or_file_path))
17
+ end
18
+ api_client.post(api_url, form: options)
19
+ end
20
+ end
21
+
22
+ def delete_torrents(hashes, delete_files = false)
23
+ send_request("/torrents/delete") do |api_url|
24
+ api_client.post(api_url, form: {
25
+ hashes: hashes,
26
+ deleteFiles: delete_files
27
+ })
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,12 @@
1
+ require 'qbittorrent/version'
2
+ require 'qbittorrent/api'
3
+ module QBittorrent
4
+ class Error < StandardError
5
+ attr_reader :response
6
+
7
+ def initialize(message, response)
8
+ super(message)
9
+ @response = response
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/qbittorrent/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'qbittorrent'
5
+ spec.version = QBittorrent::VERSION
6
+ spec.authors = ['Roy Zheng']
7
+ spec.email = ['github@roy.cc']
8
+
9
+ spec.summary = 'QBittorrent WEB API Client.'
10
+ spec.description = 'QBittorrent WEB API Client.only support qBittorrent v4.1+.'
11
+ spec.homepage = 'https://github.com/royzheng/qbittorrent'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/royzheng/qbittorrent'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/royzheng/qbittorrent'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'http', '~> 4.4.1'
29
+ spec.add_dependency 'logger', '~> 1.4'
30
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qbittorrent
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.3'
5
+ platform: ruby
6
+ authors:
7
+ - Roy Zheng
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.4.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ description: QBittorrent WEB API Client.only support qBittorrent v4.1+.
42
+ email:
43
+ - github@roy.cc
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/gem.yml"
49
+ - ".gitignore"
50
+ - ".rubocop.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/qbittorrent.rb
59
+ - lib/qbittorrent/api.rb
60
+ - lib/qbittorrent/version.rb
61
+ - lib/qbittorrent/web_api/app.rb
62
+ - lib/qbittorrent/web_api/authorize.rb
63
+ - lib/qbittorrent/web_api/core.rb
64
+ - lib/qbittorrent/web_api/response.rb
65
+ - lib/qbittorrent/web_api/torrent.rb
66
+ - qbittorrent.gemspec
67
+ homepage: https://github.com/royzheng/qbittorrent
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/royzheng/qbittorrent
72
+ source_code_uri: https://github.com/royzheng/qbittorrent
73
+ changelog_uri: https://github.com/royzheng/qbittorrent
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.8
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: QBittorrent WEB API Client.
93
+ test_files: []