junkie 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/junkie/pyload/observer.rb +22 -19
- data/lib/junkie/reactor.rb +8 -4
- data/lib/junkie/version.rb +1 -1
- metadata +1 -1
@@ -17,8 +17,10 @@ module Junkie
|
|
17
17
|
@api = Junkie::Pyload::Api.new
|
18
18
|
|
19
19
|
@ready_for_new_links = true
|
20
|
-
@
|
20
|
+
@watchdog_enabled = false
|
21
21
|
@active_downloads = Hash.new
|
22
|
+
|
23
|
+
@skipped_timer_at_first_complete_detection = false
|
22
24
|
end
|
23
25
|
|
24
26
|
# is a method that is called once from inside the reactor and allows us
|
@@ -28,6 +30,10 @@ module Junkie
|
|
28
30
|
@api.login
|
29
31
|
cleanup
|
30
32
|
}
|
33
|
+
|
34
|
+
EM.add_periodic_timer(@config[:watchdog_refresh]) do
|
35
|
+
monitor_progress if @watchdog_enabled
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
# Adds new episode to Pyload which downloads the episode and extracts it
|
@@ -49,12 +55,7 @@ module Junkie
|
|
49
55
|
|
50
56
|
log.info("Added #{episode} to Pyload, Pid=#{pid}")
|
51
57
|
|
52
|
-
|
53
|
-
if @watchdog.nil?
|
54
|
-
@watchdog = EM::PeriodicTimer.new(@config[:watchdog_refresh]) do
|
55
|
-
monitor_progress
|
56
|
-
end
|
57
|
-
end
|
58
|
+
(@watchdog_enabled = true) unless @watchdog_enabled
|
58
59
|
end
|
59
60
|
|
60
61
|
# checks if the Observer is ready to add new episodes to Pyload
|
@@ -78,7 +79,7 @@ module Junkie
|
|
78
79
|
|
79
80
|
if queue_data.empty?
|
80
81
|
log.info("Empty Pyload queue, I cancel the watchdog timer")
|
81
|
-
|
82
|
+
@watchdog_enabled = false
|
82
83
|
throw :break
|
83
84
|
end
|
84
85
|
|
@@ -95,10 +96,19 @@ module Junkie
|
|
95
96
|
pids = get_complete_downloads(queue_data)
|
96
97
|
|
97
98
|
if not pids.empty?
|
98
|
-
@
|
99
|
-
|
100
|
-
|
101
|
-
|
99
|
+
if @skipped_timer_at_first_complete_detection
|
100
|
+
@api.call(:deletePackages, {pids: pids})
|
101
|
+
log.info("Complete packages are removed from Pyload Queue")
|
102
|
+
@skipped_timer_at_first_complete_detection = false
|
103
|
+
|
104
|
+
@ready_for_new_links = true
|
105
|
+
else
|
106
|
+
# If a package is complete, we are sometimes so fast to remove
|
107
|
+
# it, before the extracting can be started, so we will skip it
|
108
|
+
# the first time
|
109
|
+
log.info("Complete package detected, skip the first time")
|
110
|
+
@skipped_timer_at_first_complete_detection = true
|
111
|
+
end
|
102
112
|
end
|
103
113
|
}
|
104
114
|
}
|
@@ -173,13 +183,6 @@ module Junkie
|
|
173
183
|
end
|
174
184
|
end
|
175
185
|
|
176
|
-
# cancels the watchdog timer
|
177
|
-
def unschedule_watchdog
|
178
|
-
if @watchdog_timer
|
179
|
-
@watchdog_timer.cancel
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
186
|
def cleanup
|
184
187
|
log.debug("Made a cleanup of Pyload's Queue")
|
185
188
|
@api.call(:stopAllDownloads)
|
data/lib/junkie/reactor.rb
CHANGED
@@ -26,8 +26,6 @@ module Junkie
|
|
26
26
|
def initialize
|
27
27
|
@config = Config.get_config(self)
|
28
28
|
|
29
|
-
@sindex = Sindex::SeriesIndex.new(index_file: @config[:series_index_file])
|
30
|
-
@sjunkieex = Sjunkieex::Interface.new(@sindex, @config)
|
31
29
|
@pyload_observer = Junkie::Pyload::Observer.new()
|
32
30
|
|
33
31
|
@episode_queue = EM::Queue.new
|
@@ -41,9 +39,15 @@ module Junkie
|
|
41
39
|
# the episode_queue if they are new
|
42
40
|
@look_for_new_episodes = Proc.new {
|
43
41
|
in_fiber {
|
44
|
-
log.info "Looking for new episodes"
|
45
42
|
|
46
|
-
|
43
|
+
log.debug "Reload Sindex from file"
|
44
|
+
# TODO refactor this so that we can detect if we have to reload the
|
45
|
+
# index (by MD5sum)
|
46
|
+
sindex = Sindex::SeriesIndex.new(index_file: @config[:series_index_file])
|
47
|
+
sjunkieex = Sjunkieex::Interface.new(sindex, @config)
|
48
|
+
|
49
|
+
log.info "Looking for new episodes"
|
50
|
+
sjunkieex.get_links_for_downloads.each do |episode|
|
47
51
|
identifier = "%s@%s" % [episode.id, episode.series]
|
48
52
|
|
49
53
|
if not @found_episodes.has_key? identifier
|
data/lib/junkie/version.rb
CHANGED