extratorrent_search 1.0.0

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: 18731b9a28e36f1eedd6649ba478a20499e5abc7
4
+ data.tar.gz: f1ac02457f2b2bf8a8c0de43786155734bb3cd2e
5
+ SHA512:
6
+ metadata.gz: 64abede84f0bf030d34ed9c0a6670d3f2c450d82646738654d3e9ddd4963b910b9f814e6fd4c18208e1adc5f007cbdf0abe1a4bdb5608e2ec53ea3a81964cf0f
7
+ data.tar.gz: 0526e1eda40ed12d36e504f1135b237ff9226938f825e7eb74fb0b407cc9356c1268c2636564c9ce3b9e217b94e8a86fcff1f4c3929415e896a727669a618c0c
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,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in extratorrent_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
+ # ExtratorrentSearch
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/extratorrent_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 'extratorrent_search'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install extratorrent_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]/extratorrent_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,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'extratorrent_search'
5
+ require 'factory_girl'
6
+
7
+ include FactoryGirl::Syntax::Methods
8
+ FactoryGirl.find_definitions
9
+
10
+ # search = build :search, search: 'silicon valley s03e08'
11
+ search = build :search
12
+ search_failed = build :search_failed
13
+
14
+ require 'pry'
15
+ 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
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby -w
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'extratorrent_search'
6
+ require 'fileutils'
7
+ require 'highline'
8
+ require 'optparse'
9
+
10
+ options = {
11
+ path: './'
12
+ }
13
+
14
+ optparse = OptionParser.new do |opts|
15
+ opts.banner = 'Usage: extratorrent_search [options] <search>'
16
+
17
+ opts.on('-y', '--auto-download', 'Auto-select first link') do
18
+ options[:auto] = true
19
+ end
20
+
21
+ opts.on('-v', '--version', 'Print version and exit') do
22
+ puts "extratorrent_search v#{ExtratorrentSearch::VERSION}"
23
+ exit
24
+ end
25
+
26
+ opts.on_tail('-h', '--help', 'Show this message') do
27
+ puts opts
28
+ exit
29
+ end
30
+ end.parse!
31
+
32
+ # Join arguments to create the search term
33
+ options[:search] = optparse.join(' ')
34
+
35
+ # main program
36
+ begin
37
+ cli = HighLine.new
38
+ HighLine.colorize_strings # Monkey patch String for cli colors
39
+
40
+ # Valid search?
41
+ if options[:search].empty?
42
+ cli.say 'Please type a search'.red
43
+ exit
44
+ end
45
+
46
+ # Search subtitle
47
+ search = ExtratorrentSearch::Search.new(options[:search])
48
+
49
+ # Results found?
50
+ unless search.results_found?
51
+ cli.say 'No results found'.red
52
+ exit
53
+ end
54
+
55
+ # Choose
56
+ if options[:auto]
57
+ torrent = search.links.first
58
+ else
59
+ cli.say "Search results for #{options[:search]}:"
60
+ torrent = cli.choose(*search.links) do |menu|
61
+ menu.default = '1'
62
+ menu.select_by = :index
63
+ end
64
+ end
65
+
66
+ # Print magnet link for selected file
67
+ cli.say torrent.magnet
68
+ rescue Interrupt, EOFError
69
+ cli.say 'Interrupted!'.red
70
+ rescue SocketError
71
+ cli.say "Couldn't perform action. Are you online?".red
72
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'extratorrent_search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'extratorrent_search'
8
+ spec.version = ExtratorrentSearch::VERSION
9
+ spec.authors = ['David Marchante']
10
+ spec.email = ['davidmarchan@gmail.com']
11
+
12
+ spec.summary = 'Search Extratorrent for torrents and magnet links'
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = 'https://github.com/iovis9/extratorrent_search.git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
25
+ spec.add_runtime_dependency 'highline', '~> 1.7'
26
+ spec.add_runtime_dependency 'httparty', '~> 0.13'
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.13"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency 'guard-rspec', '~> 4.6'
32
+ spec.add_development_dependency 'factory_girl', '~> 4.5'
33
+ spec.add_development_dependency 'webmock', '~> 2.0'
34
+ spec.add_development_dependency 'pry', '~> 0.10'
35
+ spec.add_development_dependency 'pry-byebug', '~> 3.3'
36
+ end
@@ -0,0 +1,38 @@
1
+ require 'cgi'
2
+ require 'httparty'
3
+
4
+ module ExtratorrentSearch
5
+ ##
6
+ # Object that contains the info for a torrent file
7
+ class Link
8
+ attr_reader :filename, :size, :magnet_link, :seeders, :leechers
9
+
10
+ def initialize(filename: nil, size: nil, magnet_link: nil, seeders: nil, leechers: nil)
11
+ @filename = filename
12
+ @size = size
13
+ @magnet_link = magnet_link
14
+ @seeders = seeders
15
+ @leechers = leechers
16
+ end
17
+
18
+ def <=>(other)
19
+ @seeders <=> other.seeders
20
+ end
21
+
22
+ def to_s
23
+ "#{@filename} (#{@size}) - [#{@seeders.green}/#{@leechers.red}]"
24
+ end
25
+
26
+ def info_hash
27
+ @info_hash ||= extract_hash
28
+ end
29
+
30
+ private
31
+
32
+ def extract_hash
33
+ # Extract magnet properties to a Hash and then parse the sha1 info hash
34
+ raw_hash = magnet_link[/(xt.*?)&/, 1] # extract the xt property
35
+ raw_hash.split(':').last.downcase
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,57 @@
1
+ require 'erb'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'yaml'
5
+
6
+ module ExtratorrentSearch
7
+ ##
8
+ # Extract a list of results from your search
9
+ # ExtratorrentSearch::Search.new("Suits s05e16")
10
+ class Search
11
+ NUMBER_OF_LINKS = 5
12
+ BASE_URL = 'https://extratorrent.cc'.freeze
13
+
14
+ attr_accessor :url
15
+
16
+ def initialize(search)
17
+ # Order by seeds desc
18
+ @url = "#{BASE_URL}/search/?search=#{ERB::Util.url_encode(search)}&srt=seeds&order=desc"
19
+ end
20
+
21
+ def results_found?
22
+ @results_found ||= page.at('i:contains("No torrents")').nil?
23
+ rescue OpenURI::HTTPError
24
+ @results_found = false
25
+ end
26
+
27
+ def links
28
+ @links ||= generate_links
29
+ end
30
+
31
+ private
32
+
33
+ def page
34
+ @page ||= Nokogiri::HTML(open(@url))
35
+ end
36
+
37
+ def crawl_link(link)
38
+ Link.new(
39
+ filename: link.at('.tli > a').text,
40
+ size: link.css('td')[4].text,
41
+ magnet_link: link.at('a[title="Magnet link"]')['href'],
42
+ seeders: link.at('td.sy, td.sn').text,
43
+ leechers: link.at('td.ly, td.ln').text
44
+ )
45
+ end
46
+
47
+ def generate_links
48
+ links = []
49
+ return links unless results_found?
50
+
51
+ link_nodes = page.css('tr.tlr, tr.tlz')
52
+ link_nodes.each { |link| links << crawl_link(link) }
53
+
54
+ links.first(NUMBER_OF_LINKS)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module ExtratorrentSearch
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "extratorrent_search/link"
2
+ require "extratorrent_search/search"
3
+ require "extratorrent_search/version"
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extratorrent_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Marchante
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-05 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.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.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
+ - extratorrent_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/extratorrent_search
186
+ - extratorrent_search.gemspec
187
+ - lib/extratorrent_search.rb
188
+ - lib/extratorrent_search/link.rb
189
+ - lib/extratorrent_search/search.rb
190
+ - lib/extratorrent_search/version.rb
191
+ homepage: https://github.com/iovis9/extratorrent_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.8
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Search Extratorrent for torrents and magnet links
215
+ test_files: []