Top Level Namespace

Defined Under Namespace

Modules: ShowRobot

Constant Summary collapse

BASIC_USAGE =

Define various command line option sets here

<<EOS
ShowRobot is a utility for matching media files against
TV and movie databases to categorize your media collection.
EOS
OptionSet =
{}

Instance Method Summary collapse

Instance Method Details

#apply_options(options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/showrobot/cli/options.rb', line 39

def apply_options options={}
	require 'showrobot'

	options.each do |key, value|
		# if the value is nil, skip
		next if not options.include?((key.to_s + '_given').to_sym) or value.nil?

		case key
		when :config_file
			ShowRobot.configure :config_file => options[:config_file]
			ShowRobot.load_config
		when :cache_dir, :tv_database, :movie_database, :verbose
			ShowRobot.configure key, value
		when :no_cache
			ShowRobot.configure :use_cache, false
		when :clear_cache
			puts "Clearing cache in [ #{ShowRobot.config[:cache_dir]} ]" if ShowRobot.config[:verbose]
			File.delete(*Dir[ShowRobot.config[:cache_dir] + '/*.cache'])
		end
	end
end

#identify(media, database, prompt) ⇒ Object

helper function for identifying a file



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/showrobot/cli/identify.rb', line 2

def identify media, database, prompt
	if media.is_movie?

	else
		db = ShowRobot.create_datasource database
		db.mediaFile = media
		
		db.series = if prompt
						select db.series_list, "Select a series for [ #{media.fileName} ]" do |i, item|
							sprintf " %3d) %s", i, item[:name]
						end
					else
						db.series_list.first
					end

		if prompt
			select db.episode_list, "Select an episode for [ #{media.fileName} ]" do |i, item|
				sprintf " %3d) [%02d.%02d] %s", i, item[:season], item[:episode], item[:title]
			end
		else
			db.episode media.season, media.episode
		end
	end
end

#select(list, prompt, &format) ⇒ Object

helper function for prompts



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/showrobot/cli/select.rb', line 2

def select list, prompt, &format
	range = 0...10
	begin
		puts prompt
		range.each do |i|
			puts format.call i, list[i]
		end
		print " > "
		input = $stdin.gets.chomp

		case input
		when /^[\d]+$/
			# it's a number, make sure it's in the range
			selected = list[input.to_i] if input.to_i < list.length
		when 'n' # next range
			range = Range.new(range.end, [range.end + 10, list.length].min, true) if range.end < list.length
		when 'p' # prev range
			range = Range.new([0, range.first - 10].max, range.first, true) if range.first > 1
		when 'q'
			exit
		end
	end while selected.nil?
	selected
end

#translate(str, mapping) ⇒ Object



1
2
3
# File 'lib/showrobot/cli/translate.rb', line 1

def translate str, mapping
	str.gsub(/(?<!\\){[^}]+}/, mapping).gsub(/\\({[^}]+})/, '\1')
end