Skip to content

Commit

Permalink
reorganized priorities of plugins and changed plugin config in main p…
Browse files Browse the repository at this point in the history
…rogram
  • Loading branch information
Philipp Böhm committed Apr 15, 2012
1 parent 3c3a8dd commit 185ba75
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 95 deletions.
182 changes: 92 additions & 90 deletions bin/serienrenamer
Expand Up @@ -21,11 +21,11 @@ FileUtils.mkdir(CONFIG_DIR) unless File.directory?(CONFIG_DIR)
###
# configuration
STANDARD_CONFIG = {
:default_directory => File.join(File.expand_path("~"), "Downloads"),
:store_episode_info => false,
:store_path => File.join(CONFIG_DIR, "information_storage.yml"),
:byte_count_for_md5 => 2048,
:illegal_words => %w{ ML },
:default_directory => File.join(File.expand_path("~"), "Downloads"),
:store_episode_info => false,
:store_path => File.join(CONFIG_DIR, "information_storage.yml"),
:byte_count_for_md5 => 2048,
:illegal_words => %w{ ML },
}

config = STANDARD_CONFIG.merge_with_serialized(CONFIG_FILE)
Expand All @@ -41,40 +41,40 @@ opts.separator("")
opts.separator(" Options:")

opts.on( "-p", "--plugin STRING", String,
"use only this plugin") do |opt|
options[:plugin] = opt
"use only this plugin") do |opt|
options[:plugin] = opt
end

opts.on( "-s", "--series STRING", String,
"series name that will be set for all episodes") do |opt|
options[:series] = opt
"series name that will be set for all episodes") do |opt|
options[:series] = opt
end

opts.on( "-S", "--[no-]season",
"DIR contains episodes of one season of one series") do |opt|
options[:is_single_season] = opt
opts.on( "-S", "--[no-]season",
"DIR contains episodes of one season of one series") do |opt|
options[:is_single_season] = opt
end

opts.on( "-i", "--[no-]ignore-filenamedata",
"Always ask plugins for episode information") do |opt|
options[:ignore_filenamedata] = opt
opts.on( "-i", "--[no-]ignore-filenamedata",
"Always ask plugins for episode information") do |opt|
options[:ignore_filenamedata] = opt
end

opts.on( "-a", "--[no-]all",
"Process all files (including right formatted files)") do |opt|
options[:process_all_files] = opt
opts.on( "-a", "--[no-]all",
"Process all files (including right formatted files)") do |opt|
options[:process_all_files] = opt
end

opts.on( "--showconfig", "Prints the current configuration.") do |opt|
puts "loaded configuration options:"
puts config.to_yaml
exit(0)
puts "loaded configuration options:"
puts config.to_yaml
exit(0)
end

opts.on( "-v", "--version",
"Prints the version number.") do |opt|
puts Serienrenamer::VERSION
exit(0)
"Prints the version number.") do |opt|
puts Serienrenamer::VERSION
exit(0)
end

opts.separator("")
Expand All @@ -88,7 +88,7 @@ rest = opts.permute(ARGV)
###
# Load plugins #
Dir[File.join(File.dirname(__FILE__),"../lib/plugin/*.rb")].each do |plugin|
load plugin
load plugin
end
Serienrenamer::Pluginbase.registered_plugins.sort! {|x,y| y.priority <=> x.priority }

Expand All @@ -99,93 +99,95 @@ puts ""
episode_directory = rest.pop || config[:default_directory]

fail "'#{episode_directory}' does not exist or is not a directory" unless
Dir.exists?(episode_directory)
Dir.exists?(episode_directory)

Dir.chdir(episode_directory)

###
# Iterate through all directory entries
info_storage = Serienrenamer::InformationStore.new(
config[:store_path], config[:byte_count_for_md5])
config[:store_path], config[:byte_count_for_md5])

begin

for entry in Dir.entries('.').sort do
for entry in Dir.entries('.').sort do

next if entry.match(/^\./)
next unless Serienrenamer::Episode.determine_video_file(entry)
next if entry.match(/^\./)
next unless Serienrenamer::Episode.determine_video_file(entry)

# skip files that already have the right format
unless options[:process_all_files]
next if entry.match(/^S\d+E\d+.-.\w+.*\.\w+$/)
end
# skip files that already have the right format
unless options[:process_all_files]
next if entry.match(/^S\d+E\d+.-.\w+.*\.\w+$/)
end

begin
epi = Serienrenamer::Episode.new(entry)
if options[:series]
epi.series = options[:series]
end
rescue => e
next
end

begin
epi = Serienrenamer::Episode.new(entry)
if options[:series]
epi.series = options[:series]
end
rescue => e
next
puts "<<< #{entry}"

# if episodename is empty than query plugins
if epi.episodename.match(/\w+/).nil? || options[:ignore_filenamedata]

Serienrenamer::Pluginbase.registered_plugins.each do |plugin|
# skip plugins that are not feasable
next unless plugin.usable
next unless plugin.respond_to?(:generate_episode_information)
if options[:plugin]
next unless plugin.plugin_name.match(/#{options[:plugin]}/i)
end

puts "<<< #{entry}"

# if episodename is empty than query plugins
if epi.episodename.match(/\w+/).nil? || options[:ignore_filenamedata]

Serienrenamer::Pluginbase.registered_plugins.each do |plugin|
# skip plugins that are not feasable
next unless plugin.usable
next unless plugin.respond_to?(:generate_episode_information)
if options[:plugin]
next unless plugin.plugin_name.match(/#{options[:plugin]}/i)
end

# configure cleanup
clean_data, extract_seriesname = false, false
case plugin.plugin_name
when "Textfile"
clean_data, extract_seriesname = true, true
when "SerienjunkiesOrgFeed"
clean_data = true
end

extract_seriesname = false if options[:series]

# ask plugin for information
epiname = plugin.generate_episode_information(epi)[0]
next if epiname == nil

puts "[#{plugin.plugin_name}] - #{epiname}"

epi.add_episode_information(epiname, clean_data, extract_seriesname)
next unless epi.episodename.match(/\w+/)

break
end
# configure cleanup
clean_data, extract_seriesname = false, false
case plugin.plugin_name
when "Textfile"
clean_data, extract_seriesname = true, true
when "SerienjunkiesOrgFeed"
clean_data = true
when "SerienjunkiesOrg"
clean_data = true
end

puts ">>> #{epi.to_s}"

print "Filename okay ([jy]/n): "
char = get_character
print char.chr
extract_seriesname = false if options[:series]

unless char.chr.match(/[jy\r]/i)
puts "\nwill be skipped ...\n\n"
next
end
# ask plugin for information
epiname = plugin.generate_episode_information(epi)[0]
next if epiname == nil

info_storage.store(epi) if config[:store_episode_info]
puts "[#{plugin.plugin_name}] - #{epiname}"

puts "\n\n"
epi.add_episode_information(epiname, clean_data, extract_seriesname)
next unless epi.episodename.match(/\w+/)

epi.rename()
break
end
end

puts ">>> #{epi.to_s}"

print "Filename okay ([jy]/n): "
char = get_character
print char.chr

unless char.chr.match(/[jy\r]/i)
puts "\nwill be skipped ...\n\n"
next
end

info_storage.store(epi) if config[:store_episode_info]

puts "\n\n"

epi.rename()
end

rescue Interrupt => e
puts
puts
ensure
info_storage.write() if config[:store_episode_info]
info_storage.write() if config[:store_episode_info]
end
2 changes: 1 addition & 1 deletion lib/plugin/serienjunkies_de.rb
Expand Up @@ -12,7 +12,7 @@ class SerienjunkiesDe < Serienrenamer::Pluginbase
def self.plugin_name; "SerienjunkiesDe" end
def self.plugin_url; "http://serienjunkies.de" end
def self.usable; true end
def self.priority; 4 end
def self.priority; 50 end

# this method will be called from the main program
# with an Serienrenamer::Episode instance as parameter
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/serienjunkies_feed.rb
Expand Up @@ -11,7 +11,7 @@ class SerienjunkiesOrgFeed < Serienrenamer::Pluginbase

def self.plugin_name; "SerienjunkiesOrgFeed" end
def self.usable; true end
def self.priority; 10 end
def self.priority; 80 end

@feed_url = 'http://serienjunkies.org/xml/feeds/episoden.xml'

Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/serienjunkies_org.rb
Expand Up @@ -13,7 +13,7 @@ class SerienjunkiesOrg < Serienrenamer::Pluginbase
def self.plugin_name; "SerienjunkiesOrg" end
def self.plugin_url; "http://serienjunkies.org" end
def self.usable; true end
def self.priority; 10 end
def self.priority; 60 end

# Public: tries to search for an appropriate episodename
#
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/wikipedia.rb
Expand Up @@ -11,7 +11,7 @@ class Wikipedia < Serienrenamer::Pluginbase

def self.plugin_name; "Wikipedia" end
def self.usable; true end
def self.priority; 5 end
def self.priority; 30 end

@@WIKIPEDIA_URL = 'http://de.wikipedia.org/w/api.php'

Expand Down
2 changes: 1 addition & 1 deletion lib/serienrenamer.rb
Expand Up @@ -3,7 +3,7 @@


module Serienrenamer
VERSION = '0.0.9'
VERSION = '0.0.10'

require 'serienrenamer/episode.rb'
require 'serienrenamer/information_store.rb'
Expand Down

0 comments on commit 185ba75

Please sign in to comment.