diff --git a/lib/movies/filter.rb b/lib/movies/filter.rb index 18503e7..a12ea3d 100644 --- a/lib/movies/filter.rb +++ b/lib/movies/filter.rb @@ -23,6 +23,7 @@ def to_param def cleaner string = @title + string = extract_tags(string) [/((19|20)\d{2}).*$/, /\./, /\s*-\s*/, /\s{2,}/].each do |regex| string = string.gsub(regex, ' ') end @@ -33,6 +34,17 @@ def cleaner string.strip end + # remove usual tags in filenames like {720p}, (2011) or [KingdomRelease], and save it + def extract_tags(string) + @tags = [] + [ /\[([^\[]*)\]/ , /\{([^\{]*)\}/ , /\(([^\(]*)\)/ ].each do |regex| + while(matched = string.match(regex)) do + @tags << matched[1] + string.gsub!(matched[0]) + end + end + end + private def excluded @_excluded ||= YAML.load_file("#{File.dirname(__FILE__)}/exclude.yml")["excluded"]