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 09:44:44 -0700 2008
commit  0a131f384f35df7fb8999da8c65db1b99a04abf9
tree    296a67a076629980f5e717202e0c704bc3b9be53
parent  34d9623b7574e0ee22621bbbc667c3ba9dbda313 parent  5bcce78b81508d1ecaf108974af3f9d5c4fc830a
pyrot / app / helpers / application_helper.rb
100644 184 lines (139 sloc) 5.544 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
 
  # Request from an iPhone or iPod touch? (Mobile Safari user agent)
  def iphone_user_agent?
    request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Mobile\/.+Safari)/]
  end
 
  def time_ago_in_words_short(time)
    time_ago = time_ago_in_words(time)
    time_ago = time_ago.gsub(/about /, '')
    time_ago = time_ago.gsub(/minutes/, 'mins')
    time_ago = time_ago.gsub(/hours/, 'hrs')
    time_ago = time_ago.gsub(/seconds/, 'secs')
  end
  
  def download_status(download)
    
    case download.status
    when "downloading"
      "#{bytes_complete(download)}"
    when "complete"
      "Download Complete"
    when "queued"
      "#{bytes_complete(download)} - Queued"
    when "paused"
      "#{bytes_complete(download)} - Paused"
    when "pausing"
      "#{bytes_complete(download)} - Pausing"
    when "unrar"
      "#{bytes_complete(download)} - Unraring"
    when "par_repair"
      "#{bytes_complete(download)} - Repairing"
    when "mp3_rename"
      "#{bytes_complete(download)} - Retagging"
    when "avimerge"
      "#{bytes_complete(download)} - Merging video files"
    when "error"
      "#{bytes_complete(download)} - Error"
    end
 
  end
  
  def time_remaining(download)
    case download.status
    when "downloading"
      case @pyrot.speed_in_bytes
      when 0
        time_left = "Something is wrong"
      else
        time_left = "#{((download.bytes_left/@pyrot.speed_in_bytes)/(60)).to_i} mins remaining"
      end
      time_left
    end
    
  end
 
 
  def download_buttons(download)
   output = []
 
    case download.status
    when "downloading"
     output << link_to_remote('pause', {:url => pause_download_path(download.title), :method => :get}, {:class => 'pause_button'})
     output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
    when "complete"
     output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
    when "error"
     output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
    when "paused"
     output << link_to_remote('resume', {:url => resume_download_path(download.title), :method => :get}, {:class => 'resume_button'})
     output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
    when "queued"
     output << link_to_remote('remove', {:url => remove_download_path(download.title), :method => :get}, {:class => 'remove_button'})
    end
 
   output.join
    
  end
 
 
  def bytes_complete(download)
    "#{download.completed_bytes.to_mb} MB of #{download.total_bytes.to_mb} MB (#{download.percent_complete}%)"
  end
  
  
  
  def search_button
    %{<a class="button" href="#" onclick="$('search_dialog').show(); return false;">Search</a>}
  end
  
  
  def content_for_iphone_title_bar(&block)
    
    html = %{<div class="title_bar">}
    html << capture(&block)
    html << %{</div>}
    
    concat(html, block)
    
  end
  
  def newzbin_format_options
    options_for_select([["Format", "1073741824"],["x264", "131072"],["H.264", "2048"],["XviD", "16"],["iPod", "512"],["DVD", "2"],["PSP", "1024"],["DivX", "1"]])
  end
  
  
  def newzbin_format_select_tag
    select_tag "ps_rb_video_format", newzbin_format_options
  end
 
  def newzbin_source_options
    options_for_select([["Source", "1073741824"], ["HD-DVD", "512"], ["Blu-ray", "2048"], ["DVD", "64"], ["TV Cap", "256"], ["HDTV", "128"]])
  end
  
  
  def newzbin_source_select_tag
    select_tag "ps_rb_source", newzbin_source_options
  end
 
  def newzbin_category_options
    options_for_select([["Category", "-1"], ["Movies", "6"], ["TV", "8"]])
  end
  
  
  def newzbin_category_select_tag
    select_tag "category", newzbin_category_options
  end
 
 
  def newzbin_genre_options
    options_for_select([["Genre", "1073741824"], ["Action/Adv", "1"], ["Animation", "2"], ["Children", "131072"], ["Comedy", "4"], ["Documentary", "8"], ["Drama", "16"], ["Family", "8192"], ["Fantasy", "2048"], ["Horror", "512"], ["Musical", "16384"], ["SciFi", "32"], ["Sitcom", "64"], ["Sport", "128"], ["Reality", "256"], ["Romance", "1024"], ["Thriller", "4096"], ["War", "65536"], ["Western", "32768"]])
  end
  
  
  def newzbin_genre_select_tag
    select_tag "ps_rb_video_genre", newzbin_genre_options
  end
 
 
  def pagination_links(page)
    output = "<h2>"
    
    output << link_to( "<= Previous", group_nzbs_path(@group, :page => page.to_i - 1)) if page && page.to_i > 1
    output << link_to( "More =>", group_nzbs_path(@group, :page => page == nil ? 2 : page.to_i + 1))
    output << "</h2>"
  end
  
  def decide_partial(category)
    case category
    when "movies"
      "movies/movie"
    when "tv"
      "movies/episode"
    end
  end
 
  def meta_decide_partial(category)
    case category
    when "movies"
      "movies/big_movie"
    when "tv"
      "movies/big_episode"
    end
  end
  
  def determine_season_pass_link(series)
    season_passes = SeasonPass.find(:all)
    found_pass = nil
    season_passes.each do |pass|
      found_pass = pass if pass.title =~ /#{series.title}/i
    end
 
    case found_pass
    when nil
      link_to 'Season Pass', new_season_pass_path(:title => series.title)
    else
      link_to 'Season Pass', edit_season_pass_path(found_pass)
    end
 
  end
 
  
end