sjunkieex 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,23 +21,20 @@ module Sjunkieex
21
21
  # Public: Looks for new episodes on the homepage
22
22
  #
23
23
  # Returns a Hash of links for sites that should be visited
24
- def look_for_new_episodes
24
+ def look_for_new_episodes()
25
25
  links = Hash.new
26
26
 
27
27
  doc = Nokogiri::XML(get_page_data(@options[:url]))
28
28
  doc.css("div#content > div.post > div.post-content a").each do |link|
29
- c = link.content
29
+ content = link.content
30
30
 
31
- ####
32
31
  # skip links that are not suitable
33
- next unless is_link_useful?(c)
32
+ next unless is_useful?(content)
34
33
 
35
- next unless @index.is_series_in_index?(c)
34
+ series_name = Sindex::SeriesIndex.extract_seriesname(content)
35
+ language = get_language_from_link_data(content)
36
36
 
37
- series_name = Sindex::SeriesIndex.extract_seriesname(c)
38
- next unless series_name
39
-
40
- next if @index.episode_existing?(series_name, c)
37
+ next if @index.episode_existing?(series_name, content, language)
41
38
 
42
39
  href = link[:href]
43
40
  next if links.include?(href)
@@ -62,11 +59,13 @@ module Sjunkieex
62
59
  doc.css("div#content > div.post div.post-content p").each do |paragraph|
63
60
 
64
61
  next if paragraph[:class]
65
-
66
62
  episode_data = paragraph.css("strong:first-child").text
67
- next unless is_link_useful?(episode_data)
68
63
 
69
- next if @index.episode_existing?(series_name, episode_data)
64
+ next unless is_useful?(episode_data)
65
+
66
+ language = get_language_from_link_data(episode_data)
67
+
68
+ next if @index.episode_existing?(series_name, episode_data, language)
70
69
 
71
70
  if id = Sindex::SeriesIndex.extract_episode_identifier(episode_data)
72
71
 
@@ -98,24 +97,43 @@ module Sjunkieex
98
97
  # link_data - data for the link
99
98
  #
100
99
  # Returns true if the link is useful or false if it can be skipped
101
- def is_link_useful?(link_data)
100
+ def is_useful?(link_data)
102
101
 
103
- return false unless link_data.match(/S\w+E\w+/i)
102
+ return false unless link_data.match(/S\d+E\d+/i)
104
103
 
105
- # skip links depending on language
106
- if @options[:german_only]
107
- return false unless link_data.match(/German/i)
104
+ return false unless @index.is_series_in_index?(link_data)
108
105
 
109
- unless @options[:subbed_allowed]
110
- return false if link_data.match(/Subbed/i)
111
- end
112
- else
113
- return false if link_data.match(/German/i)
106
+ language = get_language_from_link_data(link_data)
107
+ return false if language.nil?
108
+
109
+ series_name = Sindex::SeriesIndex.extract_seriesname(link_data)
110
+
111
+ return false unless
112
+ @index.is_series_in_this_language?(series_name, language)
113
+
114
+ if not @options[:subbed_allowed]
115
+ return false if link_data.match(/Subbed/i)
114
116
  end
115
117
 
116
118
  true
117
119
  end
118
120
 
121
+ # Private: determines the language the link is in
122
+ #
123
+ # data - link data
124
+ #
125
+ # Returns either :de or :en
126
+ def get_language_from_link_data(data)
127
+
128
+ return nil unless data.match(/S\d+E\d+/i)
129
+
130
+ if data.match(/German/i)
131
+ :de
132
+ else
133
+ :en
134
+ end
135
+ end
136
+
119
137
  # Internal: get a page and do some stuff if the page is gzip encoded
120
138
  #
121
139
  # link - the link that is fetched
@@ -1,3 +1,3 @@
1
1
  module Sjunkieex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/sjunkieex.gemspec CHANGED
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_runtime_dependency(%q<nokogiri>, [">= 1.5"])
19
19
  gem.add_runtime_dependency(%q<hashconfig>, [">= 0.0.1"])
20
- gem.add_runtime_dependency(%q<sindex>, [">= 0.1.0"])
20
+ gem.add_runtime_dependency(%q<sindex>, [">= 0.1.1"])
21
21
  end