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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ FileUtils.mkdir(CONFIG_DIR) unless File.directory?(CONFIG_DIR)
### ###
# configuration # configuration
STANDARD_CONFIG = { STANDARD_CONFIG = {
:default_directory => File.join(File.expand_path("~"), "Downloads"), :default_directory => File.join(File.expand_path("~"), "Downloads"),
:store_episode_info => false, :store_episode_info => false,
:store_path => File.join(CONFIG_DIR, "information_storage.yml"), :store_path => File.join(CONFIG_DIR, "information_storage.yml"),
:byte_count_for_md5 => 2048, :byte_count_for_md5 => 2048,
:illegal_words => %w{ ML }, :illegal_words => %w{ ML },
} }


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


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


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


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


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


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


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


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


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


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


Dir.chdir(episode_directory) Dir.chdir(episode_directory)


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


begin begin


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


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


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

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


begin puts "<<< #{entry}"
epi = Serienrenamer::Episode.new(entry)
if options[:series] # if episodename is empty than query plugins
epi.series = options[:series] if epi.episodename.match(/\w+/).nil? || options[:ignore_filenamedata]
end
rescue => e Serienrenamer::Pluginbase.registered_plugins.each do |plugin|
next # 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 end


puts "<<< #{entry}" # configure cleanup

clean_data, extract_seriesname = false, false
# if episodename is empty than query plugins case plugin.plugin_name
if epi.episodename.match(/\w+/).nil? || options[:ignore_filenamedata] when "Textfile"

clean_data, extract_seriesname = true, true
Serienrenamer::Pluginbase.registered_plugins.each do |plugin| when "SerienjunkiesOrgFeed"
# skip plugins that are not feasable clean_data = true
next unless plugin.usable when "SerienjunkiesOrg"
next unless plugin.respond_to?(:generate_episode_information) clean_data = true
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
end end


puts ">>> #{epi.to_s}" extract_seriesname = false if options[:series]

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


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


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 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 rescue Interrupt => e
puts puts
ensure ensure
info_storage.write() if config[:store_episode_info] info_storage.write() if config[:store_episode_info]
end end
2 changes: 1 addition & 1 deletion lib/plugin/serienjunkies_de.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SerienjunkiesDe < Serienrenamer::Pluginbase
def self.plugin_name; "SerienjunkiesDe" end def self.plugin_name; "SerienjunkiesDe" end
def self.plugin_url; "http://serienjunkies.de" end def self.plugin_url; "http://serienjunkies.de" end
def self.usable; true 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 # this method will be called from the main program
# with an Serienrenamer::Episode instance as parameter # with an Serienrenamer::Episode instance as parameter
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin/serienjunkies_feed.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SerienjunkiesOrgFeed < Serienrenamer::Pluginbase


def self.plugin_name; "SerienjunkiesOrgFeed" end def self.plugin_name; "SerienjunkiesOrgFeed" end
def self.usable; true 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' @feed_url = 'http://serienjunkies.org/xml/feeds/episoden.xml'


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


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


def self.plugin_name; "Wikipedia" end def self.plugin_name; "Wikipedia" end
def self.usable; true 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' @@WIKIPEDIA_URL = 'http://de.wikipedia.org/w/api.php'


Expand Down
2 changes: 1 addition & 1 deletion lib/serienrenamer.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@




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


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

0 comments on commit 185ba75

Please sign in to comment.