class ParsedShowName
Attributes
episode[RW]
season[RW]
showName[RW]
Public Class Methods
create(showName, season, episode)
click to toggle source
# File plugins/shows/lib/showname_parse.rb, line 98 def self.create(showName, season, episode) rc = ParsedShowName.new rc.showName = showName rc.season = season rc.episode = episode rc end
new()
click to toggle source
# File plugins/shows/lib/showname_parse.rb, line 91 def initialize end
parse(rawName, metaInfo)
click to toggle source
Given a single episode raw string (as from a filename) in rawName, and given some metaInfo (such as the file’s parent directory) returns an array of ParsedShowName
objects representing the episodes found in the string.
Format 1: Show.Name.S01E01.whatever.avi Format 2: Show.Name.S01E01E02.whatever.avi Format 3: Show Name season 3 episode 2 whatever.avi Format 4: Show.Name.1x2.whatever.avi
# File plugins/shows/lib/showname_parse.rb, line 114 def self.parse(rawName, metaInfo) rc = [] if rawName =~ /^(.*)[sS](\d+)((?:[eE]\d+)+)/ showName = self.fixShowName($1, metaInfo) season = $2.to_i # Parse the episode part; it might be more than one episode episodeStr = $3 episodeStr.scan(/[eE](\d+)/){ |ep| episode = ep.first.to_i rc.push ParsedShowName.create(showName, season, episode) } # Format 3: "The Vampire Diaries Season 3 Episode 2", elsif rawName =~ /^(.*)season[^\d]+(\d+)[^\d]+episode[^\d]+(\d+)/i showName = self.fixShowName($1, metaInfo) season = $2.to_i # Parse the episode part; it might be more than one episode episode = $3.to_i rc.push ParsedShowName.create(showName, season, episode) # Format 4: elsif rawName =~ /^(.*)\.(\d+)x(\d+)\./ showName = self.fixShowName($1, metaInfo) season = $2.to_i # Parse the episode part; it might be more than one episode episode = $3.to_i rc.push ParsedShowName.create(showName, season, episode) end rc end
Private Class Methods
fixShowName(name, metaInfo)
click to toggle source
# File plugins/shows/lib/showname_parse.rb, line 147 def self.fixShowName(name, metaInfo) if name.length == 0 && metaInfo if metaInfo.parentDir name = File.basename(metaInfo.parentDir) end end name = name.tr('.',' ').strip # Strip off trailing and leading wierd characters. if name =~ /^[_\-]*([\sa-zA-Z0-9]+)[_\-]*$/ name = $1 end parts = name.strip.split(/\s+/) parts.collect!{ |e| e.capitalize } parts.join(' ') end