junkie 0.0.10 → 0.0.11

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.
@@ -5,23 +5,30 @@ require 'sjunkieex'
5
5
 
6
6
  module Junkie
7
7
 
8
- # Monkex-patched version of the Interface from the `sjunkieex` gem
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 = @options[:hd_enabled]
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
- download_links = links.select do |link|
44
- link.match(/\/f-\w+\/#{ @options[:hoster_id] }_/)
45
- end
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 download_links.empty?
48
- puts "there are no links for this hoster"
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, download_links.first, link_data[:episodedata])
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
- http = EventMachine::HttpRequest.new(link).get :timeout => 10
88
+ http = EventMachine::HttpRequest.new(link).get :timeout => 10
72
89
 
73
- http.callback { f.resume(http) }
74
- http.errback { f.resume(http) }
90
+ http.callback { f.resume(http) }
91
+ http.errback { f.resume(http) }
75
92
 
76
- Fiber.yield
93
+ Fiber.yield
77
94
 
78
- if http.error
79
- raise IOError, http.error
80
- end
95
+ if http.error
96
+ raise IOError, http.error
97
+ end
81
98
 
82
- http.response
99
+ http.response
83
100
  end
84
101
  end
85
102
  end
@@ -33,6 +33,7 @@ module Junkie
33
33
 
34
34
  log.info("Got episode from Channel: #{episode}")
35
35
  @found_episodes.push(episode)
36
+ stat_queued_episodes
36
37
  end
37
38
  end
38
39
 
@@ -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, @config)
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|
@@ -1,3 +1,3 @@
1
1
  module Junkie
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -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" id="last_update"><%= @server %></span></li>
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() { console.log('websocket opened'); };
64
- ws.onclose = function() { console.log('websocket closed'); };
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.10
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-23 00:00:00.000000000 Z
12
+ date: 2012-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine