zooqle_search 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 623cddd1874d3b8d8680dcbd0e0cff19270bcaf9
4
+ data.tar.gz: b801c8b1e729cb467f03feb53d6f3760c24b0631
5
+ SHA512:
6
+ metadata.gz: a005e9d18329fb50df9d9d91a3fb7a473217080b0cbf1bca77433d92ff5ba62c0f4e2364e83066705885cb5a8088900dec6ac2dcb89635e3aba2af384d23fe7b
7
+ data.tar.gz: 73f1a9e3797c406bc188f34c8b8254feaa1e45de97040117c56dd881d3af80df781ab64af5164c39fc5328c0a00e406451c020aeb59251137a89ed7d471e600d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ - 2.1.5
6
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kat_search.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', cmd: 'bundle exec rspec', all_after_pass: false, failed_mode: :none do
2
+ watch(%r{\Aspec/.+_spec\.rb\z})
3
+ watch(%r{\Alib/(.+)\.rb\z}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 David Marchante
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,41 @@
1
+ # KatSearch
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kat_search`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kat_search'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kat_search
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kat_search.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'zooqle_search'
5
+ require 'factory_girl'
6
+
7
+ include FactoryGirl::Syntax::Methods
8
+ FactoryGirl.find_definitions
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+ # link = build :link
13
+ search = build :search
14
+
15
+ # (If you use this, don't forget to add pry to your Gemfile!)
16
+ require 'pry'
17
+ Pry.start
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
data/exe/zooqle_search ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby -w
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w( .. lib ))
3
+
4
+ require 'zooqle_search'
5
+ require 'fileutils'
6
+ require 'highline'
7
+ require 'optparse'
8
+
9
+ options = {
10
+ path: './'
11
+ }
12
+
13
+ optparse = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: zooqle_search [options] <search>'
15
+
16
+ opts.on('-y', '--auto-download', 'Download first result without confirmation') do
17
+ options[:auto] = true
18
+ end
19
+
20
+ opts.on('-m', '--magnet', 'Print magnet link and exit') do
21
+ options[:magnet] = true
22
+ end
23
+
24
+ opts.on('-p PATH', '--path PATH', 'Path to save the file') do |p|
25
+ options[:path] = p
26
+ end
27
+
28
+ opts.on('-v', '--version', 'Print version and exit') do
29
+ puts "zooqle_search v#{ZooqleSearch::VERSION}"
30
+ exit
31
+ end
32
+
33
+ opts.on_tail('-h', '--help', 'Show this message') do
34
+ puts opts
35
+ exit
36
+ end
37
+ end.parse!
38
+
39
+ # Join arguments to create the search term
40
+ options[:search] = optparse.join(' ')
41
+
42
+ # main program
43
+ begin
44
+ cli = HighLine.new
45
+ HighLine.colorize_strings # Monkey patch String for cli colors
46
+
47
+ # Valid search?
48
+ if options[:search].empty?
49
+ cli.say 'Please type a search'.red
50
+ exit
51
+ end
52
+
53
+ # Search subtitle
54
+ search = ZooqleSearch::Search.new(options[:search])
55
+
56
+ # Results found?
57
+ unless search.results_found?
58
+ cli.say 'No results found'.red
59
+ exit
60
+ end
61
+
62
+ # Choose
63
+ if options[:auto]
64
+ torrent = search.links.first
65
+ else
66
+ cli.say "Search results for #{options[:search]}:"
67
+ torrent = cli.choose(*search.links) do |menu|
68
+ menu.default = '1'
69
+ menu.select_by = :index
70
+ end
71
+ end
72
+
73
+ # Download torrent or print magnet link
74
+ if options[:magnet]
75
+ cli.say torrent.magnet
76
+ else
77
+ torrent_file = torrent.download(options[:path])
78
+ cli.say "#{torrent_file} downloaded successfully!".green
79
+ end
80
+ rescue Interrupt, EOFError
81
+ cli.say 'Interrupted!'.red
82
+ rescue SocketError
83
+ cli.say "Couldn't perform action. Are you online?".red
84
+ end
@@ -0,0 +1,3 @@
1
+ require 'zooqle_search/version'
2
+ require 'zooqle_search/search'
3
+ require 'zooqle_search/link'
@@ -0,0 +1,52 @@
1
+ require 'cgi'
2
+ require 'httparty'
3
+
4
+ module ZooqleSearch
5
+ ##
6
+ # Object that contains the info for a torrent file
7
+ class Link
8
+ attr_reader :filename, :size, :magnet, :download_url, :seeders, :leechers
9
+
10
+ def initialize(filename, size, magnet, download_url, seeders, leechers)
11
+ @filename = filename
12
+ @size = size
13
+ @magnet = magnet
14
+ @download_url = download_url
15
+ @seeders = seeders.tr(',', '').to_i
16
+ @leechers = leechers.tr(',', '').to_i
17
+ end
18
+
19
+ def <=>(other)
20
+ @seeders <=> other.seeders
21
+ end
22
+
23
+ def to_s
24
+ "#{@filename} (#{@size}) - [#{@seeders.to_s.green}/#{@leechers.to_s.red}]"
25
+ end
26
+
27
+ def info_hash
28
+ @info_hash ||= extract_hash
29
+ end
30
+
31
+ def download(path = './')
32
+ response = HTTParty.get(@download_url)
33
+
34
+ raise 'Wrong content-type. Aborting.' unless response.headers['content-type'].include? 'application/x-bittorrent'
35
+
36
+ # Get file name from the url
37
+ filename = @filename + '.torrent'
38
+ open(File.join(path, filename), 'w') { |f| f << response }
39
+
40
+ # return filename
41
+ filename
42
+ end
43
+
44
+ private
45
+
46
+ def extract_hash
47
+ # Extract magnet properties to a Hash and then parse the sha1 info hash
48
+ raw_hash = magnet[/(xt.*?)&/, 1] # extract the xt property
49
+ raw_hash.split(':').last.downcase
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,62 @@
1
+ require 'erb'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'yaml'
5
+
6
+ module ZooqleSearch
7
+ ##
8
+ # Extract a list of results from your search
9
+ # Zooqle.new("Suits s05e16 1080p")
10
+ class Search
11
+ NUMBER_OF_LINKS = 5
12
+ BASE_URL = "https://zooqle.com"
13
+
14
+ attr_accessor :url
15
+
16
+ def initialize(search)
17
+ @url = "#{BASE_URL}/search?q=#{ERB::Util.url_encode(search)}"
18
+ end
19
+
20
+ def results_found?
21
+ @results_found ||= page.at('p:contains("Sorry, no torrents match your query.")').nil?
22
+ rescue OpenURI::HTTPError
23
+ @results_found = false
24
+ end
25
+
26
+ def links
27
+ @links ||= generate_links
28
+ end
29
+
30
+ private
31
+
32
+ def page
33
+ @page ||= Nokogiri::HTML(open(@url))
34
+ end
35
+
36
+ def generate_links
37
+ links = []
38
+ return links unless results_found?
39
+
40
+ crawled_links = page.css('.table-torrents tr')
41
+
42
+ crawled_links.each do |link|
43
+ filename = link.at('a').text
44
+ next if filename.strip.empty?
45
+
46
+ size = link.at('.progress-bar').text
47
+ magnet = link.at('a[title="Magnet link"]')['href']
48
+ download_url = BASE_URL + link.at('a[title="Generate .torrent"]')['href']
49
+
50
+ seeders_leechers = link.at('div[title^="Seeders:"]')['title']
51
+ seeders = seeders_leechers[/Seeders: (?<seeders>[\d,]+) \| Leechers: (?<leechers>[\d,]+)/, :seeders]
52
+ leechers = seeders_leechers[/Seeders: (?<seeders>[\d,]+) \| Leechers: (?<leechers>[\d,]+)/, :leechers]
53
+
54
+ links << Link.new(filename, size, magnet, download_url, seeders, leechers)
55
+ end
56
+
57
+ links.sort!.reverse!
58
+
59
+ return links.first(NUMBER_OF_LINKS)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module ZooqleSearch
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zooqle_search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'zooqle_search'
8
+ spec.version = ZooqleSearch::VERSION
9
+ spec.authors = ['David Marchante']
10
+ spec.email = ['davidmarchan@gmail.com']
11
+
12
+ spec.summary = 'Search Zooqle Torrents.'
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/iovis9/zooqle_search.git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
23
+ spec.add_runtime_dependency 'highline', '~> 1.7'
24
+ spec.add_runtime_dependency 'httparty', '~> 0.13'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.12'
27
+ spec.add_development_dependency 'rake', '~> 11.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'guard-rspec', '~> 4.6'
30
+ spec.add_development_dependency 'factory_girl', '~> 4.5'
31
+ spec.add_development_dependency 'webmock', '~> 2.0'
32
+ spec.add_development_dependency 'pry', '~> 0.10'
33
+ spec.add_development_dependency 'pry-byebug', '~> 3.3'
34
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zooqle_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Marchante
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '11.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '11.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: factory_girl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.10'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry-byebug
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.3'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.3'
167
+ description:
168
+ email:
169
+ - davidmarchan@gmail.com
170
+ executables:
171
+ - zooqle_search
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".travis.yml"
178
+ - Gemfile
179
+ - Guardfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - exe/zooqle_search
186
+ - lib/zooqle_search.rb
187
+ - lib/zooqle_search/link.rb
188
+ - lib/zooqle_search/search.rb
189
+ - lib/zooqle_search/version.rb
190
+ - zooqle_search.gemspec
191
+ homepage: https://github.com/iovis9/zooqle_search.git
192
+ licenses:
193
+ - MIT
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.6.4
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Search Zooqle Torrents.
215
+ test_files: []