plex-autodelete 0.0.2 → 0.0.3
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/.gitignore +29 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +2 -0
- data/bin/plex-autodelete +8 -89
- data/lib/plex/autodelete/cleanup.rb +66 -0
- data/lib/plex/autodelete/cli.rb +84 -0
- data/lib/plex/autodelete/version.rb +5 -0
- data/plex-autodelete.gemspec +27 -0
- metadata +41 -5
- data/lib/plex-autodelete.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01ab31f6656a8df36c69b294924acb8e7ce245f5
|
4
|
+
data.tar.gz: 8a34eaaa2c6eec7df8914112ff6d301a2e471a8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ee939702ceef5c26665421d2c842763bde318512902b454ed001cd65a31c8a2c0702fa2578f42f9a7cfe8b1fa02769f4bacfc705ac254a51daa9fa70ebccbff
|
7
|
+
data.tar.gz: 5e0544047db6a746272884d984d374f3e0d6ebe97f2b619a028d99fc5d3a614626d64b55f05dfbb186448001cc6e05c92ed0252697d3e2781095bfa5e3cdf7b9
|
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
Gemfile.lock
|
28
|
+
.ruby-version
|
29
|
+
.ruby-gemset
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Scott Robertson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/plex-autodelete
CHANGED
@@ -1,91 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
class PlexAutoDelete < Thor
|
11
|
-
|
12
|
-
@@myplex = {
|
13
|
-
host: 'plex.tv',
|
14
|
-
port: 443
|
15
|
-
}
|
16
|
-
|
17
|
-
desc "cleanup", "Remove all watched episodes from Plex"
|
18
|
-
option :host, default: '127.0.0.1', desc: 'The hostname/ip address of the Plex Server'
|
19
|
-
option :port, default: 32400, desc: 'The port of the Plex Server'
|
20
|
-
option :token, required: true, desc: 'The token of the plex server, generate with "plex-autodelete token"'
|
21
|
-
option :skip, type: :array, desc: 'An array of shows to skip, these will not be deleted. Use quotes if show contains spaces/special characters.'
|
22
|
-
option :delete, type: :boolean, default: true, desc: 'Skip actual deletion of files, useful for testing settings'
|
23
|
-
option :section, type: :numeric, default: 1, desc: 'Which section are your TV shows in?'
|
24
|
-
def cleanup
|
25
|
-
output_config
|
26
|
-
Autodelete.configure config
|
27
|
-
Autodelete.cleanup
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'token', 'Generate the auth token needed to use "plex-autodelete cleanup"'
|
31
|
-
option :username, required: true, desc: 'Your my.plex.tv username (this will not be stored)'
|
32
|
-
option :password, required: true, desc: 'Your my.plex.tv password (this will not be stored)'
|
33
|
-
def token
|
34
|
-
|
35
|
-
http = Net::HTTP.new(@@myplex[:host], @@myplex[:port])
|
36
|
-
http.use_ssl = true
|
37
|
-
|
38
|
-
http.start do |http|
|
39
|
-
|
40
|
-
request = Net::HTTP::Post.new('/users/sign_in.xml', initheader = {'X-Plex-Client-Identifier' =>'Plex Autodelete'})
|
41
|
-
request.basic_auth options[:username], options[:password]
|
42
|
-
response, data = http.request(request)
|
43
|
-
|
44
|
-
parser = Nori.new
|
45
|
-
hash = parser.parse(response.response.body)
|
46
|
-
|
47
|
-
if hash.has_key?('errors')
|
48
|
-
hash['errors'].each do |error|
|
49
|
-
puts error.to_s
|
50
|
-
end
|
51
|
-
else
|
52
|
-
authentication_token = hash['user']['authentication_token'].to_s
|
53
|
-
puts "Authentication Token: #{authentication_token}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def output_config
|
60
|
-
output = []
|
61
|
-
output << "Host: #{config[:host]}"
|
62
|
-
output << "Port: #{config[:port]}"
|
63
|
-
output << "Token: #{config[:token]}"
|
64
|
-
output << "Section: #{config[:section]}"
|
65
|
-
output << "Skip Shows: #{config[:skip] || 'N/A'}"
|
66
|
-
output << "Skip Delete: #{delete_text}"
|
67
|
-
output << "--------------------"
|
68
|
-
output << ""
|
69
|
-
output = output.join("\n")
|
70
|
-
puts output
|
71
|
-
end
|
72
|
-
|
73
|
-
def config
|
74
|
-
{
|
75
|
-
host: options[:host],
|
76
|
-
port: options[:port],
|
77
|
-
token: options[:token],
|
78
|
-
section: options[:section],
|
79
|
-
skip: options[:skip],
|
80
|
-
delete: options[:delete],
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def delete_text
|
85
|
-
options[:delete] ? 'true' : 'false'
|
86
|
-
end
|
87
|
-
|
2
|
+
require 'pathname'
|
3
|
+
$:.unshift File.expand_path(File.dirname(Pathname.new(__FILE__).realpath) + '/../lib')
|
4
|
+
require 'plex/autodelete/cli'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Plex::Autodelete::CLI.start(ARGV)
|
8
|
+
rescue
|
9
|
+
puts "Error: #{$!.message} \n\n"
|
88
10
|
end
|
89
|
-
|
90
|
-
PlexAutoDelete.start(ARGV)
|
91
|
-
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "plex/autodelete/version"
|
2
|
+
require "plex-ruby"
|
3
|
+
|
4
|
+
module Plex
|
5
|
+
module Autodelete
|
6
|
+
class Cleanup
|
7
|
+
|
8
|
+
@config = {
|
9
|
+
host: '127.0.0.1',
|
10
|
+
port: 32400,
|
11
|
+
token: nil,
|
12
|
+
skip: [],
|
13
|
+
delete: true,
|
14
|
+
section: 1,
|
15
|
+
}
|
16
|
+
|
17
|
+
@config_keys = @config.keys
|
18
|
+
|
19
|
+
def self.configure(opts = {})
|
20
|
+
opts.each {|key, value| @config[key.to_sym] = value if @config_keys.include? key.to_sym}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.required_params!
|
24
|
+
[:host, :port, :token, :section].each do |param|
|
25
|
+
if @config[param].nil?
|
26
|
+
raise Exception
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.cleanup
|
32
|
+
|
33
|
+
self.required_params!
|
34
|
+
|
35
|
+
Plex.configure do |config|
|
36
|
+
config.auth_token = @config[:token]
|
37
|
+
end
|
38
|
+
|
39
|
+
server = Plex::Server.new(@config[:host], @config[:port])
|
40
|
+
|
41
|
+
server.library.section(@config[:section]).all.each do |show|
|
42
|
+
next if @config[:skip].include? show.title
|
43
|
+
|
44
|
+
show.seasons.each do |season|
|
45
|
+
season.episodes.each do |episode|
|
46
|
+
if episode.respond_to?(:view_count)
|
47
|
+
puts " - #{show.title} - #{season.title} - #{episode.title}"
|
48
|
+
episode.medias.each do |media|
|
49
|
+
media.parts.each do |part|
|
50
|
+
if File.exist?(part.file) and @config[:delete]
|
51
|
+
File.delete(part.file)
|
52
|
+
puts " - File Removed: #{part.file}"
|
53
|
+
else
|
54
|
+
puts " - File Not Removed: #{part.file}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
puts nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'plex/autodelete/cleanup'
|
3
|
+
require 'plex/autodelete/version'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Plex
|
7
|
+
module Autodelete
|
8
|
+
class CLI < Thor
|
9
|
+
|
10
|
+
@@myplex = {
|
11
|
+
host: 'plex.tv',
|
12
|
+
port: 443
|
13
|
+
}
|
14
|
+
|
15
|
+
desc "cleanup", "Remove all watched episodes from Plex"
|
16
|
+
option :host, default: '127.0.0.1', desc: 'The hostname/ip address of the Plex Server'
|
17
|
+
option :port, default: 32400, desc: 'The port of the Plex Server'
|
18
|
+
option :token, required: true, desc: 'The token of the plex server, generate with "plex-autodelete token"'
|
19
|
+
option :skip, type: :array, desc: 'An array of shows to skip, these will not be deleted. Use quotes if show contains spaces/special characters.'
|
20
|
+
option :delete, type: :boolean, default: true, desc: 'Skip actual deletion of files, useful for testing settings'
|
21
|
+
option :section, type: :numeric, default: 1, desc: 'Which section are your TV shows in?'
|
22
|
+
def cleanup
|
23
|
+
output_config
|
24
|
+
Plex::Autodelete::Cleanup.configure config
|
25
|
+
Plex::Autodelete::Cleanup.cleanup
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'token', 'Generate the auth token needed to use "plex-autodelete cleanup"'
|
29
|
+
option :username, required: true, desc: 'Your my.plex.tv username (this will not be stored)'
|
30
|
+
option :password, required: true, desc: 'Your my.plex.tv password (this will not be stored)'
|
31
|
+
def token
|
32
|
+
http = Net::HTTP.new(@@myplex[:host], @@myplex[:port])
|
33
|
+
http.use_ssl = true
|
34
|
+
http.start do |http|
|
35
|
+
request = Net::HTTP::Post.new('/users/sign_in.xml', initheader = {'X-Plex-Client-Identifier' =>'Plex Autodelete'})
|
36
|
+
request.basic_auth options[:username], options[:password]
|
37
|
+
response, data = http.request(request)
|
38
|
+
|
39
|
+
parser = Nori.new
|
40
|
+
hash = parser.parse(response.response.body)
|
41
|
+
|
42
|
+
if hash.has_key?('errors')
|
43
|
+
hash['errors'].each do |error|
|
44
|
+
puts error.to_s
|
45
|
+
end
|
46
|
+
else
|
47
|
+
authentication_token = hash['user']['authentication_token'].to_s
|
48
|
+
puts "Authentication Token: #{authentication_token}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def output_config
|
55
|
+
output = []
|
56
|
+
output << "Host: #{config[:host]}"
|
57
|
+
output << "Port: #{config[:port]}"
|
58
|
+
output << "Token: #{config[:token]}"
|
59
|
+
output << "Section: #{config[:section]}"
|
60
|
+
output << "Skip Shows: #{config[:skip] || 'N/A'}"
|
61
|
+
output << "Skip Delete: #{delete_text}"
|
62
|
+
output << "--------------------"
|
63
|
+
output << ""
|
64
|
+
output = output.join("\n")
|
65
|
+
puts output
|
66
|
+
end
|
67
|
+
|
68
|
+
def config
|
69
|
+
{
|
70
|
+
host: options[:host],
|
71
|
+
port: options[:port],
|
72
|
+
token: options[:token],
|
73
|
+
section: options[:section],
|
74
|
+
skip: options[:skip],
|
75
|
+
delete: options[:delete],
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete_text
|
80
|
+
options[:delete] ? 'true' : 'false'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'plex/autodelete/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "plex-autodelete"
|
8
|
+
spec.version = Plex::Autodelete::VERSION
|
9
|
+
spec.authors = ["Scott Robertson"]
|
10
|
+
spec.email = ["scottymeuk@gmail.com"]
|
11
|
+
spec.summary = "Automatically removed watched episodes in Plex"
|
12
|
+
spec.description = "Automatically removed watched episodes in Plex"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency 'plex-ruby', '~> 1.5', '>= 1.5.1'
|
24
|
+
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
25
|
+
spec.add_runtime_dependency 'nori', '~> 2.4', '>= 2.4.0'
|
26
|
+
spec.add_runtime_dependency 'mini_portile', '~> 0.6.1'
|
27
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Robertson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: plex-ruby
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,15 +107,23 @@ dependencies:
|
|
79
107
|
- !ruby/object:Gem::Version
|
80
108
|
version: 0.6.1
|
81
109
|
description: Automatically removed watched episodes in Plex
|
82
|
-
email:
|
110
|
+
email:
|
111
|
+
- scottymeuk@gmail.com
|
83
112
|
executables:
|
84
113
|
- plex-autodelete
|
85
114
|
extensions: []
|
86
115
|
extra_rdoc_files: []
|
87
116
|
files:
|
117
|
+
- ".gitignore"
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- Rakefile
|
88
121
|
- bin/plex-autodelete
|
89
|
-
- lib/plex
|
90
|
-
|
122
|
+
- lib/plex/autodelete/cleanup.rb
|
123
|
+
- lib/plex/autodelete/cli.rb
|
124
|
+
- lib/plex/autodelete/version.rb
|
125
|
+
- plex-autodelete.gemspec
|
126
|
+
homepage: ''
|
91
127
|
licenses:
|
92
128
|
- MIT
|
93
129
|
metadata: {}
|
data/lib/plex-autodelete.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'plex-ruby'
|
2
|
-
|
3
|
-
class Autodelete
|
4
|
-
|
5
|
-
@config = {
|
6
|
-
host: '127.0.0.1',
|
7
|
-
port: 32400,
|
8
|
-
token: nil,
|
9
|
-
skip: [],
|
10
|
-
delete: true,
|
11
|
-
section: 1,
|
12
|
-
}
|
13
|
-
|
14
|
-
@config_keys = @config.keys
|
15
|
-
|
16
|
-
def self.configure(opts = {})
|
17
|
-
opts.each {|key, value| @config[key.to_sym] = value if @config_keys.include? key.to_sym}
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.required_params!
|
21
|
-
[:host, :port, :token, :section].each do |param|
|
22
|
-
if @config[param].nil?
|
23
|
-
raise Exception
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.cleanup
|
29
|
-
|
30
|
-
self.required_params!
|
31
|
-
|
32
|
-
Plex.configure do |config|
|
33
|
-
config.auth_token = @config[:token]
|
34
|
-
end
|
35
|
-
|
36
|
-
server = Plex::Server.new(@config[:host], @config[:port])
|
37
|
-
|
38
|
-
server.library.section(@config[:section]).all.each do |show|
|
39
|
-
next if @config[:skip].include? show.title
|
40
|
-
|
41
|
-
show.seasons.each do |season|
|
42
|
-
season.episodes.each do |episode|
|
43
|
-
if episode.respond_to?(:view_count)
|
44
|
-
puts " - #{show.title} - #{season.title} - #{episode.title}"
|
45
|
-
episode.medias.each do |media|
|
46
|
-
media.parts.each do |part|
|
47
|
-
if File.exist?(part.file) and @config[:delete]
|
48
|
-
File.delete(part.file)
|
49
|
-
puts " - File Removed: #{part.file}"
|
50
|
-
else
|
51
|
-
puts " - File Not Removed: #{part.file}"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
puts nil
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
|