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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e94bc9ed0a6752f3ab21177d2e301e603c5b164
4
- data.tar.gz: 223dfd25c8f29d346f19f8faf35dbde831b03ae1
3
+ metadata.gz: 299b760e5856e465a123191575aa2f0709eafa75
4
+ data.tar.gz: e364723f5af594b340f312982e4f934af65af0ef
5
5
  SHA512:
6
- metadata.gz: bf1971e2ca25e9d06797df7dc90882d31cc05b1a242d89141ce10086d21d5dd65be93fcd6b485c4ec9715206aa8448e86cdd875cc877083a086ad95271ff2ce1
7
- data.tar.gz: 8c98fb1bc9f4e8c5955c1593e3b143f5e5596df1a0ca2d60752fe8191e3a182bc240c76f214b252772b1b3ba8dd71537ea2061a0f3b3e37cd6ffbe6646159f99
6
+ metadata.gz: 982562006b5265fbea20ea56858a374d8dd52b0541df29d99bc1162060081ecc476f06d9c20ad153ea809be6acdc522b4d84c9999c1c3fd814b5ac6f223b3fe1
7
+ data.tar.gz: 094de64cf493a05b3f99a08cda652a89b0b1e4719d048912bb954684e309f687a94548ed089e56597352dbc8fe33ab7226f4e1acbbbd69ddfc94613d0e9fa68c
data/lib/junkie.rb CHANGED
@@ -7,6 +7,7 @@ require 'junkie/errors'
7
7
  require 'junkie/helper'
8
8
  require 'junkie/patched/sjunkieex'
9
9
  require 'junkie/push/endpoint'
10
+ require 'junkie/resolver/redirect'
10
11
  require 'junkie/pyload/api'
11
12
  require 'junkie/pyload/observer'
12
13
  require 'junkie/notification/twitter'
@@ -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[:encrypted].push(episode)
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
@@ -1,3 +1,3 @@
1
1
  module Junkie
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -39,7 +39,9 @@ module Junkie
39
39
  end
40
40
 
41
41
  # get new encrypted episode links
42
- @@channels[:encrypted].subscribe do |episode|
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.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-13 00:00:00.000000000 Z
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