Permalink
Browse files

Hack changes to use idtest - still a hack

  • Loading branch information...
1 parent 44fecdc commit 70eb139bd3d2e5c79d5d90af17859ec583a46a1b @jacobwgillespie committed Sep 5, 2012
Showing with 126 additions and 19 deletions.
  1. +6 −0 idtest/Gemfile
  2. +21 −0 idtest/Gemfile.lock
  3. +79 −9 idtest/process.rb
  4. +2 −2 idtest/renamer/files.rb
  5. +15 −6 idtest/renamer/matcher.rb
  6. +3 −2 idtest/renamer/season.rb
View
@@ -0,0 +1,6 @@
+source :rubygems
+
+gem 'httparty', '=0.8.2'
+gem 'tvdb_party'
+gem 'highline', :require => 'highline/import'
+gem 'romans'
View
@@ -0,0 +1,21 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ highline (1.6.14)
+ httparty (0.8.2)
+ multi_json
+ multi_xml
+ multi_json (1.3.6)
+ multi_xml (0.5.1)
+ romans (0.1.0)
+ tvdb_party (0.6.2)
+ httparty (>= 0.6.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ highline
+ httparty (= 0.8.2)
+ romans
+ tvdb_party
View
@@ -2,12 +2,13 @@
$:.unshift File.dirname(__FILE__)
-require 'rubygems'
-require 'highline/import'
+
+require "rubygems"
+require "bundler/setup"
+Bundler.require(:default)
+
require 'fileutils'
-require 'tvdb_party'
require 'pp'
-require 'romans'
require 'renamer/constants'
require 'renamer/util'
@@ -16,6 +17,65 @@
require 'renamer/matcher'
+class Object
+ # Invokes the method identified by the symbol +method+, passing it any arguments
+ # and/or the block specified, just like the regular Ruby <tt>Object#send</tt> does.
+ #
+ # *Unlike* that method however, a +NoMethodError+ exception will *not* be raised
+ # and +nil+ will be returned instead, if the receiving object is a +nil+ object or NilClass.
+ #
+ # If try is called without a method to call, it will yield any given block with the object.
+ #
+ # Please also note that +try+ is defined on +Object+, therefore it won't work with
+ # subclasses of +BasicObject+. For example, using try with +SimpleDelegator+ will
+ # delegate +try+ to target instead of calling it on delegator itself.
+ #
+ # ==== Examples
+ #
+ # Without +try+
+ # @person && @person.name
+ # or
+ # @person ? @person.name : nil
+ #
+ # With +try+
+ # @person.try(:name)
+ #
+ # +try+ also accepts arguments and/or a block, for the method it is trying
+ # Person.try(:find, 1)
+ # @people.try(:collect) {|p| p.name}
+ #
+ # Without a method argument try will yield to the block unless the receiver is nil.
+ # @person.try { |p| "#{p.first_name} #{p.last_name}" }
+ #--
+ # +try+ behaves like +Object#send+, unless called on +NilClass+.
+ def try(*a, &b)
+ if a.empty? && block_given?
+ yield self
+ else
+ __send__(*a, &b)
+ end
+ end
+end
+
+class NilClass
+ # Calling +try+ on +nil+ always returns +nil+.
+ # It becomes specially helpful when navigating through associations that may return +nil+.
+ #
+ # === Examples
+ #
+ # nil.try(:name) # => nil
+ #
+ # Without +try+
+ # @person && !@person.children.blank? && @person.children.first.name
+ #
+ # With +try+
+ # @person.try(:children).try(:first).try(:name)
+ def try(*args)
+ nil
+ end
+end
+
+
EXTS = %w(avi mpeg xvid mp4 m4v mkv wmv mpg)
QUALITIES = [
@@ -91,15 +151,15 @@ def dups_with_count array
end
-show_id = 75886
+show_id = 73630
season_number = 1
-season = Renamer::Season.new show_id, season_number
+season = Renamer::Season.new(show_id, season_number)
season.episodes.each do |episode|
-# puts "#{episode[:name]} is episode #{episode[:number]}"
-# puts "If there were parts, it would be episode #{episode[:part_number]} part #{episode[:part_letter]}"
+ puts "#{episode[:name]} is episode #{episode[:number]}"
+ puts "If there were parts, it would be episode #{episode[:part_number]} part #{episode[:part_letter]}"
-# puts
+ puts
end
files_class = Renamer::Files.new('.')
@@ -113,6 +173,8 @@ def dups_with_count array
matcher = Renamer::Matcher.new files_class, season
matcher.match
+#pp matcher.files
+
counter = 0
matcher.episode_slots.each do |slot, episodes|
@@ -125,6 +187,14 @@ def dups_with_count array
puts
counter += 1
end
+
+counter = 0
+matcher.episode_slots.each do |slot, episodes|
+ episodes.each do |file|
+ puts "mv \"#{file[:name]}\" \"#{slot} - #{season.episodes[counter][:name]}.avi\""
+ end
+ counter += 1
+end
#pp files_class.files
=begin
View
@@ -104,7 +104,7 @@ def process
if parts_plus_numbers.first[:guess_episode].to_i <= @known_episodes.length
@files[index][:guessed_filename_episode] = parts_plus_numbers.first[:guess_episode].to_i
- @files[index][:guessed_filename_part] = parts_plus_numbers.first[:guess_part].nil? ? nil : parts_plus_numbers.first[:guess_part].downcase
+ @files[index][:guessed_filename_part] = parts_plus_numbers.first[:guess_part].try(:downcase)
else
@files[index][:guessed_filename_episode] = -1
@files[index][:guessed_filename_part] = nil
@@ -130,7 +130,7 @@ def find_numbers string
guess_three = string.scan /S(\d{1,2})/i
# Format: 001
- guess_four = string.scan /(\d{2,3})([a-z])?/i
+ guess_four = string.scan /(\d{2,3})([a-e])?/i
[guess_one, guess_two, guess_three, guess_four]
View
@@ -23,17 +23,26 @@ def match
@episode_slots = Hash.new { |hash, key| hash[key] = [] }
@season.episodes.each do |episode|
- @episode_slots["#{episode[:part_number]}#{episode[:part_letter]}"] if @files_class.use_alternate_naming
- @episode_slots["#{episode[:number]}"] unless @files_class.use_alternate_naming
+ puts episode
+ if @files_class.use_alternate_naming
+ @episode_slots["S#{episode[:season_number]}E#{episode[:part_number]}#{episode[:part_letter]}"]
+ else
+ @episode_slots["S#{episode[:season_number]}E#{episode[:number]}"]
+ end
end
@files.each do |file|
if @files_class.use_alternate_naming
- @episode_slots["#{file[:guessed_episode][:part_number]}#{file[:guessed_episode][:part_letter]}"] << file if file[:guessed_filename_episode] == -1
- @episode_slots["#{file[:guessed_filename_episode]}#{file[:guessed_filename_part] || 'a'}"] << file unless file[:guessed_filename_episode] == -1
+ @episode_slots["S#{file[:guessed_episode][:season_number]}E#{file[:guessed_episode][:part_number]}#{file[:guessed_episode][:part_letter]}"] << file if file[:guessed_filename_episode] == -1
+ # TODO: add season to next line
+ #@episode_slots["#{file[:guessed_filename_episode]}#{file[:guessed_filename_part] || 'a'}"] << file unless file[:guessed_filename_episode] == -1
else
- @episode_slots["#{file[:guessed_episode][:number]}"] << file if file[:guessed_filename_episode] == -1
- @episode_slots["#{file[:guessed_filename_episode]}"] << file unless file[:guessed_filename_episode] == -1
+ if file[:guessed_filename_episode] == -1 or true
+ @episode_slots["S#{file[:guessed_episode][:season_number]}E#{file[:guessed_episode][:number]}"] << file
+ else
+ # TODO: add season to next line
+ #@episode_slots["#{file[:guessed_filename_episode]}"] << file
+ end
end
end
View
@@ -9,7 +9,7 @@ def initialize tvdb_id, season_number
@tvdb = TvdbParty::Search.new(ENV['TVDB_KEY'])
puts "Loading show information..."
@show = tvdb.get_series_by_id(@tvdb_id)
- @episodes = show.episodes.reject { |e| e.season_number.to_i != @season_number }
+ @episodes = show.episodes #.reject { |e| e.season_number.to_i != @season_number }
puts "Loaded"
@episodes = @episodes.to_a.map do |episode|
@@ -21,7 +21,8 @@ def initialize tvdb_id, season_number
:number => episode.number.to_i,
:overview => episode.overview,
:air_date => episode.air_date,
- :id => episode.id.to_i
+ :id => episode.id.to_i,
+ :season_number => episode.season_number.to_i
}
end

0 comments on commit 70eb139

Please sign in to comment.