iml 0.1.6 → 0.2.0

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/lib/iml/patterns.rb DELETED
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Contains methods to build the regexp to match against the input filenames
4
- class IML::Patterns
5
- # @return [IML::Hash] pattern config
6
- def config
7
- IML::Hash.new ::YAML.load_file(pattern_file)
8
- end
9
-
10
- # @return [IML::Hash] pattern config singleton version
11
- def self.config
12
- new.config
13
- end
14
-
15
- # Mini format arrtibute DSL
16
- def method_missing(method_name)
17
- m = config[method_name]
18
- super unless m
19
- if m.is_a?(Hash)
20
- "(?<#{method_name}>(#{m.keys.join('|')}))"
21
- elsif m.is_a?(Array)
22
- "(?<#{method_name}>(#{m.join('|')}))"
23
- elsif m.is_a?(String)
24
- "(?<#{method_name}>#{m})"
25
- end
26
- end
27
-
28
- # @return <Boolean> true when method name is a config key
29
- def respond_to_missing?(method_name, _include_private = false)
30
- config.key?(method_name) || false
31
- end
32
-
33
- # @return [Array<Regex>] Array of Regexp patterns to match filenames of Movies
34
- def movie
35
- [
36
- /#{format_pattern('^%<title>s\.%<year>s\.?%<quality>s?\.%<source>s\.%<codec>s\.?%<audio>s?-?%<group>s\.%<extension>s$')}/i,
37
- /#{format_pattern('^%<title>s_\(%<year>s\)_\[%<quality>s,%<source>s,%<audio>s,%<codec>s\]_-_%<group>s.%<extension>s$')}/i
38
- ]
39
- end
40
-
41
- # @return [Array<Regex>] Array of Regexp patterns to match filenames of TV Shows
42
- def tv
43
- [
44
- /#{format_pattern('^%<title>s.S%<season>sE%<episode>s.?%<episode_title>s?.?%<quality>s?.%<source>s.%<audio>s?\.?%<codec>s-%<group>s.%<extension>s$')}/i
45
- ]
46
- end
47
-
48
- private
49
-
50
- def pattern_file
51
- Pathname(__dir__) + '..' + '..' + 'patterns.yml'
52
- end
53
-
54
- def media_info
55
- {
56
- title: title, year: year, quality: quality, source: source, codec: codec, audio: audio, group: group,
57
- extension: extension, season: season, episode: episode, episode_title: episode_title
58
- }
59
- end
60
-
61
- def format_pattern(pattern)
62
- format(pattern, media_info)
63
- end
64
- end
data/lib/iml/text.rb DELETED
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Parsing and mangling of text metadata
4
- class IML::Text < String
5
- attr_accessor :options
6
-
7
- def initialize(string = nil, options = {})
8
- @options = options
9
- super(string.to_s)
10
- end
11
-
12
- # Convert IML::Text to desired title format
13
- def to_title
14
- tr('.', ' ').tr('_', ' ').titleize
15
- end
16
-
17
- # Determine if IML::Text matches rules for a media type
18
- # @return [<IML::Movie>, <IML::TVSeries>] Media type object
19
- def detect
20
- tv? || movie? || false
21
- end
22
-
23
- private
24
-
25
- def tv?
26
- match = match_patterns(IML::Patterns.new.tv)
27
- match ? IML::TVSeries.new(match, options) : false
28
- end
29
-
30
- def movie?
31
- match = match_patterns(IML::Patterns.new.movie)
32
- match ? IML::Movie.new(match, options) : false
33
- end
34
-
35
- def match_patterns(patterns)
36
- patterns.each do |pattern|
37
- match = match_and_return(pattern)
38
- return match if match
39
- end
40
- false
41
- end
42
-
43
- def match_and_return(pattern)
44
- match = self.match(pattern)
45
- if match
46
- match.named_captures
47
- else
48
- false
49
- end
50
- end
51
- end
data/lib/iml/tvseries.rb DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # TV Series media file type class
4
- class IML::TVSeries < IML::Base
5
- # Formatting placeholders for TV Series
6
- PLACEHOLDERS = {
7
- '%T' => :title,
8
- '%E' => :episode,
9
- '%S' => :season,
10
- '%f' => :extension,
11
- '%e' => :episode_i,
12
- '%s' => :season_i,
13
- '%t' => :episode_title,
14
- '%a' => :audio,
15
- '%v' => :codec,
16
- '%q' => :quality,
17
- '%g' => :group,
18
- '%z' => :source
19
- }.freeze
20
-
21
- # Default formatting sting
22
- DEFAULT_FORMAT = '%T/Season %s/%T - S%SE%E.%f'
23
-
24
- # @return <Boolean> always true for IML::TVSeries
25
- def tv?
26
- true
27
- end
28
-
29
- # @return <Integer> Season number in Integer
30
- def season_i
31
- season.to_i
32
- end
33
-
34
- # @return <Integer> episode number in Integer
35
- def episode_i
36
- episode.to_i
37
- end
38
- end