scene-toolkit 0.1.1 → 0.1.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.
- data/VERSION +1 -1
- data/lib/scene_toolkit/cli.rb +4 -9
- data/lib/scene_toolkit/release.rb +39 -23
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/scene_toolkit/cli.rb
CHANGED
@@ -56,8 +56,10 @@ class SceneToolkit::CLI
|
|
56
56
|
invalid_releases += 1
|
57
57
|
puts release.name.foreground(:red)
|
58
58
|
puts release.path
|
59
|
-
release.errors.each do |
|
60
|
-
|
59
|
+
release.errors.each do |validation, errors|
|
60
|
+
errors.each do |error|
|
61
|
+
puts " - #{error}"
|
62
|
+
end
|
61
63
|
end
|
62
64
|
|
63
65
|
puts
|
@@ -97,7 +99,6 @@ class SceneToolkit::CLI
|
|
97
99
|
raise ArgumentError("#{source} is not a directory") unless File.directory?(source)
|
98
100
|
|
99
101
|
releases = []
|
100
|
-
uids = {}
|
101
102
|
|
102
103
|
Dir.glob(File.join(source, "**", "*.mp3")).each do |file|
|
103
104
|
release_path = File.expand_path(File.dirname(file))
|
@@ -106,12 +107,6 @@ class SceneToolkit::CLI
|
|
106
107
|
release = SceneToolkit::Release.new(release_path, @cache)
|
107
108
|
releases << release_path
|
108
109
|
yield(release)
|
109
|
-
|
110
|
-
if uids.has_key?(release.uid)
|
111
|
-
release.errors << "Duplicate release of #{uids[release.uid]}"
|
112
|
-
else
|
113
|
-
uids[release.uid] = release.path
|
114
|
-
end
|
115
110
|
end
|
116
111
|
end
|
117
112
|
end
|
@@ -4,46 +4,46 @@ require 'zlib'
|
|
4
4
|
class SceneToolkit::Release
|
5
5
|
REQUIRED_FILES = [:sfv, :nfo, :m3u]
|
6
6
|
VALIDATIONS = [:name, :required_files, :checksum]
|
7
|
-
|
7
|
+
|
8
8
|
attr_accessor :name, :path, :uid
|
9
9
|
attr_accessor :errors
|
10
10
|
|
11
|
-
class << self
|
12
|
-
def has_files_with_extension(*exts)
|
13
|
-
exts.each do |ext|
|
14
|
-
define_method "#{ext}_files" do
|
15
|
-
files.select { |f| File.extname(f).downcase.eql?(".#{ext}") }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
has_files_with_extension :mp3, :sfv, :nfo, :m3u
|
21
|
-
|
22
11
|
def initialize(path, cache)
|
23
12
|
@cache = cache
|
24
13
|
@path = path
|
25
14
|
@name = File.basename(path)
|
26
15
|
@uid = Digest::MD5.hexdigest(@name.downcase.gsub(/[^A-Z0-9]/i, ' ').gsub(/\s+/, ' '))
|
27
16
|
@errors = {}
|
28
|
-
VALIDATIONS.each do |validation|
|
29
|
-
@errors[validation] = []
|
30
|
-
end
|
31
17
|
end
|
32
18
|
|
33
19
|
def valid?(validations = VALIDATIONS)
|
20
|
+
@errors = {}
|
21
|
+
|
34
22
|
if @cache.releases.modified?(self)
|
35
|
-
|
23
|
+
# if release was modified, invalidate all cached validations
|
24
|
+
@cache.releases.flush(self)
|
36
25
|
validations.each do |validation|
|
37
26
|
send("valid_#{validation}?")
|
38
27
|
end
|
39
|
-
@cache.releases.store(self)
|
40
28
|
else
|
41
|
-
|
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
|
+
end
|
42
38
|
end
|
43
|
-
|
39
|
+
|
40
|
+
@cache.releases.store(self)
|
41
|
+
|
42
|
+
@errors.sum { |validation, errors| errors.size }.zero?
|
44
43
|
end
|
45
44
|
|
46
45
|
def valid_required_files?
|
46
|
+
@errors[:required_files] = []
|
47
47
|
REQUIRED_FILES.each do |ext|
|
48
48
|
file_count = send("#{ext}_files")
|
49
49
|
@errors[:required_files] << "No #{ext} found." if file_count.none?
|
@@ -51,11 +51,9 @@ class SceneToolkit::Release
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def files
|
55
|
-
Dir.glob(File.join(@path, "*"))
|
56
|
-
end
|
57
|
-
|
58
54
|
def valid_checksum?
|
55
|
+
@errors[:checksum] = []
|
56
|
+
|
59
57
|
sfv_file = sfv_files.first
|
60
58
|
|
61
59
|
return if sfv_file.nil?
|
@@ -88,9 +86,27 @@ class SceneToolkit::Release
|
|
88
86
|
end
|
89
87
|
|
90
88
|
def valid_name?
|
89
|
+
@errors[:name] = []
|
91
90
|
@errors[:name] << "Release name is not a valid scene release name" unless @name =~ /^([A-Z0-9\-_.()&]+)\-(\d{4}|\d{3}x|\d{2}xx)\-([A-Z0-9_]+)$/i
|
92
91
|
@errors[:name] << "Release name is lowercased" if @name.eql?(@name.downcase)
|
93
92
|
@errors[:name] << "Release name is uppercased" if @name.eql?(@name.upcase)
|
94
93
|
end
|
94
|
+
|
95
|
+
def files
|
96
|
+
Dir.glob(File.join(@path, "*"))
|
97
|
+
end
|
98
|
+
|
99
|
+
class << self
|
100
|
+
protected
|
101
|
+
|
102
|
+
def has_files_with_extension(*exts)
|
103
|
+
exts.each do |ext|
|
104
|
+
define_method "#{ext}_files" do
|
105
|
+
files.select { |f| File.extname(f).downcase.eql?(".#{ext}") }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
has_files_with_extension :mp3, :sfv, :nfo, :m3u
|
95
111
|
end
|
96
112
|
|
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: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
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-19 00:00:00 +02:00
|
19
19
|
default_executable: scene-toolkit
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|