rtorrent_xmlrpc 0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -0
- data/lib/rtorrent_xmlrpc.rb +113 -18
- data/rtorrent_xmlrpc.gemspec +3 -2
- metadata +22 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: aec5bd8704d971c6eed048549bcb34ab77c1f203
         | 
| 4 | 
            +
              data.tar.gz: dcb43f75567b59bb2d7527765f8466e2e19d7553
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 774572a3be0c2293acb2bf20808ebef6260f120905e1e36816b6bfa7cfe674c61274a806378af820984fa8912c8f80b809bdc4600b31f72ef29f9040f6ccc5fb
         | 
| 7 | 
            +
              data.tar.gz: df05f889605f03f46efa6b4c739c2dd78c3cca46cbc55aa50bb570c2218897fc7c41be5db6cb5690c567a9940667d9303f467d1ca016555a7cb682bb52d3d23c
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -3,6 +3,7 @@ PATH | |
| 3 3 | 
             
              specs:
         | 
| 4 4 | 
             
                rtorrent_xmlrpc (0.1)
         | 
| 5 5 | 
             
                  colorize (~> 0.7, >= 0.7.7)
         | 
| 6 | 
            +
                  filesize (~> 0.1, >= 0.1.0)
         | 
| 6 7 | 
             
                  hashie (~> 3.4, >= 3.4.2)
         | 
| 7 8 | 
             
                  thor (~> 0.19, >= 0.19.1)
         | 
| 8 9 |  | 
| @@ -10,6 +11,7 @@ GEM | |
| 10 11 | 
             
              remote: https://rubygems.org/
         | 
| 11 12 | 
             
              specs:
         | 
| 12 13 | 
             
                colorize (0.7.7)
         | 
| 14 | 
            +
                filesize (0.1.0)
         | 
| 13 15 | 
             
                hashie (3.4.2)
         | 
| 14 16 | 
             
                rake (10.4.2)
         | 
| 15 17 | 
             
                thor (0.19.1)
         | 
    
        data/lib/rtorrent_xmlrpc.rb
    CHANGED
    
    | @@ -1,45 +1,117 @@ | |
| 1 1 | 
             
            require 'colorize'
         | 
| 2 | 
            +
            require 'filesize'
         | 
| 2 3 | 
             
            require 'hashie'
         | 
| 3 4 | 
             
            require 'xmlrpc/client'
         | 
| 4 5 |  | 
| 5 6 | 
             
            module RTorrent
         | 
| 6 7 |  | 
| 7 8 | 
             
              class Torrent
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                # Attributes
         | 
| 8 11 | 
             
                attr_accessor :hash, :name, :completed, :base_filename, :base_path, :is_multi_file, :tied_to_file
         | 
| 9 | 
            -
                attr_reader :labels
         | 
| 12 | 
            +
                attr_reader :down_total, :labels, :priority, :ratio, :size, :up_total
         | 
| 10 13 |  | 
| 11 | 
            -
                def  | 
| 12 | 
            -
                  @ | 
| 14 | 
            +
                def down_total=(down_total) # :nodoc:
         | 
| 15 | 
            +
                  @down_total = Filesize.new(down_total)
         | 
| 13 16 | 
             
                end
         | 
| 14 17 |  | 
| 15 | 
            -
                def labels=(labels)
         | 
| 18 | 
            +
                def labels=(labels) # :nodoc:
         | 
| 16 19 | 
             
                  @labels = labels.split(',')
         | 
| 20 | 
            +
                  @labels.map! { |label| label.chomp }
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def labels_str
         | 
| 24 | 
            +
                  @labels.join(', ')
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def priority=(priority) # :nodoc:
         | 
| 28 | 
            +
                  begin
         | 
| 29 | 
            +
                    @priority = priority.to_i
         | 
| 30 | 
            +
                  rescue
         | 
| 31 | 
            +
                    @priority = 2
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                # Return priority converted to a human readable string
         | 
| 36 | 
            +
                def priority_str
         | 
| 37 | 
            +
                  case @priority
         | 
| 38 | 
            +
                  when 0
         | 
| 39 | 
            +
                    "Off"
         | 
| 40 | 
            +
                  when 1
         | 
| 41 | 
            +
                    "Low"
         | 
| 42 | 
            +
                  when 2
         | 
| 43 | 
            +
                    "Normal"
         | 
| 44 | 
            +
                  when 3
         | 
| 45 | 
            +
                    "High"
         | 
| 46 | 
            +
                  else
         | 
| 47 | 
            +
                    "Unknown"
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def ratio=(ratio) # :nodoc:
         | 
| 52 | 
            +
                  begin
         | 
| 53 | 
            +
                    @ratio = ratio.to_f
         | 
| 54 | 
            +
                  rescue
         | 
| 55 | 
            +
                    @ratio = 0.0
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def size=(size) # :nodoc:
         | 
| 60 | 
            +
                  @size = Filesize.new(size)
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def up_total=(up_total) # :nodoc:
         | 
| 64 | 
            +
                  @up_total = Filesize.new(up_total)
         | 
| 17 65 | 
             
                end
         | 
| 18 66 |  | 
| 67 | 
            +
                # Return hash of all values in Torrent
         | 
| 19 68 | 
             
                def to_h
         | 
| 20 69 | 
             
                  {
         | 
| 21 | 
            -
                    hash: @hash,
         | 
| 22 | 
            -
                    name: @name,
         | 
| 23 | 
            -
                    labels: @labels,
         | 
| 24 | 
            -
                    completed: @completed,
         | 
| 25 70 | 
             
                    base_filename: @base_filename,
         | 
| 26 71 | 
             
                    base_path: @base_path,
         | 
| 72 | 
            +
                    completed: @completed,
         | 
| 73 | 
            +
                    hash: @hash,
         | 
| 27 74 | 
             
                    is_multi_file: @is_multi_file,
         | 
| 75 | 
            +
                    labels: @labels,
         | 
| 76 | 
            +
                    name: @name,
         | 
| 77 | 
            +
                    priority: @priority,
         | 
| 78 | 
            +
                    ratio: @ratio,
         | 
| 79 | 
            +
                    size: @size,
         | 
| 28 80 | 
             
                    tied_to_file: @tied_to_file,
         | 
| 29 81 | 
             
                  }
         | 
| 30 82 | 
             
                end
         | 
| 31 83 |  | 
| 84 | 
            +
                # Single line header
         | 
| 85 | 
            +
                def self.header
         | 
| 86 | 
            +
                  "hash : name : size : down : up : ratio : labels"
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                # All torrent data in a single string for output to screen
         | 
| 90 | 
            +
                def to_s
         | 
| 91 | 
            +
                  "#{self.hash} : #{self.name} : #{self.size.pretty} : #{self.down_total.pretty} : #{self.up_total.pretty} : #{self.ratio} : #{self.labels_str}"
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                # All torrent data dumped to screen in color
         | 
| 32 95 | 
             
                def pp
         | 
| 33 96 | 
             
                  puts "-------------- ".red
         | 
| 34 | 
            -
                  puts "         hash: ".blue +  | 
| 35 | 
            -
                  puts "         name: ".blue +  | 
| 36 | 
            -
                  puts " | 
| 37 | 
            -
                  puts " | 
| 38 | 
            -
                  puts " | 
| 39 | 
            -
                  puts " | 
| 40 | 
            -
                  puts " | 
| 41 | 
            -
                  puts " | 
| 97 | 
            +
                  puts "         hash: ".blue + self.hash.green
         | 
| 98 | 
            +
                  puts "         name: ".blue + self.name.green
         | 
| 99 | 
            +
                  puts "         size: ".blue + self.size.pretty.green
         | 
| 100 | 
            +
                  puts "   downloaded: ".blue + self.down_total.pretty.green
         | 
| 101 | 
            +
                  puts "     uploaded: ".blue + self.up_total.pretty.green
         | 
| 102 | 
            +
                  puts "        ratio: ".blue + self.ratio.to_s.green
         | 
| 103 | 
            +
                  puts "     priority: ".blue + self.priority_str.green
         | 
| 104 | 
            +
                  puts "       labels: ".blue + self.labels_str.green
         | 
| 105 | 
            +
                  puts "    completed: ".blue + self.completed.to_s.green
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                # FILTERS
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                # Test if torrent has a specific label
         | 
| 111 | 
            +
                def has_label?(label)
         | 
| 112 | 
            +
                  @labels.include? label.to_s
         | 
| 42 113 | 
             
                end
         | 
| 114 | 
            +
             | 
| 43 115 | 
             
              end
         | 
| 44 116 |  | 
| 45 117 | 
             
              class XMLRPC
         | 
| @@ -85,7 +157,25 @@ module RTorrent | |
| 85 157 | 
             
                def fetch_torrents
         | 
| 86 158 | 
             
                  self.connect unless @status == :connected
         | 
| 87 159 | 
             
                  @torrents = []
         | 
| 88 | 
            -
                   | 
| 160 | 
            +
                  args = [
         | 
| 161 | 
            +
                    'd.multicall',
         | 
| 162 | 
            +
                    'main',
         | 
| 163 | 
            +
                    'd.hash=',
         | 
| 164 | 
            +
                    'd.name=',
         | 
| 165 | 
            +
                    'd.custom1=',
         | 
| 166 | 
            +
                    'd.complete=',
         | 
| 167 | 
            +
                    'd.base_filename=',
         | 
| 168 | 
            +
                    'd.base_path=',
         | 
| 169 | 
            +
                    'd.is_multi_file=',
         | 
| 170 | 
            +
                    'd.tied_to_file=',
         | 
| 171 | 
            +
                    'd.get_size_bytes=',
         | 
| 172 | 
            +
                    'd.get_down_total=',
         | 
| 173 | 
            +
                    'd.get_up_total=',
         | 
| 174 | 
            +
                    'd.get_ratio=',
         | 
| 175 | 
            +
                    'd.get_priority=',
         | 
| 176 | 
            +
                  ]
         | 
| 177 | 
            +
                  #@server.call('d.multicall', 'main', 'd.hash=', 'd.name=', 'd.custom1=', 'd.complete=', 'd.base_filename=', 'd.base_path=', 'd.is_multi_file=', 'd.tied_to_file=', 'd.get_size').each do |stats|
         | 
| 178 | 
            +
                  @server.call(*args).each do |stats|
         | 
| 89 179 | 
             
                    torrent = RTorrent::Torrent.new
         | 
| 90 180 | 
             
                    torrent.hash = stats[0]
         | 
| 91 181 | 
             
                    torrent.name = stats[1]
         | 
| @@ -95,6 +185,11 @@ module RTorrent | |
| 95 185 | 
             
                    torrent.base_path = stats[5]
         | 
| 96 186 | 
             
                    torrent.is_multi_file = stats[6] == 1 ? true: false
         | 
| 97 187 | 
             
                    torrent.tied_to_file = stats[7]
         | 
| 188 | 
            +
                    torrent.size = stats[8]
         | 
| 189 | 
            +
                    torrent.down_total = stats[9]
         | 
| 190 | 
            +
                    torrent.up_total = stats[10]
         | 
| 191 | 
            +
                    torrent.ratio = stats[11].to_f / 1000
         | 
| 192 | 
            +
                    torrent.priority = stats[12]
         | 
| 98 193 | 
             
                    @torrents << torrent
         | 
| 99 194 | 
             
                  end
         | 
| 100 195 | 
             
                end
         | 
| @@ -131,7 +226,7 @@ module RTorrent | |
| 131 226 | 
             
                # Get a list of torrents with label
         | 
| 132 227 | 
             
                def with_label(label)
         | 
| 133 228 | 
             
                  result = []
         | 
| 134 | 
            -
                  @torrents.each { |torrent| result << torrent if torrent.has_label | 
| 229 | 
            +
                  @torrents.each { |torrent| result << torrent if torrent.has_label? label }
         | 
| 135 230 | 
             
                  return result
         | 
| 136 231 | 
             
                end
         | 
| 137 232 | 
             
              end
         | 
    
        data/rtorrent_xmlrpc.gemspec
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            Gem::Specification.new do |s|
         | 
| 2 2 | 
             
              s.name        = 'rtorrent_xmlrpc'
         | 
| 3 | 
            -
              s.version     = '0.1'
         | 
| 4 | 
            -
              s.date        = '2015-07- | 
| 3 | 
            +
              s.version     = '0.1.1'
         | 
| 4 | 
            +
              s.date        = '2015-07-03'
         | 
| 5 5 | 
             
              s.summary     = 'A library and tool to query an rtorrent xmlrpc service.'
         | 
| 6 6 | 
             
              s.authors     = ['Zan Loy']
         | 
| 7 7 | 
             
              s.email       = 'zan.loy@gmail.com'
         | 
| @@ -12,6 +12,7 @@ Gem::Specification.new do |s| | |
| 12 12 |  | 
| 13 13 | 
             
              s.add_dependency 'colorize', '~> 0.7', '>= 0.7.7'
         | 
| 14 14 | 
             
              s.add_dependency 'hashie', '~> 3.4', '>= 3.4.2'
         | 
| 15 | 
            +
              s.add_dependency 'filesize', '~> 0.1', '>= 0.1.0'
         | 
| 15 16 | 
             
              s.add_dependency 'thor', '~> 0.19', '>= 0.19.1'
         | 
| 16 17 |  | 
| 17 18 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rtorrent_xmlrpc
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 0.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Zan Loy
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-07- | 
| 11 | 
            +
            date: 2015-07-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         | 
| @@ -50,6 +50,26 @@ dependencies: | |
| 50 50 | 
             
                - - ">="
         | 
| 51 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 52 52 | 
             
                    version: 3.4.2
         | 
| 53 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 54 | 
            +
              name: filesize
         | 
| 55 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 56 | 
            +
                requirements:
         | 
| 57 | 
            +
                - - "~>"
         | 
| 58 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            +
                    version: '0.1'
         | 
| 60 | 
            +
                - - ">="
         | 
| 61 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 62 | 
            +
                    version: 0.1.0
         | 
| 63 | 
            +
              type: :runtime
         | 
| 64 | 
            +
              prerelease: false
         | 
| 65 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - "~>"
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: '0.1'
         | 
| 70 | 
            +
                - - ">="
         | 
| 71 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 72 | 
            +
                    version: 0.1.0
         | 
| 53 73 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 54 74 | 
             
              name: thor
         | 
| 55 75 | 
             
              requirement: !ruby/object:Gem::Requirement
         |