public
Description: Your friendly neighborhood nzb downloader
Clone URL: git://github.com/maddox/pyrot.git
Search Repo:
Click here to lend your support to: pyrot and make a donation at www.pledgie.com !
maddox (author)
Fri May 09 11:45:43 -0700 2008
commit  10e0bd09fa963635be4fea31ead4dc1132c37b72
tree    04aa8c9e8a985b08c83b49de6a5ab568143bd8da
parent  5bcce78b81508d1ecaf108974af3f9d5c4fc830a
pyrot / lib / tasks / pyrot.rake
100755 168 lines (127 sloc) 5.282 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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