junkie 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,6 +43,8 @@ module Junkie
43
43
  in_fiber {
44
44
  @api.login
45
45
  cleanup
46
+ stat_queued_episodes
47
+ stat_current_download
46
48
  }
47
49
 
48
50
  EM.add_periodic_timer(@config[:watchdog_refresh]) do
@@ -65,6 +67,7 @@ module Junkie
65
67
 
66
68
  @active_episode = @found_episodes.shift
67
69
  episode = @active_episode
70
+ stat_queued_episodes
68
71
 
69
72
  @ready_for_new_links = false
70
73
  episode.status = :downloading
@@ -82,6 +85,27 @@ module Junkie
82
85
  end
83
86
 
84
87
 
88
+ # sends the current number of queued episodes out on the info channel
89
+ def stat_queued_episodes
90
+ @channels[:info].push({
91
+ key: "Pending episodes",
92
+ desc: "Number of episodes queued for download",
93
+ value: @found_episodes.size
94
+ })
95
+ end
96
+
97
+
98
+ # send the info about the current active download out on the
99
+ # info channel
100
+ def stat_current_download(complete=nil)
101
+ @channels[:info].push({
102
+ key: "Current active download",
103
+ desc: @active_episode ? @active_episode.to_s : "No active download",
104
+ value: complete ? "#{complete} %" : "-",
105
+ })
106
+ end
107
+
108
+
85
109
  # checks if the Observer is ready to add new episodes to Pyload
86
110
  #
87
111
  # @returns [Boolean] true if new links can be added
@@ -121,6 +145,8 @@ module Junkie
121
145
  # check for empty queue and disable watchdog if needed
122
146
  check_for_empty_queue(queue_data)
123
147
 
148
+ stat_current_download(get_complete_percentage(queue_data))
149
+
124
150
  # extract package IDs and map them to current downloads
125
151
  update_package_ids(queue_data)
126
152
 
@@ -207,6 +233,7 @@ module Junkie
207
233
  log.info("Sending complete episode out on the channel")
208
234
  @channels[:episodes].push(@active_episode)
209
235
  @active_episode = nil
236
+ stat_current_download
210
237
  end
211
238
 
212
239
  # remove all complete packages
@@ -226,6 +253,26 @@ module Junkie
226
253
  end
227
254
 
228
255
 
256
+ # get the percentage of completeness
257
+ #
258
+ # @param [Array] queue_data returned from :getQueueData api method
259
+ #
260
+ # @return [int] percentage of current download or nil
261
+ def get_complete_percentage(queue_data)
262
+ pids = []
263
+ queue_data.each do |package|
264
+ begin
265
+ sizetotal = package['sizetotal'].to_i
266
+ sizedone = package['sizedone'].to_i
267
+
268
+ return (sizedone * 100) / sizetotal
269
+ rescue Exception => e
270
+ end
271
+ end
272
+ nil
273
+ end
274
+
275
+
229
276
  # Looks for complete downloads and returns their pids
230
277
  #
231
278
  # @param [Array] queue_data returned from :getQueueData api method
@@ -1,3 +1,3 @@
1
1
  module Junkie
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junkie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine