cinema 1.1.0 → 2.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: ba917e49edd5b86cf329e6eb52852e37e02bd4c2
4
- data.tar.gz: aafb7012609bdb0c9f2b076fa4020710f82f85d5
3
+ metadata.gz: 4ce1d18103a051c4c254f219fb75481a5428a32d
4
+ data.tar.gz: cd3f665f2c78c8cdd4e9e470542c03b78e441b0f
5
5
  SHA512:
6
- metadata.gz: 6c2c5bda97f19fe58baa324463dc972a7925c0c69a38e372dc109871fc8f1fc6d8ad7063a832a4216897bf0cb8261b3ae5d83861c50f408fb5117ff9d4938fa1
7
- data.tar.gz: 3c7f8c122f2e2dcf1d6a6cdccfe068b56f0441d69e6cb612d2731a3500c617da1f4017e731f46e64cec38a54a20d9daf1b4970eca4e3d9240d5f5a6d90b5ab04
6
+ metadata.gz: edec0ccc0659b10ba8c38dd4b59168f3ba4b979b7c92d393e86752d6b1ad7e3e3a3e9c374113701d41d81abd42eb5e19764027669dce01189f84d056aa59c55e
7
+ data.tar.gz: 9173da777e32df964b8d196dca177ea435b9574a111c38895eed387fea8f23be70b8d1f8722336c4e6a61f0461df122ca22dd758bc604422e5c20a085e448e65
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_dependency "traktr", ">=0.7.0"
24
- spec.add_dependency "yify", ">=0.0.1"
23
+ spec.add_dependency "rest-client"
24
+ spec.add_dependency "launchy"
25
25
  end
@@ -1,20 +1,34 @@
1
- require "cinema/version"
1
+ require 'cinema/version'
2
+ require 'rest_client'
3
+ require 'launchy'
2
4
  require 'tempfile'
3
- require 'traktr'
4
5
  require 'yify'
5
6
  require 'yaml'
7
+ require 'pry'
6
8
 
7
9
  module Cinema
8
10
  class << self
11
+ APP_ID="69f18bbaff859f035d934888f846b7ae3653e223a2b0f15629bcc9b836d3996b"
12
+ APP_SECRET="077edf5024fca4102295263e802631f52f8cebd404f612194279f059bc5d9b8d"
13
+
9
14
  def ask_and_play
10
- imdb_id = select("Select movie", watchlist, ->(x){ x["title"] })["imdb_id"]
11
- torrent = select("Select quality", torrents(imdb_id), ->(x){ x.quality })["torrent_url"]
12
- downloader = select("Select downloader", ["peerflix","qbittorrent","wget","echo"], ->(x){x})
13
- if downloader == 'peerflix'
15
+ imdb_id = select("Select movie",
16
+ watchlist.sort_by{|x| x["released"]},
17
+ ->(x){ x["movie"]["title"] })["movie"]["ids"]["imdb"]
18
+ unless imdb_id
19
+ print "imdb id: "
20
+ imdb_id = gets.chomp
21
+ end
22
+ torrent = select("Select quality", torrents(imdb_id), ->(x){ x["quality"] })["url"]
23
+ downloader = select("Select downloader", ["peerflix", "qbittorrent", "wget", "echo"], ->(x){x})
24
+ case downloader
25
+ when 'peerflix'
14
26
  player = select("Select player", ["mplayer","vlc"], ->(x){x})
15
27
  system downloader, torrent, "--#{player}"
16
- else
28
+ when 'qbittorrent'
17
29
  system "sh", "-c", "#{downloader} #{torrent} &"
30
+ else
31
+ system downloader, torrent
18
32
  end
19
33
  end
20
34
 
@@ -25,24 +39,24 @@ module Cinema
25
39
  '--menu', '', '0', '0', '0',
26
40
  *menu_items.flatten
27
41
  unless success
28
- puts "\nCancelled"
29
- exit 0
42
+ return nil
30
43
  end
31
- end.to_i
32
- items[index]
44
+ end
45
+ items[index.to_i] if index
33
46
  end
34
47
 
35
48
  def watchlist
36
49
  with_unreliable_api do
37
50
  puts "Requesting watchlist..."
38
- trakt.user.watchlist.movies.sort_by{|x| x["title"]}
51
+ trakt_request(:get, "calendars/my/movies/1900-01-01/1000000")
39
52
  end
40
53
  end
41
54
 
42
55
  def torrents(imdb_id)
43
56
  with_unreliable_api do
44
57
  puts "Searching torrents..."
45
- yify.list_imdb(imdb_id: imdb_id).result
58
+ response = RestClient.get("http://yts.to/api/v2/list_movies.json?query_term=#{imdb_id}").body
59
+ JSON.parse(response)["data"]["movies"].first["torrents"]
46
60
  end
47
61
  end
48
62
 
@@ -50,17 +64,79 @@ module Cinema
50
64
  @yify ||= Yify::Client.new
51
65
  end
52
66
 
53
- def trakt
54
- @trakt ||= Traktr::Client.new config['api_key'], config['username'], config['password']
67
+ def redirect_uri
68
+ 'urn:ietf:wg:oauth:2.0:oob'
69
+ end
70
+
71
+ def pin_to_token(pin)
72
+ response =
73
+ RestClient.post('https://trakt.tv/oauth/token', {
74
+ code: pin,
75
+ client_id: APP_ID,
76
+ client_secret: APP_SECRET,
77
+ redirect_uri: redirect_uri,
78
+ grant_type: 'authorization_code'
79
+ }).body
80
+ JSON.parse(response).values_at('access_token', 'refresh_token')
81
+ end
82
+
83
+ def initial_authorize
84
+ loop do
85
+ capture_stderr do
86
+ Launchy.open("https://trakt.tv/oauth/authorize?client_id=#{APP_ID}&redirect_uri=#{redirect_uri}&response_type=code")
87
+ end
88
+ print "Please authorize the app and enter PIN: "
89
+ pin = gets.chomp
90
+ if pin.size == 8
91
+ return pin_to_token(pin)
92
+ end
93
+ end
94
+ end
95
+
96
+ def write_config(access_token, refresh_token)
97
+ File.write config_file, {access_token: access_token, refresh_token: refresh_token}.to_yaml
98
+ end
99
+
100
+ def initial_authorize_and_save_config
101
+ write_config(*initial_authorize)
102
+ end
103
+
104
+ def refresh_access_token
105
+ response =
106
+ RestClient.post('https://trakt.tv/oauth/token', {
107
+ refresh_token: config[:refresh_token],
108
+ client_id: APP_ID,
109
+ client_secret: APP_SECRET,
110
+ redirect_uri: redirect_uri,
111
+ grant_type: 'refresh_token'
112
+ }).body
113
+ write_config *JSON.parse(response).values_at('access_token', 'refresh_token')
114
+ end
115
+
116
+ def trakt_request(method, path, payload=nil)
117
+ params = {
118
+ method: method,
119
+ url: "https://api-v2launch.trakt.tv/#{path}",
120
+ payload: payload,
121
+ headers: {
122
+ "Content-Type" => "application/json",
123
+ "Authorization" => "Bearer #{config[:access_token]}",
124
+ "trakt-api-version" => "2",
125
+ "trakt-api-key" => APP_ID,
126
+ }
127
+ }
128
+ JSON.parse RestClient::Request.execute(params).body
129
+ rescue RestClient::Unauthorized
130
+ puts 'Unauthorized. Trying to refresh token.'
131
+ refresh_access_token
132
+ retry
55
133
  end
56
134
 
57
135
  def config
58
- @config ||= if File.exist? config_file
59
- YAML.load_file config_file
60
- else
61
- STDERR.puts "#{config_file} not found"
62
- exit 255
63
- end
136
+ unless File.exist? config_file
137
+ initial_authorize_and_save_config
138
+ end
139
+ YAML.load_file config_file
64
140
  end
65
141
 
66
142
  def config_file
@@ -1,3 +1,3 @@
1
1
  module Cinema
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ales Guzik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: traktr
42
+ name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.7.0
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.7.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: yify
56
+ name: launchy
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.1
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.1
68
+ version: '0'
69
69
  description: ''
70
70
  email:
71
71
  - me@aguzik.net
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.5
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Select movie from trakt.tv watchlist and stream it from torrents
110
110
  test_files: []
111
- has_rdoc: