scene-toolkit 0.1.4 → 0.1.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.
- data/VERSION +1 -1
- data/bin/scene-toolkit +0 -1
- data/lib/scene_toolkit.rb +1 -1
- data/lib/scene_toolkit/cli.rb +15 -22
- data/lib/scene_toolkit/release.rb +32 -54
- metadata +4 -7
- data/lib/scene_toolkit/cache.rb +0 -4
- data/lib/scene_toolkit/cache/base.rb +0 -10
- data/lib/scene_toolkit/cache/releases.rb +0 -76
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/bin/scene-toolkit
CHANGED
@@ -12,7 +12,6 @@ Optitron.dispatch(SceneToolkit::CLI.new) do
|
|
12
12
|
opt "playlist", "Validate playlist against existing files"
|
13
13
|
opt "checksum", "Validate release CRC-32 checksum"
|
14
14
|
opt "hide-valid", "Do not display valid releases"
|
15
|
-
opt "flush-cache", "Flush file modification cache"
|
16
15
|
opt "move-invalid-to", "Move INVALID releases to specified folder", :type => :string
|
17
16
|
opt "move-valid-to", "Move VALID releases to specified folder", :type => :string
|
18
17
|
end
|
data/lib/scene_toolkit.rb
CHANGED
data/lib/scene_toolkit/cli.rb
CHANGED
@@ -7,14 +7,6 @@ require 'optitron'
|
|
7
7
|
require 'rainbow'
|
8
8
|
|
9
9
|
class SceneToolkit::CLI
|
10
|
-
def initialize
|
11
|
-
@cache = SceneToolkit::Cache::Base.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def flush_cache
|
15
|
-
@cache.releases.flush_all
|
16
|
-
end
|
17
|
-
|
18
10
|
def verify(directory, opts)
|
19
11
|
opts.underscore_and_symbolize_keys!
|
20
12
|
validations = []
|
@@ -31,14 +23,11 @@ class SceneToolkit::CLI
|
|
31
23
|
raise ArgumentError.new("#{invalid_target_directory} does not exist") unless File.directory?(invalid_target_directory)
|
32
24
|
end
|
33
25
|
|
34
|
-
|
35
26
|
valid_target_directory = opts.delete(:move_valid_to)
|
36
27
|
unless valid_target_directory.nil?
|
37
28
|
raise ArgumentError.new("#{invalid_target_directory} does not exist") unless File.directory?(valid_target_directory)
|
38
29
|
end
|
39
30
|
|
40
|
-
flush_cache if opts.delete(:flush_cache)
|
41
|
-
|
42
31
|
release_count = 0
|
43
32
|
valid_releases = 0
|
44
33
|
invalid_releases = 0
|
@@ -46,32 +35,36 @@ class SceneToolkit::CLI
|
|
46
35
|
each_release(directory) do |release|
|
47
36
|
release_count += 1
|
48
37
|
|
49
|
-
if release.valid?(validations)
|
38
|
+
if release_valid = release.valid?(validations)
|
50
39
|
valid_releases += 1
|
51
40
|
puts release.name.foreground(:green) unless opts[:hide_valid]
|
52
|
-
move_release(release, valid_target_directory) unless valid_target_directory.nil?
|
53
41
|
else
|
54
42
|
invalid_releases += 1
|
55
43
|
puts release.name.foreground(:red)
|
56
|
-
move_release(release, invalid_target_directory) unless invalid_target_directory.nil?
|
57
44
|
end
|
58
45
|
|
59
46
|
puts release.path
|
60
47
|
|
61
|
-
puts "#{release.errors.values.sum(&:count)} errors"
|
62
48
|
release.errors.each do |validation, errors|
|
63
49
|
errors.each do |error|
|
64
|
-
puts "
|
50
|
+
puts " ✕ #{error}".foreground(:red)
|
65
51
|
end
|
66
52
|
end
|
67
53
|
|
68
|
-
puts "#{release.warnings.values.sum(&:count)} warnings"
|
69
54
|
release.warnings.each do |validation, warnings|
|
70
55
|
warnings.each do |warning|
|
71
|
-
puts "
|
56
|
+
puts " ✕ #{warning}".foreground(:yellow)
|
72
57
|
end
|
73
58
|
end
|
74
59
|
|
60
|
+
unless valid_target_directory.nil?
|
61
|
+
move_release(release, valid_target_directory) if release_valid
|
62
|
+
end
|
63
|
+
|
64
|
+
unless invalid_target_directory.nil?
|
65
|
+
move_release(release, invalid_target_directory) unless release_valid
|
66
|
+
end
|
67
|
+
|
75
68
|
puts
|
76
69
|
end
|
77
70
|
|
@@ -83,10 +76,10 @@ class SceneToolkit::CLI
|
|
83
76
|
|
84
77
|
def move_release(release, destination)
|
85
78
|
target_dir = File.join(destination, release.name)
|
86
|
-
puts "Moving release to #{target_dir}".foreground(:yellow)
|
79
|
+
puts " ■ Moving release to #{target_dir}".foreground(:yellow)
|
87
80
|
|
88
81
|
if File.directory?(target_dir)
|
89
|
-
puts "Target directory already exists. Skipping.".foreground(:red)
|
82
|
+
puts " ✕ Target directory already exists. Skipping.".foreground(:red)
|
90
83
|
else
|
91
84
|
begin
|
92
85
|
FileUtils.mv(release.path, target_dir)
|
@@ -94,7 +87,6 @@ class SceneToolkit::CLI
|
|
94
87
|
puts e.message.foreground(:red)
|
95
88
|
end
|
96
89
|
end
|
97
|
-
puts
|
98
90
|
end
|
99
91
|
|
100
92
|
def each_release(source, &block)
|
@@ -107,10 +99,11 @@ class SceneToolkit::CLI
|
|
107
99
|
release_path = File.expand_path(File.dirname(file))
|
108
100
|
|
109
101
|
unless releases.include?(release_path)
|
110
|
-
release = SceneToolkit::Release.new(release_path
|
102
|
+
release = SceneToolkit::Release.new(release_path)
|
111
103
|
releases << release_path
|
112
104
|
yield(release)
|
113
105
|
end
|
114
106
|
end
|
115
107
|
end
|
108
|
+
|
116
109
|
end
|
@@ -8,8 +8,7 @@ class SceneToolkit::Release
|
|
8
8
|
attr_accessor :name, :path, :uid
|
9
9
|
attr_accessor :errors, :warnings
|
10
10
|
|
11
|
-
def initialize(path
|
12
|
-
@cache = cache
|
11
|
+
def initialize(path)
|
13
12
|
@path = path
|
14
13
|
@name = File.basename(path)
|
15
14
|
@uid = Digest::MD5.hexdigest(@name.downcase.gsub(/[^A-Z0-9]/i, ' ').gsub(/\s+/, ' '))
|
@@ -18,34 +17,9 @@ class SceneToolkit::Release
|
|
18
17
|
|
19
18
|
def valid?(validations = VALIDATIONS)
|
20
19
|
@errors, @warnings = {}, {}
|
21
|
-
|
22
|
-
|
23
|
-
# if release was modified, invalidate all cached validations
|
24
|
-
@cache.releases.flush(self)
|
25
|
-
validations.each do |validation|
|
26
|
-
send("valid_#{validation}?")
|
27
|
-
end
|
28
|
-
else
|
29
|
-
validations.each do |validation|
|
30
|
-
validation_errors = @cache.releases.errors(self, [validation])
|
31
|
-
if validation_errors.nil?
|
32
|
-
# execute validation if release was catched but this particular validation was not executed
|
33
|
-
send("valid_#{validation}?")
|
34
|
-
else
|
35
|
-
@errors.merge!(validation_errors)
|
36
|
-
end
|
37
|
-
|
38
|
-
validation_warnings = @cache.releases.warnings(self, [validation])
|
39
|
-
if validation_warnings.nil?
|
40
|
-
# execute validation if release was catched but this particular validation was not executed
|
41
|
-
send("valid_#{validation}?")
|
42
|
-
else
|
43
|
-
@warnings.merge!(validation_warnings)
|
44
|
-
end
|
45
|
-
end
|
20
|
+
validations.each do |validation|
|
21
|
+
send("valid_#{validation}?")
|
46
22
|
end
|
47
|
-
|
48
|
-
@cache.releases.store(self)
|
49
23
|
@errors.sum { |validation, errors| errors.size }.zero?
|
50
24
|
end
|
51
25
|
|
@@ -63,44 +37,48 @@ class SceneToolkit::Release
|
|
63
37
|
playlist = m3u_files.first
|
64
38
|
|
65
39
|
unless playlist.nil?
|
66
|
-
File.read(
|
67
|
-
|
68
|
-
|
40
|
+
File.read(playlist).split(/[\r\n]+/).each do |filename|
|
41
|
+
filename.strip!
|
42
|
+
next if filename.blank? or filename.start_with?("#") or filename.start_with?(";")
|
43
|
+
@errors[:playlist] << "File #{filename} not found (M3U)" unless File.exist?(File.join(@path, filename))
|
69
44
|
end
|
70
45
|
end
|
71
46
|
end
|
72
47
|
|
73
48
|
def valid_checksum?
|
74
49
|
@errors[:checksum], @warnings[:checksum] = [], []
|
50
|
+
sfv = sfv_files.first
|
75
51
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
collection[File.basename(file).downcase] = File.expand_path(file)
|
82
|
-
collection
|
83
|
-
end
|
52
|
+
unless sfv.blank? do
|
53
|
+
files_to_check = files.inject({}) do |collection, file|
|
54
|
+
collection[File.basename(file).downcase] = File.expand_path(file)
|
55
|
+
collection
|
56
|
+
end
|
84
57
|
|
85
|
-
|
86
|
-
|
58
|
+
matched_something = false
|
59
|
+
File.read(sfv).split(/[\r\n]+/).each do |line|
|
60
|
+
line.strip!
|
87
61
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
62
|
+
if (/(generated|raped)/i =~ line and not /MorGoTH/i =~ line)
|
63
|
+
@warnings[:checksum] << "Possibly tampered SFV: #{line.strip}"
|
64
|
+
end
|
92
65
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
66
|
+
if match = /^(.+?)\s+([\dA-Fa-f]{8})$/.match(line)
|
67
|
+
matched_something = true
|
68
|
+
filename, checksum = match.captures
|
69
|
+
filename.strip!.downcase!
|
70
|
+
|
71
|
+
if files_to_check.has_key?(filename)
|
72
|
+
unless Zlib.crc32(File.read(files_to_check[filename])).eql?(checksum.hex)
|
73
|
+
@errors[:checksum] << "File #{filename} is corrupted (SFV)"
|
74
|
+
end
|
75
|
+
else
|
76
|
+
@errors[:checksum] << "File #{filename} not found (SFV)"
|
98
77
|
end
|
99
|
-
else
|
100
|
-
@errors[:checksum] << "File #{filename} not found"
|
101
78
|
end
|
102
|
-
matched_something = true
|
103
79
|
end
|
80
|
+
@warnings[:checksum] << "No files to verify found (SFV)" unless matched_something
|
81
|
+
end
|
104
82
|
end
|
105
83
|
end
|
106
84
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scene-toolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "V\xC3\xADctor Mart\xC3\xADnez"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-24 00:00:00 +02:00
|
19
19
|
default_executable: scene-toolkit
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -82,9 +82,6 @@ files:
|
|
82
82
|
- VERSION
|
83
83
|
- bin/scene-toolkit
|
84
84
|
- lib/scene_toolkit.rb
|
85
|
-
- lib/scene_toolkit/cache.rb
|
86
|
-
- lib/scene_toolkit/cache/base.rb
|
87
|
-
- lib/scene_toolkit/cache/releases.rb
|
88
85
|
- lib/scene_toolkit/cli.rb
|
89
86
|
- lib/scene_toolkit/ext.rb
|
90
87
|
- lib/scene_toolkit/ext/hash.rb
|
data/lib/scene_toolkit/cache.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
class SceneToolkit::Cache::Releases
|
2
|
-
def initialize(cache, cache_key = :releases)
|
3
|
-
@cache = cache
|
4
|
-
@cache_key = cache_key
|
5
|
-
@cache.transaction do
|
6
|
-
@cache[@cache_key] ||= {}
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def modified?(release)
|
11
|
-
@cache.transaction(true) do
|
12
|
-
if @cache[@cache_key].has_key?(release.path)
|
13
|
-
@cache[@cache_key][release.path][:files].each do |filename, mtime|
|
14
|
-
file_path = File.join(release.path, filename)
|
15
|
-
unless File.exists?(file_path) and (@cache[@cache_key][release.path][:files].has_key?(filename) and File.stat(file_path).mtime.eql?(mtime))
|
16
|
-
flush(release)
|
17
|
-
return true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
false
|
21
|
-
else
|
22
|
-
true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def errors(release, validations = SceneToolkit::Release::VALIDATIONS)
|
28
|
-
@cache.transaction(true) do
|
29
|
-
if @cache[@cache_key].has_key?(release.path)
|
30
|
-
@cache[@cache_key][release.path][:errors].reject { |validation, errors| not validations.include?(validation) }
|
31
|
-
else
|
32
|
-
raise RuntimeError.new("Release not catched")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def warnings(release, validations = SceneToolkit::Release::VALIDATIONS)
|
38
|
-
@cache.transaction(true) do
|
39
|
-
if @cache[@cache_key].has_key?(release.path)
|
40
|
-
@cache[@cache_key][release.path][:warnings].reject { |validation, warnings| not validations.include?(validation) }
|
41
|
-
else
|
42
|
-
raise RuntimeError.new("Release not catched")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def files(release)
|
48
|
-
@cache.transaction(true) do
|
49
|
-
@cache[@cache_key][release.path][:files]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def flush(release)
|
54
|
-
@cache.transaction do
|
55
|
-
@cache[@cache_key].delete(release.path) if @cache[@cache_key].has_key?(release.path)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def flush_all
|
60
|
-
@cache.transaction do
|
61
|
-
@cache[@cache_key] = {}
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def store(release)
|
66
|
-
@cache.transaction do
|
67
|
-
@cache[@cache_key][release.path] = {}
|
68
|
-
@cache[@cache_key][release.path][:errors] = release.errors
|
69
|
-
@cache[@cache_key][release.path][:warnings] = release.warnings
|
70
|
-
@cache[@cache_key][release.path][:files] = Dir.glob(File.join(release.path, "*")).inject({}) do |collection, f|
|
71
|
-
collection[File.basename(f)] = File.stat(f).mtime
|
72
|
-
collection
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|