peerflixrb 0.5.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecd842be46cd8c610100394084b572f3a2b30e7a
4
- data.tar.gz: 9323654ec6e8fa53c1145f674484e3665486650b
3
+ metadata.gz: 7f72fe14a2b2bd54ce3302ac31e79d9a20f2dbc5
4
+ data.tar.gz: a7f4ed3e378c3b3ca7aaf88565b2e9ccb2eac3fc
5
5
  SHA512:
6
- metadata.gz: 6fc3279083411f97554e670daaf94c2b9e2a3891decc6a909ab47e70d8ecc351f99a76ac4a6000c1add86c33f774196a4ca9314bcf0d1040749ef3e506de0eb8
7
- data.tar.gz: 6d3e85cabcb11806c7e6f23d7034227a7fa61a176f81d00b1fa4a8e403fb2b0e7b3815c145f06c5a5970b4d7b1f07afadd8a2718fe521099ecb0a2959dedb3bb
6
+ metadata.gz: 7234667bc7be33ab9aab85b7fc961d4dadadbb546795ee0a8c60f8ece60649790201fc28230bcb6a3358d13be10c464b2211d869701d1c3020d19afa7b2a1d90
7
+ data.tar.gz: 40c64762f88130eb69a4746f4307f3293fd9aebd5889af6480ab932800711f59b4cd4f9f309812483491f2785789e34d5d1ffa7b0f48bca7a175179494a552eb
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Peerflixrb
4
4
 
5
- Wrapper for [peerflix](https://github.com/mafintosh/peerflix) with automatic search through [Kickass Torrents](kat.cr) and [Addic7ed](http://www.addic7ed.com/) (with [gem addic7ed](https://github.com/michaelbaudino/addic7ed-ruby)).
5
+ Wrapper for [peerflix](https://github.com/mafintosh/peerflix) with automatic search through [Kickass Torrents](kat.cr), [YifySubtitles](http://www.yifysubtitles.com/) and [Addic7ed](http://www.addic7ed.com/) (with [gem addic7ed](https://github.com/michaelbaudino/addic7ed-ruby)).
6
6
 
7
7
 
8
8
  ## Requirements
@@ -23,16 +23,18 @@ Install the gem:
23
23
  Pass a string with what you want to watch and it will search KAT with your query and present you with the first 5 results for you to choose. The file selected will then be sent to **peerflix**.
24
24
 
25
25
  $ peerflixrb Suits s05e12
26
+ $ peerflixrb The Godfather II
26
27
 
27
28
  If you prefer to autoplay the first matched result, use the ```-y``` flag:
28
29
 
29
- $ peerflixrb -y Archer s07e02
30
+ $ peerflixrb -y Archer s07e02 1080p
30
31
 
31
- You can play the video with subtitles with the ```-s``` option (Default: English). It will try and find the best match in [Addic7ed](http://www.addic7ed.com/).
32
+ You can play the video with subtitles with the ```-s``` option (Default: English). It will try and find the best match in [YifySubtitles](http://www.yifysubtitles.com/) if it's a movie and if [Addic7ed](http://www.addic7ed.com/) if it's a TV Show.
32
33
 
33
- $ peerflixrb -s Game Of Thrones S05E01 1080p
34
+ $ peerflixrb -s Birdman
35
+ $ peerflixrb -s The Wire s04e05
34
36
 
35
- Choose the language with ```-l LANGUAGE``` ([Available Languages](https://github.com/michaelbaudino/addic7ed-ruby/blob/master/lib/addic7ed/common.rb))
37
+ Choose the language with ```-l LANGUAGE``` ([Available Languages](https://github.com/michaelbaudino/addic7ed-ruby/blob/master/lib/addic7ed/common.rb)). Currently only for TV Shows (Choosing movie subtitles language will come soon!)
36
38
 
37
39
  $ peerflixrb -sl es-es Breaking Bad s05e03
38
40
 
data/bin/peerflixrb CHANGED
@@ -63,12 +63,11 @@ end
63
63
 
64
64
  # main program
65
65
  begin
66
- system 'clear'
67
- cli = Commands::cli
66
+ cli = Peerflixrb::Commands::cli
68
67
 
69
68
  # KAT Search
70
69
  cli.say "Searching KAT for #{options[:search].blue}".yellow
71
- kat_search = KAT.new(options[:search])
70
+ kat_search = Peerflixrb::KAT.new(options[:search])
72
71
 
73
72
  # Did it find results?
74
73
  if not kat_search.results_found
@@ -77,7 +76,7 @@ begin
77
76
  end
78
77
 
79
78
  # Choose link and subtitles
80
- link, sub_file = Commands.choose_video_and_subtitles(options, kat_search)
79
+ link, sub_file = Peerflixrb::Commands.choose_video_and_subtitles(kat_search, options)
81
80
 
82
81
  # Peerflix command build
83
82
  command = "peerflix '#{link.magnet}'"
data/lib/peerflixrb.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'peerflixrb/version'
2
2
  require 'peerflixrb/kat'
3
3
  require 'peerflixrb/link'
4
+ require 'peerflixrb/imdb'
5
+ require 'peerflixrb/yify'
@@ -1,72 +1,94 @@
1
1
  require 'addic7ed'
2
2
  require 'highline'
3
3
 
4
- module Commands
5
- class << self
6
- attr_accessor :cli
7
- end
4
+ module Peerflixrb
5
+ module Commands
6
+ class << self
7
+ attr_accessor :cli
8
+ end
8
9
 
9
- self.cli = HighLine.new
10
- HighLine.colorize_strings
10
+ self.cli = HighLine.new
11
+ HighLine.colorize_strings
11
12
 
12
- def self.select_link(kat_search)
13
- cli.choose(*kat_search.links) do |menu|
14
- menu.header = 'Choose which file'.yellow
15
- menu.default = '1'
16
- menu.select_by = :index
13
+ def self.select_link(kat_search)
14
+ cli.choose(*kat_search.links) do |menu|
15
+ menu.header = 'Choose which file'.yellow
16
+ menu.default = '1'
17
+ menu.select_by = :index
18
+ end
17
19
  end
18
- end
19
20
 
20
- def self.find_subtitles(video_file, language)
21
- episode = Addic7ed::Episode.new(video_file)
22
- return File.basename episode.download_best_subtitle!(language)
23
- rescue Addic7ed::EpisodeNotFound
24
- cli.say 'Episode not found on Addic7ed'.red
25
- rescue Addic7ed::ShowNotFound
26
- cli.say 'Show not found on Addic7ed'.red
27
- rescue Addic7ed::NoSubtitleFound
28
- cli.say 'No (acceptable) subtitle has been found on Addic7ed'.red
29
- rescue Addic7ed::InvalidFilename
30
- cli.say 'Addic7ed gem could not parse the filename correctly'.red
31
- end
32
-
33
- def self.choose_video_and_subtitles(options, kat_search)
34
- # Proactively declare them because they would be lost in the block scope
35
- link = nil
36
- sub_file = nil
21
+ def self.choose_video_and_subtitles(kat_search, options)
22
+ # Proactively declare them because they would be lost in the block scope
23
+ link = nil
24
+ sub_file = nil
37
25
 
38
- loop do
39
- # Choose file
40
- link = (options[:auto_select]) ? kat_search.links.first : select_link(kat_search)
26
+ loop do
27
+ # Choose file
28
+ link = (options[:auto_select]) ? kat_search.links.first : select_link(kat_search)
41
29
 
42
- # Subtitle search
43
- sub_file = if options[:find_subtitles]
44
- cli.say "Searching Addic7ed for subtitles for #{link.filename.blue}".yellow
45
- find_subtitles(link.filename, options[:language])
46
- elsif options[:subtitles]
47
- options[:subtitles]
48
- end
30
+ # Subtitle search
31
+ sub_file = if options[:find_subtitles]
32
+ cli.say "Searching subtitles for #{link.filename.blue}".yellow
33
+ find_subtitles(link.filename, options)
34
+ elsif options[:subtitles]
35
+ options[:subtitles]
36
+ end
49
37
 
50
- # Was there a problem with the subtitle?
51
- if options[:find_subtitles] && sub_file.nil?
52
- continue = cli.agree "Do you want to continue? #{'[y/n]'.yellow}".green
38
+ # Was there a problem with the subtitle?
39
+ if options[:find_subtitles] && sub_file.nil?
40
+ continue = cli.agree "Do you want to continue? #{'[y/n]'.yellow}".green
53
41
 
54
- unless continue
55
- # If :auto_select, exit program
56
- # If video chosen, choose video again
57
- if options[:auto_select]
58
- exit
59
- else
60
- system 'clear'
61
- next
42
+ unless continue
43
+ # If :auto_select, exit program
44
+ # If video chosen, choose video again
45
+ if options[:auto_select]
46
+ exit
47
+ else
48
+ system 'clear'
49
+ next
50
+ end
62
51
  end
63
52
  end
53
+
54
+ # If the loop got here then it found subtitles
55
+ break
64
56
  end
65
57
 
66
- # If the loop got here then it found subtitles
67
- break
58
+ [link, sub_file]
68
59
  end
69
60
 
70
- [link, sub_file]
61
+ # Helper methods (private)
62
+ def self.find_subtitles(video_file, options)
63
+ # Imdb search based on initial command input
64
+ movie = Imdb.find(options[:search])
65
+
66
+ if movie
67
+ # TODO Choose language
68
+ find_movie_subtitles(movie, 'english')
69
+ else
70
+ find_tv_subtitles(video_file, options[:language])
71
+ end
72
+ end
73
+
74
+ def self.find_movie_subtitles(movie, language)
75
+ sub_file = YifySubtitles.download(movie.imdb_id, language)
76
+ return sub_file unless sub_file.nil?
77
+ cli.say "Could not find subtitles for #{movie}".red
78
+ end
79
+
80
+ def self.find_tv_subtitles(video_file, language)
81
+ # TV Show search based on video filename
82
+ episode = Addic7ed::Episode.new(video_file)
83
+ return File.basename episode.download_best_subtitle!(language)
84
+ rescue Addic7ed::EpisodeNotFound
85
+ cli.say 'Episode not found on Addic7ed'.red
86
+ rescue Addic7ed::ShowNotFound
87
+ cli.say 'Show not found on Addic7ed'.red
88
+ rescue Addic7ed::NoSubtitleFound
89
+ cli.say 'No (acceptable) subtitle has been found on Addic7ed'.red
90
+ rescue Addic7ed::InvalidFilename
91
+ cli.say 'Addic7ed gem could not parse the filename correctly'.red
92
+ end
71
93
  end
72
94
  end
@@ -0,0 +1,29 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Peerflixrb
5
+ module Imdb
6
+ def self.find(title)
7
+ params = { 'json' => '1', 'nr' => 1, 'tt' => 'on', 'q' => title }
8
+ query = HTTParty.get('http://www.imdb.com/xml/find', query: params)
9
+ results = JSON.load(query)['title_popular']
10
+
11
+ # Return the most popular for that search
12
+ Movie.new(results.first) if results
13
+ end
14
+
15
+ class Movie
16
+ attr_accessor :imdb_id, :title, :year
17
+
18
+ def initialize(params)
19
+ @imdb_id = params['id']
20
+ @title = params['title']
21
+ @year = params['description'].match(/\A\d+/).to_s
22
+ end
23
+
24
+ def to_s
25
+ "#{title} (#{year})"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,39 +2,43 @@ require 'erb'
2
2
  require 'nokogiri'
3
3
  require 'yaml'
4
4
 
5
- ##
6
- # Extract a list of results from your search
7
- # KAT.new("Suits s05e16 1080p")
8
- class KAT
9
- NUMBER_OF_LINKS = 5
5
+ module Peerflixrb
6
+ ##
7
+ # Extract a list of results from your search
8
+ # KAT.new("Suits s05e16 1080p")
9
+ class KAT
10
+ NUMBER_OF_LINKS = 5
10
11
 
11
- attr_accessor :url
12
+ attr_accessor :url
12
13
 
13
- def initialize(search)
14
- @url = "https://kat.cr/usearch/#{ERB::Util.url_encode(search)}/"
15
- end
14
+ def initialize(search)
15
+ @url = "https://kat.cr/usearch/#{ERB::Util.url_encode(search)}/"
16
+ end
16
17
 
17
- def page
18
- @page ||= Nokogiri::HTML(open(@url))
19
- end
18
+ def page
19
+ @page ||= Nokogiri::HTML(open(@url))
20
+ end
20
21
 
21
- def results_found
22
- @results_found ||= page.at('p:contains("did not match any documents")').nil?
23
- end
22
+ def results_found
23
+ @results_found ||= page.at('p:contains("did not match any documents")').nil?
24
+ rescue OpenURI::HTTPError
25
+ @results_found = false
26
+ end
24
27
 
25
- def links
26
- @links ||= generate_links
27
- end
28
+ def links
29
+ @links ||= generate_links
30
+ end
28
31
 
29
- private
32
+ private
30
33
 
31
- def generate_links
32
- links = []
33
- crawled_links = page.css('.iaconbox > div')
34
- crawled_links[0..NUMBER_OF_LINKS - 1].each do |link|
35
- links << Link.new(YAML.load(link['data-sc-params']))
36
- end
34
+ def generate_links
35
+ links = []
36
+ crawled_links = page.css('.iaconbox > div')
37
+ crawled_links[0..NUMBER_OF_LINKS - 1].each do |link|
38
+ links << Link.new(YAML.load(link['data-sc-params']))
39
+ end
37
40
 
38
- return links
41
+ return links
42
+ end
39
43
  end
40
44
  end
@@ -1,34 +1,36 @@
1
1
  require 'cgi'
2
2
  require 'open-uri'
3
3
 
4
- ##
5
- # Object that contains the info for a torrent file
6
- class Link
7
- def initialize(params)
8
- @params = params
9
- end
4
+ module Peerflixrb
5
+ ##
6
+ # Object that contains the info for a torrent file
7
+ class Link
8
+ def initialize(params)
9
+ @params = params
10
+ end
10
11
 
11
- def to_s
12
- filename
13
- end
12
+ def to_s
13
+ filename
14
+ end
14
15
 
15
- def filename
16
- @filename ||= "#{CGI.unescape(@params['name'])}.#{@params['extension']}"
17
- end
16
+ def filename
17
+ @filename ||= "#{CGI.unescape(@params['name'])}.#{@params['extension']}"
18
+ end
18
19
 
19
- def magnet
20
- @magnet ||= @params['magnet']
21
- end
20
+ def magnet
21
+ @magnet ||= @params['magnet']
22
+ end
22
23
 
23
- def info_hash
24
- @info_hash ||= extract_hash
25
- end
24
+ def info_hash
25
+ @info_hash ||= extract_hash
26
+ end
26
27
 
27
- private
28
+ private
28
29
 
29
- def extract_hash
30
- # Extract magnet properties to a Hash
31
- magnet_params = CGI.parse(URI.parse(magnet).query)
32
- magnet_params['xt'].first.match(/[0-9A-F]+/).to_s.downcase
30
+ def extract_hash
31
+ # Extract magnet properties to a Hash
32
+ magnet_params = CGI.parse(URI.parse(magnet).query)
33
+ magnet_params['xt'].first.match(/[0-9A-F]+/).to_s.downcase
34
+ end
33
35
  end
34
36
  end
@@ -1,3 +1,3 @@
1
1
  module Peerflixrb
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'httparty'
2
+ require 'zip'
3
+
4
+ module Peerflixrb
5
+ module YifySubtitles
6
+ API_URL = 'http://api.yifysubtitles.com/subs/'.freeze
7
+ BASE_URL = 'http://www.yifysubtitles.com'.freeze
8
+
9
+ def self.download(imdb_id, language = 'english')
10
+ url = get_subtitles_url(imdb_id, language)
11
+ return if url.nil?
12
+
13
+ zip = download_subtitles(url)
14
+ extract_zip(zip)
15
+ end
16
+
17
+ # Helper methods (private)
18
+ def self.get_subtitles_url(imdb_id, language)
19
+ results = HTTParty.get(API_URL + imdb_id)
20
+
21
+ if results['success'] && results['subtitles'] > 0
22
+ BASE_URL + results['subs'][imdb_id][language][0]['url']
23
+ end
24
+ end
25
+
26
+ def self.download_subtitles(url)
27
+ HTTParty.get(url).body
28
+ end
29
+
30
+ def self.extract_zip(zip_body)
31
+ sub_file = nil
32
+
33
+ Zip::InputStream.open(StringIO.new(zip_body)) do |io|
34
+ while (entry = io.get_next_entry)
35
+ # Don't extract if not a subtitle file
36
+ next unless entry.name =~ /\.(srt|sub|ass)\z/
37
+
38
+ sub_file = entry.name
39
+ open(sub_file, 'w') do |f|
40
+ f << io.read
41
+ end
42
+ end
43
+ end
44
+
45
+ sub_file
46
+ end
47
+ end
48
+ end
data/peerflixrb.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_runtime_dependency 'nokogiri', '~> 1.6'
23
23
  spec.add_runtime_dependency 'addic7ed', '~> 2.0'
24
24
  spec.add_runtime_dependency 'highline', '~> 1.7'
25
+ spec.add_runtime_dependency 'httparty', '~> 0.13'
26
+ spec.add_runtime_dependency 'rubyzip', '~> 1.2'
25
27
 
26
28
  spec.add_development_dependency 'bundler', '~> 1.11'
27
29
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peerflixrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Marchante
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.13'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubyzip
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -183,9 +211,11 @@ files:
183
211
  - bin/peerflixrb
184
212
  - lib/peerflixrb.rb
185
213
  - lib/peerflixrb/commands.rb
214
+ - lib/peerflixrb/imdb.rb
186
215
  - lib/peerflixrb/kat.rb
187
216
  - lib/peerflixrb/link.rb
188
217
  - lib/peerflixrb/version.rb
218
+ - lib/peerflixrb/yify.rb
189
219
  - peerflixrb.gemspec
190
220
  homepage: https://github.com/iovis9/peerflixrb
191
221
  licenses: