junkie 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/junkie.rb +1 -0
- data/lib/junkie/reactor.rb +2 -2
- data/lib/junkie/resolver/redirect.rb +67 -0
- data/lib/junkie/version.rb +1 -1
- data/lib/junkie/webinterface/interface.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299b760e5856e465a123191575aa2f0709eafa75
|
4
|
+
data.tar.gz: e364723f5af594b340f312982e4f934af65af0ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982562006b5265fbea20ea56858a374d8dd52b0541df29d99bc1162060081ecc476f06d9c20ad153ea809be6acdc522b4d84c9999c1c3fd814b5ac6f223b3fe1
|
7
|
+
data.tar.gz: 094de64cf493a05b3f99a08cda652a89b0b1e4719d048912bb954684e309f687a94548ed089e56597352dbc8fe33ab7226f4e1acbbbd69ddfc94613d0e9fa68c
|
data/lib/junkie.rb
CHANGED
data/lib/junkie/reactor.rb
CHANGED
@@ -27,7 +27,6 @@ module Junkie
|
|
27
27
|
log.info("Starting Junkie #{Junkie::VERSION}")
|
28
28
|
|
29
29
|
@channels = {
|
30
|
-
encrypted: EM::Channel.new,
|
31
30
|
episodes: EM::Channel.new,
|
32
31
|
notifications: EM::Channel.new,
|
33
32
|
info: EM::Channel.new,
|
@@ -39,6 +38,7 @@ module Junkie
|
|
39
38
|
@twitter_notification = Junkie::Notification::Twitter.new(@channels)
|
40
39
|
@dumper = Junkie::Notification::Dumper.new(@channels)
|
41
40
|
@push_endpoint = Junkie::Push::Endpoint.new(@channels)
|
41
|
+
@redirect_resolver = Junkie::Resolver::RedirectResolver.new(@channels)
|
42
42
|
|
43
43
|
@found_episodes = Hash.new
|
44
44
|
build_procs # has to be called here
|
@@ -102,7 +102,7 @@ module Junkie
|
|
102
102
|
if not @found_episodes.has_key? identifier
|
103
103
|
log.info("Found new episode '#{episode}'")
|
104
104
|
|
105
|
-
@channels[:
|
105
|
+
@channels[:episodes].push(episode)
|
106
106
|
@found_episodes[identifier] = episode
|
107
107
|
end
|
108
108
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'em-http'
|
2
|
+
|
3
|
+
module Junkie
|
4
|
+
module Resolver
|
5
|
+
|
6
|
+
class RedirectResolver
|
7
|
+
include Log, Config
|
8
|
+
|
9
|
+
DEFAULT_CONFIG = {
|
10
|
+
uri_patterns: [
|
11
|
+
'http://download.serienjunkies.org/go-'
|
12
|
+
],
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(channels)
|
16
|
+
@channels = channels
|
17
|
+
@patterns = Config.get_config(self)[:uri_patterns]
|
18
|
+
|
19
|
+
channels[:episodes].subscribe do |episode|
|
20
|
+
next unless episode.status == :decrypted
|
21
|
+
|
22
|
+
resolve_links(episode)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# resolve links that matches any pattern by issuing a HEAD request and
|
27
|
+
# using the Location response header instead of the original supplied header
|
28
|
+
def resolve_links(episode)
|
29
|
+
multi = EventMachine::MultiRequest.new
|
30
|
+
request_count = 0
|
31
|
+
|
32
|
+
episode.links.each_with_index do |link, index|
|
33
|
+
next unless @patterns.index { |p| link.include?(p) }
|
34
|
+
|
35
|
+
request_count += 1
|
36
|
+
multi.add(index, EventMachine::HttpRequest.new(link).head)
|
37
|
+
end
|
38
|
+
|
39
|
+
if request_count == 0
|
40
|
+
send_episode(episode)
|
41
|
+
else
|
42
|
+
multi.callback do
|
43
|
+
links = episode.links.clone
|
44
|
+
|
45
|
+
responses = multi.responses[:callback]
|
46
|
+
responses.each do |index, value|
|
47
|
+
location = value.response_header.fetch("LOCATION") { nil }
|
48
|
+
|
49
|
+
unless location.nil?
|
50
|
+
links[index] = location
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
episode.links = links
|
55
|
+
send_episode(episode)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def send_episode(episode)
|
61
|
+
episode.status = :resolved
|
62
|
+
@channels[:episodes].push(episode)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/junkie/version.rb
CHANGED
@@ -39,7 +39,9 @@ module Junkie
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# get new encrypted episode links
|
42
|
-
@@channels[:
|
42
|
+
@@channels[:episodes].subscribe do |episode|
|
43
|
+
next unless episode.status == :encrypted
|
44
|
+
|
43
45
|
@@encrypted_episodes[episode.uuid] = episode
|
44
46
|
publish_encrypted_count
|
45
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: junkie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Böhm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -222,6 +222,7 @@ files:
|
|
222
222
|
- lib/junkie/pyload/api.rb
|
223
223
|
- lib/junkie/pyload/observer.rb
|
224
224
|
- lib/junkie/reactor.rb
|
225
|
+
- lib/junkie/resolver/redirect.rb
|
225
226
|
- lib/junkie/version.rb
|
226
227
|
- lib/junkie/webinterface/interface.rb
|
227
228
|
- lib/junkie/webinterface/public/js/index.js
|