Sha256: 5d509947b561dc3cc4eb5d986855fba7bf850f8d998c61c3b180b4f705ef0a87

Contents?: true

Size: 1.7 KB

Versions: 9

Compression:

Stored size: 1.7 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

                    # only files with one line with the title are interesting
                    next if data.lines.to_a.size > 1

                    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

9 entries across 9 versions & 1 rubygems

Version Path
serienrenamer-0.0.14 lib/plugin/textfile.rb
serienrenamer-0.0.13 lib/plugin/textfile.rb
serienrenamer-0.0.12 lib/plugin/textfile.rb
serienrenamer-0.0.11 lib/plugin/textfile.rb
serienrenamer-0.0.10 lib/plugin/textfile.rb
serienrenamer-0.0.9 lib/plugin/textfile.rb
serienrenamer-0.0.8 lib/plugin/textfile.rb
serienrenamer-0.0.7 lib/plugin/textfile.rb
serienrenamer-0.0.6 lib/plugin/textfile.rb