class AppleTvConverter::FilenameParser
Attributes
episode_number[RW]
last_episode_number[RW]
season_number[RW]
tvshow_name[RW]
Public Class Methods
new(path)
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 5 def initialize(path) @path = path end
Private Instance Methods
basename()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 27 def basename @basename ||= File.basename(@path) end
format1_match()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 31 def format1_match # /.*?S(\d+)E(\d+)(?:(?:[-E]+(\d+))*).*?/ -> S00E01, S00E01(E02)+, S00E01(-E02)+, S00E01(-02)+, S00 E01( E02)+ @format1_match ||= basename.match(/.*?S(\d+)\s*E(\d+)(?:(?:[-E]+(\d+)\s*)*).*?/i) end
format2_match()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 36 def format2_match # /(\d+)x(\d+)(?:(?:_?(?:\1)x(\d+))*)/ -> 0x01, 0x01(_0x02)+ , assuming same season number (0x01_1x02 fails!) @format2_match ||= basename.match(/(\d+)x(\d+)(?:(?:_?(?:\1)x(\d+))*)/i) end
format3_match()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 41 def format3_match # /(\d+)_?of_?\d+/i -> 1_of_12, 1of12. Only episode numbers @format3_match ||= basename.match(/(\d+)_?of_?\d+/i) end
parse_episode_number()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 57 def parse_episode_number return format1_match[2].to_i if format1_match return format2_match[2].to_i if format2_match return format3_match[1].to_i if format3_match end
parse_last_episode_number()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 63 def parse_last_episode_number return format1_match[3].to_i if format1_match && format1_match[3] return format2_match[3].to_i if format2_match && format2_match[3] end
parse_season_number()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 52 def parse_season_number return format1_match[1].to_i if format1_match return format2_match[1].to_i if format2_match end
parse_tvshow_name()
click to toggle source
# File lib/apple_tv_converter/filename_parser.rb, line 46 def parse_tvshow_name test_path = File.expand_path(File.basename(File.dirname(@path)) =~ /^season\s*\d+/i ? File.dirname(File.dirname(@path)) : File.dirname(@path)) match = test_path.match(/.*\/(.*?)(?:S(\d+))?$/i) match[1].strip end