# frozen_string_literal: true module VixenRename module FileParser # rubocop:disable Lint/MixedRegexpCaptureTypes UNPROCESSED_SCENE_TYPE_1_REGEX = / ^ # Start of String (?(DEEPER|VIXEN|BLACKEDRAW|BLACKED|TUSHYRAW|TUSHY|CHANNELS)) # Site Name _ # Separator (?\d*) # Video ID _\d{3,4}P # Video Resolution .mp4 # File Extension $ # End of String /x.freeze UNPROCESSED_SCENE_TYPE_2_REGEX = / ^ # Start of String (?(DEEPER|VIXEN|BLACKEDRAW|BLACKED|TUSHYRAW|TUSHY|CHANNELS)) # Site Name _ # Separator (?\d{6}) # Video ID -.*_ # Actor First Name \d{3,4}P # Resolution .mp4 # File Extension $ # End of String /x.freeze # rubocop:enable Lint/MixedRegexpCaptureTypes # Class to fetch details for a scene using the filename class Scene # @param [VixenRename::Net] net def initialize(net) @net = net end # @param [String] file Name of file def process(file) @file = file return if match.nil? hash = search(match[:video_id], match[:site]) return filename(hash, File.extname(@file)), hash[:release_date] end private def match return @file.match(UNPROCESSED_SCENE_TYPE_1_REGEX) unless @file.match(UNPROCESSED_SCENE_TYPE_1_REGEX).nil? @file.match(UNPROCESSED_SCENE_TYPE_2_REGEX) unless @file.match(UNPROCESSED_SCENE_TYPE_2_REGEX).nil? end def search(video_id, site) @net.get_video_by_id(video_id, site) end def filename(hash, extension) "#{hash[:models].join(", ")} [T] #{hash[:title].strip} [S] #{hash[:site].strip} [ID] #{hash[:video_id]}#{extension}" end end end end