Class: ElchScan::Movie
- Inherits:
-
Object
show all
- Defined in:
- lib/elch_scan/movie.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
dir => source movie directory (e.g. C:/Movies) path => folder path of movie (e.g. C:/Movies/BestFilmEver) dirname => source movie directory name (e.g. BestFilmEver) nfo => path to nfo file.
-
#files ⇒ Object
readonly
dir => source movie directory (e.g. C:/Movies) path => folder path of movie (e.g. C:/Movies/BestFilmEver) dirname => source movie directory name (e.g. BestFilmEver) nfo => path to nfo file.
Instance Method Summary
collapse
Constructor Details
#initialize(app, attrs = {}) ⇒ Movie
Returns a new instance of Movie.
9
10
11
12
13
|
# File 'lib/elch_scan/movie.rb', line 9
def initialize app, attrs = {}
@app = ->{app}
@attrs = {}.merge(attrs).with_indifferent_access
analyze!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/elch_scan/movie.rb', line 19
def method_missing(meth, *args, &blk)
qmeth = meth.to_s.gsub("?", "") if meth.to_s.end_with?("?")
smeth = meth.to_s.gsub("=", "") if meth.to_s.end_with?("=")
if @attrs.keys.include?(meth.to_s)
@attrs[meth]
elsif @attrs.keys.include?(smeth)
@attrs[smeth] = args.first
@attrs[smeth]
elsif @attrs.keys.include?(qmeth)
!!@attrs[qmeth]
else
return false if qmeth
super
end
end
|
Instance Attribute Details
#attrs ⇒ Object
dir => source movie directory (e.g. C:/Movies) path => folder path of movie (e.g. C:/Movies/BestFilmEver) dirname => source movie directory name (e.g. BestFilmEver) nfo => path to nfo file
7
8
9
|
# File 'lib/elch_scan/movie.rb', line 7
def attrs
@attrs
end
|
#files ⇒ Object
dir => source movie directory (e.g. C:/Movies) path => folder path of movie (e.g. C:/Movies/BestFilmEver) dirname => source movie directory name (e.g. BestFilmEver) nfo => path to nfo file
7
8
9
|
# File 'lib/elch_scan/movie.rb', line 7
def files
@files
end
|
Instance Method Details
#analyze! ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/elch_scan/movie.rb', line 41
def analyze!
set :dirname, File.basename(path)
@files = Dir.glob("#{path.gsub("[", "\\[")}/*.*")
matched = naming_select(@files)
matched.each_with_object({}) {|(name, matches), r| set name, matches.try(:first) }
set :movie, select_movies(@files).sort_by(&:length).first
app.warn "No movie file found for #{dirname}" unless movie?
end
|
#app ⇒ Object
15
16
17
|
# File 'lib/elch_scan/movie.rb', line 15
def app
@app.call
end
|
#name ⇒ Object
88
89
90
|
# File 'lib/elch_scan/movie.rb', line 88
def name
movie.split(".")[0..-2].join(".") if movie?
end
|
#naming_select(strings) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/elch_scan/movie.rb', line 51
def naming_select strings
raw_patterns = app.cfg(:application, :naming).symbolize_keys
patterns = raw_patterns.map do |name, pattern|
[name, /#{Regexp.escape(pattern).gsub("<baseFileName>", ".*?")}/]
end
patterns.each_with_object({}) do |(name, pattern), result|
result[name] = strings.select{|s| s.match(pattern) }
end
end
|
#nfo! ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/elch_scan/movie.rb', line 72
def nfo!
if nfo?
XmlSimple.xml_in(nfo).tap do |nfo|
if block_given?
begin
return yield(nfo)
rescue
return false
end
end
end
end
rescue
false
end
|
#select_movies(strings) ⇒ Object
62
63
64
65
66
|
# File 'lib/elch_scan/movie.rb', line 62
def select_movies strings
strings.map{|s| File.basename(s) }.select do |s|
app.cfg(:application, :video_extensions).split("\s").include?(s.split(".").last)
end
end
|
#set(name, value) ⇒ Object
36
37
38
39
|
# File 'lib/elch_scan/movie.rb', line 36
def set name, value
@attrs[name] = value
@attrs[name]
end
|
#source ⇒ Object
68
69
70
|
# File 'lib/elch_scan/movie.rb', line 68
def source
FFMPEG::Movie.new("#{path}/#{movie}") rescue $!.message
end
|