plex-autodelete 0.0.4 → 0.0.5
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 +4 -4
- data/Gemfile +1 -0
- data/bin/plex-autodelete +1 -1
- data/lib/plex/autodelete/cli.rb +62 -47
- data/lib/plex/autodelete/version.rb +1 -1
- data/plex-autodelete.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a943700c4631bf182a9a65136908bede7bd1cb75
|
4
|
+
data.tar.gz: df9d8ff1f18a4a35b45f0a1d29bab9fe8f6e46ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eeebd1a1e620da3a9bd6c94ad5dc7972c14a54e0f1c0c17687f77e62721e46d10ddc48244ebf3761591fd5a91f80808cb417fecb00c0495bb44ef484819d154
|
7
|
+
data.tar.gz: 59c6fc16690ac1734da8303366264346999518c9e298b780e1d6027d3270ae46064648a62a6497b99a11218203b8d698b7169e01b665a18b68fec5ba2bd91e43
|
data/Gemfile
CHANGED
data/bin/plex-autodelete
CHANGED
data/lib/plex/autodelete/cli.rb
CHANGED
@@ -1,37 +1,82 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'yaml'
|
3
|
+
require 'nori'
|
4
|
+
require 'colorize'
|
2
5
|
require 'plex/autodelete/cleanup'
|
3
6
|
|
4
7
|
module Plex
|
5
8
|
module Autodelete
|
9
|
+
|
6
10
|
class CLI < Thor
|
7
11
|
|
12
|
+
@@config_file = ENV['HOME'] + '/.plex-autodelete.yml'
|
13
|
+
@@config = nil
|
8
14
|
@@myplex = {
|
9
15
|
host: 'plex.tv',
|
10
|
-
port: 443
|
16
|
+
port: 443,
|
17
|
+
path: '/users/sign_in.xml',
|
18
|
+
client: "plex-autodelete #{Plex::Autodelete::VERSION}",
|
11
19
|
}
|
12
20
|
|
13
21
|
desc "cleanup", "Remove all watched episodes from Plex"
|
14
|
-
option :host, default: '127.0.0.1', desc: 'The hostname/ip address of the Plex Server'
|
15
|
-
option :port, default: 32400, desc: 'The port of the Plex Server'
|
16
|
-
option :token, required: true, desc: 'The token of the plex server, generate with "plex-autodelete token"'
|
17
|
-
option :skip, type: :array, desc: 'An array of shows to skip, these will not be deleted. Use quotes if show contains spaces/special characters.'
|
18
|
-
option :delete, type: :boolean, default: true, desc: 'Skip actual deletion of files, useful for testing settings'
|
19
|
-
option :section, type: :numeric, default: 1, desc: 'Which section are your TV shows in?'
|
20
22
|
def cleanup
|
21
|
-
|
23
|
+
unless File.exists? @@config_file
|
24
|
+
puts "Config file does not exist, please run 'plex-autocomplete install' to generate it"
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
puts "#{config.to_yaml}\n"
|
29
|
+
|
22
30
|
Plex::Autodelete::Cleanup.configure config
|
23
31
|
Plex::Autodelete::Cleanup.cleanup
|
24
32
|
end
|
25
33
|
|
26
|
-
desc '
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
desc 'install', "Generate the config file to use with 'plex-autodelete cleanup'"
|
35
|
+
def install
|
36
|
+
|
37
|
+
puts "Generating token using https://#{@@myplex[:host]}. Username/Password will not be stored".bold
|
38
|
+
username = ask("Username")
|
39
|
+
password = ask("Password", echo: false)
|
40
|
+
token = get_token(username, password)
|
41
|
+
|
42
|
+
puts "\n"
|
43
|
+
puts "Token generated: #{token}".green
|
44
|
+
|
45
|
+
puts "\n"
|
46
|
+
puts "Configure Plex Autodelete".bold
|
47
|
+
|
48
|
+
@@config = {
|
49
|
+
host: ask("Plex Server address", default: '127.0.0.1') ,
|
50
|
+
port: ask("Plex Server port:", default: 32400),
|
51
|
+
token: token,
|
52
|
+
skip: ask("Shows to skip [comma seperated list]").split(','),
|
53
|
+
delete: true,
|
54
|
+
section: 1
|
55
|
+
}
|
56
|
+
|
57
|
+
write_config
|
58
|
+
puts "Config file has been written to #{@@config_file}".green
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def write_config
|
65
|
+
File.open(@@config_file, "w") { |file|
|
66
|
+
YAML.dump(config, file)
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def config
|
71
|
+
@@config ||= YAML::load_file(@@config_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_token(username, password)
|
30
75
|
http = Net::HTTP.new(@@myplex[:host], @@myplex[:port])
|
31
76
|
http.use_ssl = true
|
32
77
|
http.start do |http|
|
33
|
-
request = Net::HTTP::Post.new(
|
34
|
-
request.basic_auth
|
78
|
+
request = Net::HTTP::Post.new(@@myplex[:path], initheader = {'X-Plex-Client-Identifier' => @@myplex[:client]})
|
79
|
+
request.basic_auth username, password
|
35
80
|
response, data = http.request(request)
|
36
81
|
|
37
82
|
parser = Nori.new
|
@@ -39,44 +84,14 @@ module Plex
|
|
39
84
|
|
40
85
|
if hash.has_key?('errors')
|
41
86
|
hash['errors'].each do |error|
|
42
|
-
puts error.to_s
|
87
|
+
puts error.to_s.red
|
43
88
|
end
|
89
|
+
exit
|
44
90
|
else
|
45
|
-
|
46
|
-
puts "Authentication Token: #{authentication_token}"
|
91
|
+
hash['user']['authentication_token'].to_s
|
47
92
|
end
|
48
93
|
end
|
49
94
|
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def output_config
|
53
|
-
output = []
|
54
|
-
output << "Host: #{config[:host]}"
|
55
|
-
output << "Port: #{config[:port]}"
|
56
|
-
output << "Token: #{config[:token]}"
|
57
|
-
output << "Section: #{config[:section]}"
|
58
|
-
output << "Skip Shows: #{config[:skip] || 'N/A'}"
|
59
|
-
output << "Skip Delete: #{delete_text}"
|
60
|
-
output << "--------------------"
|
61
|
-
output << ""
|
62
|
-
output = output.join("\n")
|
63
|
-
puts output
|
64
|
-
end
|
65
|
-
|
66
|
-
def config
|
67
|
-
{
|
68
|
-
host: options[:host],
|
69
|
-
port: options[:port],
|
70
|
-
token: options[:token],
|
71
|
-
section: options[:section],
|
72
|
-
skip: options[:skip],
|
73
|
-
delete: options[:delete],
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
def delete_text
|
78
|
-
options[:delete] ? 'true' : 'false'
|
79
|
-
end
|
80
95
|
end
|
81
96
|
end
|
82
97
|
end
|
data/plex-autodelete.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_runtime_dependency 'plex-ruby', '~> 1.5', '>= 1.5.1'
|
24
24
|
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
25
|
+
spec.add_runtime_dependency 'colorize', '~> 0.7.3'
|
25
26
|
spec.add_runtime_dependency 'nori', '~> 2.4', '>= 2.4.0'
|
26
27
|
spec.add_runtime_dependency 'mini_portile', '~> 0.6.1'
|
27
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plex-autodelete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Robertson
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 0.19.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: colorize
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.7.3
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.7.3
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: nori
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|