Class: Sjunkieex::Interface

Inherits:
Object
  • Object
show all
Includes:
Junkie::Config, Junkie::Log
Defined in:
lib/junkie/patched/sjunkieex.rb

Overview

Monkey-patched version of the Interface from the ‘sjunkieex` gem

Constant Summary collapse

DEFAULT_CONFIG =
{
  :hd_enabled         => false,
  # the first hoster has the highest priority
  :hoster_ids         => ['NOT_AN_HOSTER'],
}

Instance Method Summary collapse

Methods included from Junkie::Log

#log

Methods included from Junkie::Config

collect_default_configs, get_config, included

Instance Method Details

Note:

should be called inside a Ruby fiber

Method that searches for new episodes and returns it in a nice structure

Returns:

  • (Hash)

    series names as keys, data as values



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/junkie/patched/sjunkieex.rb', line 21

def get_links_for_downloads
  @junkie_config ||= Config.get_config(self)

  episodes = []
  look_for_new_episodes.each do |link,series|

    links = parse_series_page(series, link)
    links.each do |identifier, link_data|

      hd = @junkie_config[:hd_enabled]

      # select links, depending on wanted resolution
      links = []
      if hd
          if link_data[:hd_1080p]
              links = link_data[:hd_1080p]
          elsif link_data[:hd_720p]
              links = link_data[:hd_720p]
          end
      else
        (links = link_data[:sd]) if link_data[:sd]
      end

      if links.empty?
          log.info("#{series}(#{identifier}) no links in this resolution")
          next
      end

      # select a link which corresponds to the hoster with the highest
      # possible priority
      selected_link = nil
      catch(:break) {
        @junkie_config[:hoster_ids].each do |hoster|
          links.each do |link|
            if link.match(/\/f-\w+\/#{ hoster }_/)
              selected_link = link
              throw :break
            end
          end
        end
      }

      if selected_link.nil?
          log.warn("#{series}(#{identifier}) no links for any specified hoster")
          next
      end

      episode = Junkie::Episode.new(series, [selected_link], link_data[:episodedata])
      episode.status = :encrypted
      episodes << episode
    end
  end

  episodes

rescue Exception => e
  # an ioerror is mostly raised on a temporary network problem
  log.error("An Exception was raised, I will return empty array of episodes")
  log.error(e)
  return []
end