namespace :pyrot do
desc "Generate Pyrot Daemon Config File"
task :generate_daemon_config => [:environment] do
config = open(File.join(RAILS_ROOT, 'lib', 'pyrot', 'config.xml'), 'w+')
xml = Builder::XmlMarkup.new(:target => config, :indent => 1)
xml.instruct!
xml.tag! 'nzb-config' do
xml.tag! 'thread-count', PYROT_CONFIG['thread_count']
xml.tag! 'bandwidth-limit', PYROT_CONFIG['bandwidth_limit']
xml.tag! 'skip-pars', PYROT_CONFIG['skip_pars']
xml.tag! 'store-by-group', PYROT_CONFIG['store_by_group']
xml.usenet do
xml.host PYROT_CONFIG['usenet']['host']
xml.login PYROT_CONFIG['usenet']['login']
xml.password PYROT_CONFIG['usenet']['password']
end
xml.newzbin do
xml.login PYROT_CONFIG['newzbin']['login']
xml.password PYROT_CONFIG['newzbin']['password']
end
# xml.server do
# xml.port PYROT_CONFIG['server']['port']
# xml.login PYROT_CONFIG['server']['login']
# xml.password PYROT_CONFIG['server']['password']
# end
xml.server do
xml.port 1480
xml.login 'test'
xml.password 'test'
end
xml.group :title => :Movies do
xml.tag! 'save-directory', PYROT_CONFIG['movies']['save_directory']
xml.tag! 'par-repair'
xml.unrar
xml.script do
xml.command File.join(File.dirname(__FILE__), '..', 'pyrot', 'scripts', PYROT_CONFIG['movies']['script'] )
end
end
xml.group :title => :TV do
xml.tag! 'save-directory', PYROT_CONFIG['tv']['save_directory']
xml.tag! 'par-repair'
xml.unrar
xml.script do
xml.command File.join(File.dirname(__FILE__), '..', 'pyrot', 'scripts', PYROT_CONFIG['tv']['script'] )
end
end
end
end
desc "Update Pyrot Ruby lib"
task :update_pyrot_library do
puts "Updating Pyrot Ruby Library"
puts
system "svn export http://code.jtoe.net/ruby/pyrot/pyrot.rb lib/pyrot.rb"
end
desc "Update Imdb Ruby lib"
task :update_imdb_library do
puts "Updating Imdb Ruby Library"
puts
system "svn export http://code.jtoe.net/ruby/imdb/imdb.rb lib/imdb.rb"
end
desc "Update Tvdb Ruby lib"
task :update_tvdb_library do
puts "Updating Tvdb Ruby Library"
puts
system "svn export http://code.jtoe.net/ruby/tvdb/tvdb.rb lib/tvdb.rb"
end
desc "Update Newzbin Ruby lib"
task :update_newzbin_library do
puts "Updating Newzbin Ruby Library"
puts
system "svn export http://code.jtoe.net/ruby/newzbin/newzbin.rb lib/newzbin.rb"
end
desc "Update Pyrot scripts"
task :update_scripts do
puts "Updating Pyrot scripts"
puts
system "svn export --force http://code.jtoe.net/ruby/pyrot_processors lib/pyrot/scripts"
end
desc "Start Pyrot daemon"
task :start => [:generate_daemon_config] do
puts "Starting the Pyrot daemon"
puts
system "nohup java -Djava.awt.headless=true -Dlog4j.configuration=#{File.join(File.dirname(__FILE__), '..', 'pyrot', 'log4j.properties')} -cp #{File.join(File.dirname(__FILE__), '..', '..','lib', 'pyrot', 'pyrot-client.jar')}:. org.monkey.pyrot.client.NzbServer #{File.join(File.dirname(__FILE__), '..', '..','lib', 'pyrot', 'config.xml')} & 2>&1 && echo $! > #{File.join(File.dirname(__FILE__), '..', '..', 'log', 'pyrot.pid')} "
end or raise "Failures"
desc "Stop Pyrot daemon"
task :stop do
puts "Stopping the Pyrot daemon"
puts
pid = File.new(File.join(File.dirname(__FILE__), '..', '..', 'log', 'pyrot.pid'), 'r').readline
system "kill #{pid}"
end or raise "Failures"
desc "Restart Pyrot daemon"
task :restart => [:stop, :start] do
end or raise "Failures"
desc "Check for new episodes of season passes"
task :check_for_new_episodes => [:environment] do
puts "Checking for new episodes"
puts
season_passes = SeasonPass.find(:all, :conditions => ['on_hiatus = 0'])
season_passes.each do |pass|
puts "checking for: #{pass.title} #{pass.season}x#{pass.next_episode}"
series = Series.find(:first, :params => {:title => pass.title} )
if series
episodes = Episode.find(:all, :params => {:series_id => series.id})
episodes.each do |episode|
if episode.episode_number == pass.next_episode && episode.season_number == pass.season
episode.nzbs.each do |nzb|
if nzb.is_hd? == pass.hd?
puts "found it"
# open connection to pyrot and get the nzb xml
newzbin = Newzbin::Connection.new(:username => PYROT_CONFIG['newzbin']['login'], :password => PYROT_CONFIG['newzbin']['password'])
full_nzb = newzbin.get_nzb(nzb.newzbin_id)
# pyrot add episode for downloading
pyrot = Pyrot.new(:url => 'localhost', :path => '/xmlrpc', :port => '1480')
pyrot.add(nzb.title, 'TV', full_nzb)
# update season pass
pass.next_episode += 1
pass.save
break
end
end
end
end
end
end
end
end