plex-autodelete 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/plex-autodelete +91 -0
- data/lib/plex-autodelete.rb +63 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f22e2d591972c6c22992b99d6aa7ef2527949ad5
|
4
|
+
data.tar.gz: e8dcb854d04850e133c3f78e3c7dbd59221d0105
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a7c019c5c60e4c3be5608fc5992869a8b92f459a9e3422beacb636208e53e45b0af98360f59155d9f613d37b6379971bcd33aa92044c0e8a50f9e9bd89d7fa0
|
7
|
+
data.tar.gz: ef99b4aa5e6cd9560815f26c1706e5fbd27f62dea8d8eada74d0b6732c1a7072952fa198cc19632cadf06d8a916b1bf3073075e8babf8243640ab0ea055f1d73
|
data/bin/plex-autodelete
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "thor"
|
5
|
+
require "nori"
|
6
|
+
require 'net/https'
|
7
|
+
|
8
|
+
Dir["./lib/*.rb"].each {|file| require file }
|
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
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
PlexAutoDelete.start(ARGV)
|
91
|
+
|
@@ -0,0 +1,63 @@
|
|
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
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plex-autodelete
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: plex-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.5.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.5.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: thor
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.19.1
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.19.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: nori
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.4'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.4.0
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.4'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.4.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: mini_portile
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.6.1
|
74
|
+
type: :runtime
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.6.1
|
81
|
+
description: Automatically removed watched episodes in Plex
|
82
|
+
email: scottymeuk@gmail.com
|
83
|
+
executables:
|
84
|
+
- plex-autodelete
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- bin/plex-autodelete
|
89
|
+
- lib/plex-autodelete.rb
|
90
|
+
homepage: http://rubygems.org/gems/plex-autodelete
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Automatically removed watched episodes in Plex
|
114
|
+
test_files: []
|