<commit_before>module Transmission
  class Client
    def on_download_finished(&blk); @on_download_finished = blk; callback_initialized; end
    def on_torrent_added(&blk); @on_torrent_added = blk; callback_initialized; end
    def on_torrent_stopped(&blk); @on_torrent_stopped = blk; callback_initialized; end
    def on_torrent_started(&blk); @on_torrent_started = blk; callback_initialized; end
    def on_torrent_removed(&blk); @on_torrent_removed = blk; callback_initialized; end
    
    def initialize(host='localhost',port=9091, username = nil, password = <PASSWORD>)
      @connection = Connection.new(host, port, username, password)
      @torrents = nil
    end
    
    def start_all &cb
      @connection.send('torrent-start')
    end
    
    def start(id)
      @connection.send('torrent-start', {'ids' => id.class == Array ? id : [id]})
    end
    
    def stop(id)
      @connection.send('torrent-stop', {'ids' => id.class == Array ? id : [id]})
    end
    
    def stop_all &cb
      @connection.send('torrent-stop')
    end
    
    def remove(id, delete_data = false)
      @connection.send('torrent-remove', {'ids' => id.class == Array ? id : [id], 'delete-local-data' => delete_data })
    end
    
    def remove_all(delete_data = false)
      @connection.send('torrent-remove', {'delete-local-data' => delete_data })
    end

    def add_tracker(id, announce = 'http://retracker.local/announce')
      @connection.send('torrent-set', {'ids' => id.class == Array ? id : [id], 'trackerAdd' => announce })
    end

    def add_torrent(a)
      if a['filename'].nil? && a['metainfo'].nil?
        raise "You need to provide either a 'filename' or 'metainfo'."
      end
      @connection.send('torrent-add', a)
    end
    
    def add_torrent_by_file(filename)
      add_torrent({'filename' => filename})
    end
    
    def add_torrent_by_data(data)
      add_torrent({'metainfo' => data})
    end


    #TODO handler for resp['status'] != 'success'
    def session
      @connection.request('session-get') do |resp|
        if resp == :connection_error
          yield :connection_error
        else
          yield Session.new resp
        end
      end
    end
    
    def session_stat
      @connection.request('session-stats') { |resp| yield SessionStat.new resp }
    end
    
    #TODO handler for resp['status'] != 'success'
    # options = { 'fields' => ['id'], 'ids' => [1,4,6] }
    def torrents(options = {})
      params = { 'fields' => Transmission::Torrent::ATTRIBUTES}.merge options
      @connection.request('torrent-get', params) { |resp|
        if resp == :connection_error
          yield :connection_error<commit_msg>Compability with prev version of arguments<commit_after>module Transmission
  class Client
    def on_download_finished(&blk); @on_download_finished = blk; callback_initialized; end
    def on_torrent_added(&blk); @on_torrent_added = blk; callback_initialized; end
    def on_torrent_stopped(&blk); @on_torrent_stopped = blk; callback_initialized; end
    def on_torrent_started(&blk); @on_torrent_started = blk; callback_initialized; end
    def on_torrent_removed(&blk); @on_torrent_removed = blk; callback_initialized; end
    
    def initialize(host='localhost',port=9091, username = nil, password = <PASSWORD>)
      @connection = Connection.new(host, port, username, password)
      @torrents = nil
    end
    
    def start_all &cb
      @connection.send('torrent-start')
    end
    
    def start(id)
      @connection.send('torrent-start', {'ids' => id.class == Array ? id : [id]})
    end
    
    def stop(id)
      @connection.send('torrent-stop', {'ids' => id.class == Array ? id : [id]})
    end
    
    def stop_all &cb
      @connection.send('torrent-stop')
    end
    
    def remove(id, delete_data = false)
      @connection.send('torrent-remove', {'ids' => id.class == Array ? id : [id], 'delete-local-data' => delete_data })
    end
    
    def remove_all(delete_data = false)
      @connection.send('torrent-remove', {'delete-local-data' => delete_data })
    end

    def add_tracker(id, announce = 'http://retracker.local/announce')
      @connection.send('torrent-set', {'ids' => id.class == Array ? id : [id], 'trackerAdd' => announce })
    end

    def add_torrent(a)
      if a['filename'].nil? && a['metainfo'].nil?
        raise "You need to provide either a 'filename' or 'metainfo'."
      end
      @connection.send('torrent-add', a)
    end
    
    def add_torrent_by_file(filename)
      add_torrent({'filename' => filename})
    end
    
    def add_torrent_by_data(data)
      add_torrent({'metainfo' => data})
    end


    #TODO handler for resp['status'] != 'success'
    def session
      @connection.request('session-get') do |resp|
        if resp == :connection_error
          yield :connection_error
        else
          yield Session.new resp
        end
      end
    end
    
    def session_stat
      @connection.request('session-stats') { |resp| yield SessionStat.new resp }
    end
    
    #TODO handler for resp['status'] != 'success'
    # options = { 'fields' => ['id'], 'ids' => [1,4,6] }
    def torrents(options = {})
      options = { 'fields' => options } if options.is_a? Array
      params = { 'fields' => Transmission::Torrent::ATTRIBUTES}.merge options
      @connection.request('torrent-get', params) { |resp|
        if resp == :connection_error
          yield :connection_error
{'fraction_non_alphanumeric': 0.13592770195499815, 'fraction_numerical': 0.0025820730357801547, 'mean_word_length': 2.9670811997073883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343128', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1719, 'n_words': 394}