<commit_before>require File.dirname(__FILE__) + '/torrent_site'
module Yggtorrent
  class Download < TorrentSite::Download
  end
  ##
  # Extract a list of results from your search
  class Search < TorrentSite::Search
    BASE_URL = 'https://yggtorrent.com'.freeze

    attr_accessor :url

    def initialize(search)
      # Order by seeds desc
      #@url = "#{BASE_URL}/engine/search?q=the+circle+2017"
      @query = search
      @url = "#{BASE_URL}/engine/search?q=#{URI.escape(search)}"
      @agent = Mechanize.new
      @agent.pluggable_parser['application/x-bittorrent'] = Mechanize::Download
      @logged = false
    end

    def download(url, destination, name)
      authenticate! unless @logged
      return unless @logged
      @agent.get(url).save("#{destination}/#{name}.torrent")
    end

    private

    def authenticate!
      if $config['yggtorrent']
        Speaker.speak_up('Authenticating on yggtorrent.')
        login = @agent.get(BASE_URL + '/user/login')
        login_form = login.forms[1]
        login_form.id = $config['yggtorrent']['username']
        login_form.pass = $<PASSWORD>['<PASSWORD>']['password']
        @agent.submit login_form
        @logged = true
      else
        Speaker.speak_up('YggTorrent not configured, cannot authenticate')
      end
    end

    def page
      @page ||= @agent.get(@url)
    end
<commit_msg>Optimization<commit_after>require File.dirname(__FILE__) + '/torrent_site'
module Yggtorrent
  class Download < TorrentSite::Download
  end
  ##
  # Extract a list of results from your search
  class Search < TorrentSite::Search
    BASE_URL = 'https://yggtorrent.com'.freeze

    attr_accessor :url

    def initialize(search)
      # Order by seeds desc
      #@url = "#{BASE_URL}/engine/search?q=the+circle+2017"
      @query = search
      @url = "#{BASE_URL}/engine/search?q=#{URI.escape(search)}"
      if $ygg_agent.nil?
        $ygg_agent = Mechanize.new
        $ygg_agent.pluggable_parser['application/x-bittorrent'] = Mechanize::Download
      end
      $ygg_logged = false
    end

    def download(url, destination, name)
      authenticate! unless $ygg_logged
      return unless $ygg_logged
      $ygg_agent.get(url).save("#{destination}/#{name}.torrent")
    end

    private

    def authenticate!
      if $config['yggtorrent']
        Speaker.speak_up('Authenticating on yggtorrent.')
        login = $ygg_agent.get(BASE_URL + '/user/login')
        login_form = login.forms[1]
        login_form.id = $config['yggtorrent']['username']
        login_form.pass = $config['<PASSWORD>']['password']
        $ygg_agent.submit login_form
        $ygg_logged = true
      else
        Speaker.speak_up('YggTorrent not configured, cannot authenticate')
      end
    end

    def page
      @page ||= $ygg_agent.get(@url)
    end

{'fraction_non_alphanumeric': 0.12491103202846975, 'fraction_numerical': 0.0035587188612099642, 'mean_word_length': 2.9314685314685316, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3695118', 'n_tokens_mistral': 932, 'n_tokens_neox': 903, 'n_words': 183}