junkie 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/junkie/resolver/redirect.rb +19 -24
- data/lib/junkie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 728c1f06bb30b73b2560183c18be33eac3ec38df
|
4
|
+
data.tar.gz: 2347ce511acf6f802a14ed434c002205eb7ac539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea56196f84c2276994100080b7bc7843d34f502a0f904040da3f6e9720576735f15f6ede249fb056fa29d6050a0a093c172cc52256771ae9256b4c6141ce9d81
|
7
|
+
data.tar.gz: 21a931fb9ddd8d0267850db69da03416024d7bb391a53d1a0e98811a50a2924a85ec9899591c0ae4c2ac707ee71841f209a38da4265a38ad8e6e925c2dce9dc0
|
@@ -23,41 +23,36 @@ module Junkie
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def is_resolvable(link)
|
27
|
+
@patterns.index { |p| link.include?(p) }
|
28
|
+
end
|
29
|
+
|
26
30
|
# resolve links that matches any pattern by issuing a HEAD request and
|
27
31
|
# using the Location response header instead of the original supplied header
|
28
32
|
def resolve_links(episode)
|
29
|
-
|
30
|
-
|
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
|
33
|
+
resolvable, resolved = episode.links.partition { |link| is_resolvable(link) }
|
34
|
+
episode.links = resolved
|
38
35
|
|
39
|
-
if
|
36
|
+
if resolvable.empty?
|
40
37
|
send_episode(episode)
|
41
38
|
else
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
episode.links = links
|
39
|
+
EM::Iterator.new(resolvable, 2).map( proc { |url, iter|
|
40
|
+
res = EventMachine::HttpRequest.new(url).head
|
41
|
+
res.callback {
|
42
|
+
iter.return(res.response_header.fetch("LOCATION") { nil })
|
43
|
+
}
|
44
|
+
res.errback {
|
45
|
+
iter.return(nil)
|
46
|
+
}
|
47
|
+
}, proc { |links|
|
48
|
+
episode.links += links.select {|l| !l.nil? }
|
55
49
|
send_episode(episode)
|
56
|
-
|
50
|
+
})
|
57
51
|
end
|
58
52
|
end
|
59
53
|
|
60
54
|
def send_episode(episode)
|
55
|
+
log.debug('Resolved links: ' + episode.links.to_s)
|
61
56
|
episode.status = :resolved
|
62
57
|
@channels[:episodes].push(episode)
|
63
58
|
end
|
data/lib/junkie/version.rb
CHANGED
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.3
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|