Sha256: be448c3690ab09db886292b927bdb05eb8c77581e433c1b2310c40a7f728d0a6

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

#
# Class that searches for a file with
# episode information in the directory
# like "episode.txt"
#

module Plugin

    class Textfile < Serienrenamer::Pluginbase

        def self.plugin_name; "Textfile" end
        def self.usable; true end
        def self.priority; 100 end

        # this method will be called from the main program
        # with an Serienrenamer::Episode instance or a path
        # to to a directory as parameter
        #
        # it returns an array of episode information
        def self.generate_episode_information(episode)

            sourcedir = ""
            if episode.is_a?(Serienrenamer::Episode) && episode.source_directory
                sourcedir = episode.source_directory
            elsif episode.is_a?(String) && File.directory?(episode)
                sourcedir = episode
            end

            matched_episodes = []

            if sourcedir != "" && Dir.exists?(sourcedir)

                # search for files that are smaller than 128 Bytes
                # an check if they contain episode information
                Dir.new(sourcedir).each do |e|
                    file = File.join(sourcedir, e)
                    next if File.size(file) > 128 || File.zero?(file)

                    data = File.open(file, "rb").read
                    if data != nil && data.match(/\w+/) &&
                            Serienrenamer::Episode.contains_episode_information?(data)
                        matched_episodes.push(data)
                    end
                end
            end

            return matched_episodes
        end
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
serienrenamer-0.0.5 lib/plugin/textfile.rb
serienrenamer-0.0.4 lib/plugin/textfile.rb
serienrenamer-0.0.3 lib/plugin/textfile.rb
serienrenamer-0.0.2 lib/plugin/textfile.rb
serienrenamer-0.0.1 lib/plugin/textfile.rb