kmru 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36e59cd53af9cc8470afef2fdc1f987065304e0e
4
+ data.tar.gz: 27372b69c1244112bbcfde4ea770c61fe57b1644
5
+ SHA512:
6
+ metadata.gz: 4b6451dc0c57063de983472b7d4d70d029e53b7cb43687cc535b5004dbfec65bd0cdd49c5f0cab1f15d9aee9b467416e737a859adef5c086895784d6648b020b
7
+ data.tar.gz: 7b3a855a6579462fa07229ce137c331b88f8aa428b103f51dcaf8f70962a8825400161341039e624938d68fe657e476b6a6bacee16a93fe1316cc9581444455a
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.vendors/
11
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kmru.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # Kmru
2
+
3
+ This gem install a command `kmru`, it's not a gem you can use in your software.
4
+
5
+ The goal is simple: Fix note and votes in kodi database from IMDB
6
+
7
+ ## Installation
8
+
9
+ $ gem install kmru
10
+
11
+ Then first launch will create the configuration file in ~/.config/kmru.conf
12
+
13
+ ## Configuration
14
+
15
+ Edit **~/.config/kmru.conf**
16
+
17
+ * *host* = kodi host
18
+ * *port* = kodi api port
19
+ * *user* = kodi api user
20
+ * *pass* = kodi api pass
21
+ * *number* = default number of movie in cron / random / last mode
22
+
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ Usage: kmru [options]
28
+ -m, --mode MODE Choose which mode to use
29
+ - last : proceed most recent movies ( default)
30
+ - random : Take N random movies
31
+ - cron : like random but with minimal output
32
+ - all : procees the entire library
33
+ -n, --number NUM Check NUM movies
34
+ -v, --verbose Verbose output (show nochange movies too)
35
+ -h, --help Displays Help
36
+
37
+ Host options (you should use config file) :
38
+
39
+ -H, --host HOST Kodi instance address
40
+ -P, --port Kodi instance port
41
+ -u, --user USERNAME Kodi instance auth user
42
+ -p, --pass PASSWORD Kodi instance auth password
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Celedhrim/kmru.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'kmru'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -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,150 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require 'bundler/setup'
4
+ require 'kmru'
5
+ require 'rbconfig'
6
+ require 'optparse'
7
+ require 'ruby-progressbar'
8
+
9
+ # not design for windows
10
+ is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
11
+ if is_windows
12
+ puts 'Sorry not design for windows'
13
+ exit 1
14
+ end
15
+
16
+ # function to put messages
17
+ def myputs(msg)
18
+ if $options[:mode] == 'cron'
19
+ puts msg
20
+ else
21
+ $progressbar.log msg
22
+ end
23
+ end
24
+
25
+ CONFFILE = '~/.config/kmru.conf'
26
+ conffile = File.expand_path(CONFFILE)
27
+
28
+ # Load config file
29
+ $conf = Kmru.confread(conffile)
30
+
31
+ # Script command line arguments
32
+ $options = { mode: 'last',
33
+ number: $conf['number'],
34
+ verbose: false,
35
+ host: $conf['host'],
36
+ port: $conf['port'],
37
+ user: $conf['user'],
38
+ pass: $conf['pass'] }
39
+
40
+ parser = OptionParser.new do |opts|
41
+ opts.banner = 'Usage: kmru [options]'
42
+ opts.on('-m', '--mode MODE', ["last", "random", "cron", "all"], 'Choose which mode to use',
43
+ " - last : proceed most recent movies ( default)",
44
+ " - random : Take N random movies",
45
+ " - cron : like random but with minimal output",
46
+ " - all : procees the entire library") do |setting|
47
+ $options[:mode] = setting;
48
+ end
49
+
50
+ opts.on('-n', '--number NUM', Integer, 'Check NUM movies') do |setting|
51
+ $options[:number] = setting;
52
+ end
53
+
54
+ opts.on('-v', '--verbose', 'Verbose output (show nochange movies too)') do |setting|
55
+ $options[:verbose] = setting;
56
+ end
57
+
58
+ opts.on('-h', '--help', 'Displays Help') do
59
+ puts opts
60
+ exit
61
+ end
62
+
63
+ opts.separator ""
64
+ opts.separator "Host options (you should use config file) :"
65
+ opts.separator ""
66
+
67
+ opts.on('-H', '--host HOST', 'Kodi instance address') do |setting|
68
+ $options[:host] = setting;
69
+ end
70
+
71
+ opts.on('-P', '--port', 'Kodi instance port') do |setting|
72
+ $options[:port] = setting;
73
+ end
74
+
75
+ opts.on('-u', '--user USERNAME', 'Kodi instance auth user') do |setting|
76
+ $options[:user] = setting;
77
+ end
78
+
79
+ opts.on('-p', '--pass PASSWORD', 'Kodi instance auth password') do |setting|
80
+ $options[:pass] = setting;
81
+ end
82
+ end
83
+
84
+ parser.parse!
85
+
86
+ #Test connection to kodi api
87
+ unless Kmru.koditestconn
88
+ puts "Unable to connect KODI"
89
+ exit 1
90
+ end
91
+
92
+ movies = Kmru.getmovies
93
+
94
+ $progressbar = ProgressBar.create(:length => 80, :format => '%e |%b>%i| %P%% %t') unless $options[:mode] == "cron"
95
+ myputs('-'*80) unless $options[:cron]
96
+
97
+
98
+ x = 1
99
+ step = (x*100.0)/movies.count
100
+
101
+ movies.each do |m|
102
+ details = Kmru.getmoviedetails(m['movieid'])
103
+ if details['imdbnumber'].match(/(\d\d\d\d\d\d\d)/)
104
+ infos = Kmru.imdbdetails(details['imdbnumber'].match(/(\d\d\d\d\d\d\d)/))
105
+ if details['rating'].round(1) != infos.rating
106
+ myputs("| Progress: #{x}/#{movies.count}")
107
+ Kmru.setmoviedetails(m['movieid'],details['imdbnumber'],infos.rating,infos.votes)
108
+ myputs("| Update #{details['label']}")
109
+ myputs("| Rating: #{details['rating'].round(1)} => #{infos.rating}")
110
+ myputs("| Votes : #{details['votes']} => #{infos.votes}")
111
+ myputs('-'*80)
112
+ else
113
+ if $options[:verbose]
114
+ myputs("| Progress: #{x}/#{movies.count}")
115
+ myputs("| No change => #{details['label']}")
116
+ myputs('-'*80)
117
+ end
118
+ end
119
+ else
120
+ s = Imdb::Search.new("#{CGI::escape(details['label'])} #{details['year']}")
121
+ infos = s.movies
122
+ if infos.size > 0
123
+ begin
124
+ while infos.first.title.include? "(TV" or infos.first.title.include? "(Short)" or infos.first.title.include? "(in developement)" do
125
+ infos.shift
126
+ end
127
+ rescue
128
+ myputs("| error getting #{details['label']} infos on IMDB")
129
+ end
130
+ end
131
+
132
+ if infos.size > 0
133
+ myputs("| Found a match tt#{infos.first.id} => #{infos.first.title}")
134
+ Kmru.setmoviedetails(m['movieid'],"tt#{infos.first.id}",infos.first.rating,infos.first.votes)
135
+ myputs("| Update #{details['label']} with id tt#{infos.first.id}")
136
+ myputs("| Rating: #{infos.first.rating}")
137
+ myputs("| Votes : #{infos.first.votes}")
138
+ myputs('-'*80)
139
+ else
140
+ myputs("| No match found for #{details['label']}")
141
+ myputs("| skipping :(")
142
+ myputs('-'*80)
143
+ end
144
+ end
145
+ unless $options[:mode] == "cron" then
146
+ x == movies.count ? $progressbar.finish : $progressbar.progress += step
147
+ end
148
+ x = x+1
149
+
150
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kmru/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kmru"
8
+ spec.version = Kmru::VERSION
9
+ spec.authors = ["Celedhrim"]
10
+ spec.email = ["celed+gitlab@ielf.org"]
11
+
12
+ spec.summary = %q{Kodi movie rating update}
13
+ spec.description = %q{Let's update rating and vote for your movies using imdb.}
14
+ spec.homepage = "http://www.ielf.org"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "iniparse", ">= 1.4.1"
33
+ spec.add_dependency "imdb", "~> 0.8"
34
+ spec.add_dependency "rest-client"
35
+ spec.add_dependency "ruby-progressbar"
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.13"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
@@ -0,0 +1,8 @@
1
+ require "kmru/version"
2
+ require "kmru/config"
3
+ require "kmru/kodi"
4
+ require "kmru/imdb"
5
+
6
+ module Kmru
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,29 @@
1
+ require "iniparse"
2
+
3
+ module Kmru
4
+
5
+ # create the config
6
+ def self.confcreate(conffilepath)
7
+ docs = IniParse.gen do |doc|
8
+ doc.section("kmru") do |kmru|
9
+ kmru.option("host","127.0.0.1")
10
+ kmru.option("port","80")
11
+ kmru.option("user","kodi")
12
+ kmru.option("pass","kodi")
13
+ kmru.option("number","10")
14
+ end
15
+ end
16
+ docs.save(conffilepath)
17
+ puts "Conf file created : #{conffilepath}"
18
+ puts "Edit to fit your need then run again"
19
+ #Add exit
20
+ exit
21
+ end
22
+
23
+ # Read the config
24
+ def self.confread(conffilepath)
25
+ confcreate(conffilepath) unless File.exists?(conffilepath)
26
+ IniParse.parse( File.read(conffilepath) )['kmru']
27
+ end
28
+
29
+ end
@@ -0,0 +1,7 @@
1
+ require 'imdb'
2
+
3
+ module Kmru
4
+ def self.imdbdetails(id)
5
+ return Imdb::Movie.new(id)
6
+ end
7
+ end
@@ -0,0 +1,104 @@
1
+ require "rest-client"
2
+ require "json"
3
+ require "pp"
4
+
5
+ module Kmru
6
+
7
+ # Simple function to call the api
8
+ def self.kodireq(payload)
9
+ return RestClient.post "http://#{$options[:user]}:#{$options[:pass]}@#{$options[:host]}:#{$options[:port]}/jsonrpc", payload, {content_type: :json, accept: :json}
10
+ end
11
+
12
+ # Test kodi api connection
13
+ def self.koditestconn
14
+ payload = {
15
+ "id" => "kmru",
16
+ "jsonrpc" => "2.0",
17
+ "method" => "JSONRPC.Ping"
18
+ }.to_json
19
+
20
+ result = false
21
+ begin
22
+ response = self.kodireq(payload)
23
+ result = true if response.code == 200
24
+ rescue
25
+ result = false
26
+ end
27
+ return result
28
+ end
29
+
30
+ def self.getmovies
31
+ case $options[:mode]
32
+ when "last"
33
+ payload = {
34
+ "id" => "kmru",
35
+ "jsonrpc" => "2.0",
36
+ "method" => "VideoLibrary.GetRecentlyAddedMovies",
37
+ "params" => {
38
+ "limits" => {
39
+ "start" => 0,
40
+ "end" => $options[:number]
41
+ }
42
+ }
43
+ }.to_json
44
+
45
+ when "random", "cron"
46
+ payload = {
47
+ "id" => "kmru",
48
+ "jsonrpc" => "2.0",
49
+ "method" => "VideoLibrary.GetMovies",
50
+ "params" => {
51
+ "limits" => {
52
+ "start" => 0,
53
+ "end" => $options[:number]
54
+ },
55
+ "sort" => {
56
+ "method" => "random"
57
+ }
58
+ }
59
+ }.to_json
60
+
61
+ when "all"
62
+ payload = {
63
+ "id" => "kmru",
64
+ "jsonrpc" => "2.0",
65
+ "method" => "VideoLibrary.GetMovies"
66
+ }.to_json
67
+ else
68
+ puts "No suitable mode"
69
+ exit 1
70
+ end
71
+
72
+ return JSON.parse(self.kodireq(payload).body.force_encoding("UTF-8"))['result']['movies']
73
+ end
74
+
75
+ def self.getmoviedetails(id)
76
+ payload ={
77
+ "id" => "kmru",
78
+ "jsonrpc" => "2.0",
79
+ "method" => "VideoLibrary.GetMovieDetails",
80
+ "params" => {
81
+ "movieid" => id,
82
+ "properties" => ['rating', 'imdbnumber', 'votes', 'year']
83
+ }
84
+ }.to_json
85
+
86
+ return JSON.parse(self.kodireq(payload).body.force_encoding("UTF-8"))['result']['moviedetails']
87
+
88
+ end
89
+
90
+ def self.setmoviedetails(id,imdbid,rating,votes)
91
+ payload ={
92
+ "id" => "kmru",
93
+ "jsonrpc" => "2.0",
94
+ "method" => "VideoLibrary.SetMovieDetails",
95
+ "params" => {
96
+ "movieid" => id,
97
+ "imdbnumber" => imdbid,
98
+ "rating" => rating,
99
+ "votes" => "#{votes}"
100
+ }
101
+ }.to_json
102
+ return self.kodireq(payload)
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module Kmru
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kmru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Celedhrim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: iniparse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: imdb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-progressbar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.13'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description: Let's update rating and vote for your movies using imdb.
98
+ email:
99
+ - celed+gitlab@ielf.org
100
+ executables:
101
+ - kmru
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - exe/kmru
112
+ - kmru.gemspec
113
+ - lib/kmru.rb
114
+ - lib/kmru/config.rb
115
+ - lib/kmru/imdb.rb
116
+ - lib/kmru/kodi.rb
117
+ - lib/kmru/version.rb
118
+ homepage: http://www.ielf.org
119
+ licenses: []
120
+ metadata:
121
+ allowed_push_host: https://rubygems.org
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Kodi movie rating update
142
+ test_files: []