junkie 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,23 +5,30 @@ require 'sjunkieex'
|
|
5
5
|
|
6
6
|
module Junkie
|
7
7
|
|
8
|
-
#
|
8
|
+
# Monkey-patched version of the Interface from the `sjunkieex` gem
|
9
9
|
class ::Sjunkieex::Interface
|
10
|
-
include Junkie::Log
|
10
|
+
include Junkie::Log, Junkie::Config
|
11
11
|
|
12
|
+
DEFAULT_CONFIG = {
|
13
|
+
:hd_enabled => false,
|
14
|
+
# the first hoster has the highest priority
|
15
|
+
:hoster_ids => ['NOT_AN_HOSTER'],
|
16
|
+
}
|
12
17
|
|
13
18
|
# Method that searches for new episodes and returns it in a nice structure
|
14
19
|
#
|
15
20
|
# @note should be called inside a Ruby fiber
|
16
21
|
# @return [Hash] series names as keys, data as values
|
17
22
|
def get_links_for_downloads
|
23
|
+
@junkie_config ||= Config.get_config(self)
|
24
|
+
|
18
25
|
episodes = []
|
19
26
|
look_for_new_episodes.each do |link,series|
|
20
27
|
|
21
28
|
links = parse_series_page(series, link)
|
22
29
|
links.each do |identifier, link_data|
|
23
30
|
|
24
|
-
hd = @
|
31
|
+
hd = @junkie_config[:hd_enabled]
|
25
32
|
|
26
33
|
# select links, depending on wanted resolution
|
27
34
|
links = []
|
@@ -40,17 +47,27 @@ module Junkie
|
|
40
47
|
next
|
41
48
|
end
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
# select a link which corresponds to the hoster with the highest
|
51
|
+
# possible priority
|
52
|
+
selected_link = nil
|
53
|
+
catch(:break) {
|
54
|
+
@junkie_config[:hoster_ids].each do |hoster|
|
55
|
+
links.each do |link|
|
56
|
+
if link.match(/\/f-\w+\/#{ hoster }_/)
|
57
|
+
selected_link = link
|
58
|
+
throw :break
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
}
|
46
63
|
|
47
|
-
if
|
48
|
-
|
64
|
+
if selected_link.nil?
|
65
|
+
log.warn("#{series}(#{identifier}) no links for any specified hoster")
|
49
66
|
next
|
50
67
|
end
|
51
68
|
|
52
69
|
episode = Junkie::Episode.new(
|
53
|
-
series,
|
70
|
+
series, selected_link, link_data[:episodedata])
|
54
71
|
episodes << episode
|
55
72
|
end
|
56
73
|
end
|
@@ -68,18 +85,18 @@ module Junkie
|
|
68
85
|
|
69
86
|
def get_page_data(link)
|
70
87
|
f = Fiber.current
|
71
|
-
|
88
|
+
http = EventMachine::HttpRequest.new(link).get :timeout => 10
|
72
89
|
|
73
|
-
|
74
|
-
|
90
|
+
http.callback { f.resume(http) }
|
91
|
+
http.errback { f.resume(http) }
|
75
92
|
|
76
|
-
|
93
|
+
Fiber.yield
|
77
94
|
|
78
|
-
|
79
|
-
|
80
|
-
|
95
|
+
if http.error
|
96
|
+
raise IOError, http.error
|
97
|
+
end
|
81
98
|
|
82
|
-
|
99
|
+
http.response
|
83
100
|
end
|
84
101
|
end
|
85
102
|
end
|
data/lib/junkie/reactor.rb
CHANGED
@@ -16,8 +16,6 @@ module Junkie
|
|
16
16
|
include Log, Helper, Config
|
17
17
|
|
18
18
|
DEFAULT_CONFIG = {
|
19
|
-
:hd_enabled => false,
|
20
|
-
:hoster_id => "ul",
|
21
19
|
:series_index_file => File.join(Dir.home, '.sindex/seriesindex.xml'),
|
22
20
|
:episode_search_refresh => 15, # in minutes
|
23
21
|
}
|
@@ -52,7 +50,7 @@ module Junkie
|
|
52
50
|
# TODO refactor this so that we can detect if we have to reload the
|
53
51
|
# index (by MD5sum)
|
54
52
|
sindex = Sindex::SeriesIndex.new(index_file: @config[:series_index_file])
|
55
|
-
sjunkieex = Sjunkieex::Interface.new(sindex
|
53
|
+
sjunkieex = Sjunkieex::Interface.new(sindex)
|
56
54
|
|
57
55
|
log.info "Looking for new episodes"
|
58
56
|
sjunkieex.get_links_for_downloads.each do |episode|
|
data/lib/junkie/version.rb
CHANGED
@@ -30,7 +30,8 @@
|
|
30
30
|
|
31
31
|
<li data-role="list-divider">About</li>
|
32
32
|
<li>Stats Last Updated At<span class="ui-li-count bigger" id="last_update"></span></li>
|
33
|
-
<li>Junkie Host<span class="ui-li-count bigger"
|
33
|
+
<li>Junkie Host<span class="ui-li-count bigger"><%= @server %></span></li>
|
34
|
+
<li>Connection Status<span class="ui-li-count bigger" id="connection_status">disconnected</span></li>
|
34
35
|
</ul>
|
35
36
|
</div>
|
36
37
|
</div>
|
@@ -60,8 +61,14 @@
|
|
60
61
|
|
61
62
|
$(function () {
|
62
63
|
var ws = new WebSocket('ws://' + window.location.host + window.location.pathname);
|
63
|
-
ws.onopen = function() {
|
64
|
-
|
64
|
+
ws.onopen = function() {
|
65
|
+
console.log('websocket opened');
|
66
|
+
$('#connection_status').text('connected');
|
67
|
+
};
|
68
|
+
ws.onclose = function() {
|
69
|
+
console.log('websocket closed');
|
70
|
+
$('#connection_status').text('disconnected');
|
71
|
+
};
|
65
72
|
ws.onmessage = function(m) {
|
66
73
|
updateUpdatedAt();
|
67
74
|
var obj = $.parseJSON(m.data);
|
@@ -14,7 +14,7 @@ describe Junkie::Pyload::Observer do
|
|
14
14
|
stub_const("Junkie::CONFIG_FILE", '/dev/null')
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:channels) { {episodes: EM::Channel.new} }
|
17
|
+
let(:channels) { {episodes: EM::Channel.new, info: EM::Channel.new} }
|
18
18
|
let(:epi_channel) { channels[:episodes]}
|
19
19
|
let(:episode) do
|
20
20
|
epi = Junkie::Episode.new( "One Tree Hill", "http://local.host/12345",
|
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.
|
4
|
+
version: 0.0.11
|
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-
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|