sindex 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,13 +22,21 @@ module Sindex
22
22
  # :filename - the filename to the episode
23
23
  # :language - language in which the episode was watched :de/:en
24
24
  #
25
- def add_episode(filename, language=:de)
25
+ def add_episode(filename, language=:de, all_before=false)
26
26
  if id = SeriesIndex.extract_episode_identifier(filename)
27
27
 
28
28
  if @episodes[language].nil?
29
29
  @episodes[language] = {}
30
30
  end
31
31
 
32
+ # mark all previous episodes as watched if `all_before`
33
+ if all_before
34
+ ids = build_up_ids_before_another_id(id)
35
+ for virtual_id in ids
36
+ @episodes[language][virtual_id] = :virtual
37
+ end
38
+ end
39
+
32
40
  @episodes[language][id] = filename
33
41
  end
34
42
  end
@@ -52,5 +60,33 @@ module Sindex
52
60
  false
53
61
  end
54
62
 
63
+ private
64
+
65
+ # Private: buils up a list of strings that are IDs [season]_[episode]
66
+ # smaller than the supplied id
67
+ #
68
+ # Returns list of strings in the structure above
69
+ def build_up_ids_before_another_id(id)
70
+ if md = id.match(/^(\d+)_(\d+)$/)
71
+ season = md[1].to_i
72
+ episode = md[2].to_i
73
+ virtual_ids= []
74
+
75
+ 1.upto(season).each do |s|
76
+ episode_range = (1..50).to_a
77
+ if s == season
78
+ episode_range = (1...episode).to_a
79
+ end
80
+
81
+ episode_range.each do |e|
82
+ virtual_ids << "%d_%d" % [s, e]
83
+ end
84
+ end
85
+
86
+ return virtual_ids
87
+ else
88
+ raise AttributeError, "the supplied id was not an id"
89
+ end
90
+ end
55
91
  end
56
92
  end
@@ -163,9 +163,25 @@ module Sindex
163
163
 
164
164
  # write the different episodes
165
165
  data.episodes.each do |language, episodes|
166
+ add_all_before_flag=false
167
+
166
168
  xml.episodes(:lang => language) {
167
169
  episodes.each do |episode_id, filename|
168
- xml.episode(:name => filename)
170
+
171
+ # only dump real episodes not virtual episodes that are
172
+ # added because of the `all_before`-flag
173
+ if filename == :virtual
174
+ add_all_before_flag=true
175
+ next
176
+ end
177
+
178
+ args = {:name => filename}
179
+ if add_all_before_flag
180
+ args[:all_before] = true
181
+ add_all_before_flag=false
182
+ end
183
+
184
+ xml.episode(args)
169
185
  end
170
186
  }
171
187
  end
@@ -217,12 +233,18 @@ module Sindex
217
233
  s.receive_updates = false if series[:receive_updates].match(/false/i)
218
234
 
219
235
  series.css('episodes').each do |episodes|
220
- language = episodes['lang'].match(/de/) ? :de : :en
236
+ language = episodes['lang'].to_sym
221
237
 
222
238
  episodes.css('episode').each do |episode|
223
239
  episode['name'] || next
224
240
 
225
- s.add_episode(episode['name'], language)
241
+ # process `all_before` flag
242
+ all_before=false
243
+ if episode['all_before'] && episode['all_before'].match(/true/i)
244
+ all_before=true
245
+ end
246
+
247
+ s.add_episode(episode['name'], language, all_before)
226
248
  end
227
249
  end
228
250
 
@@ -1,3 +1,3 @@
1
1
  module Sindex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -9,6 +9,8 @@
9
9
 
10
10
  <!ELEMENT episode EMPTY>
11
11
  <!ATTLIST episode name CDATA #REQUIRED>
12
+ <!ATTLIST episode all_before (true|false) "false">
13
+ <!-- set this on an episode and all episodes before has also been watched -->
12
14
 
13
15
  <!ELEMENT alias EMPTY>
14
16
  <!ATTLIST alias to CDATA #REQUIRED>
@@ -73,4 +73,12 @@
73
73
  <episode name="S01E04 - Bitte warten.avi" />
74
74
  </episodes>
75
75
  </series>
76
+ <series name="The Big Bang Theory">
77
+ <episodes>
78
+ <episode name="S06E01 - do not change.avi" all_before="true"/>
79
+ <episode name="S06E02 - Grundkurs Spanisch.avi" />
80
+ <episode name="S06E03 - Carpe Diem.avi" />
81
+ <episode name="S06E04 - Bitte warten.avi" />
82
+ </episodes>
83
+ </series>
76
84
  </seriesindex>
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require File.dirname(__FILE__) + '/test_helper.rb'
3
3
  require 'fileutils'
4
+ require 'nokogiri'
4
5
 
5
6
  class TestIndex < Test::Unit::TestCase
6
7
 
@@ -89,6 +90,20 @@ class TestIndex < Test::Unit::TestCase
89
90
  "Prison.Break.S01E31.Bankgeheimnis.DL.German.HDTV.XviD-GDR")
90
91
  end
91
92
 
93
+ def test_that_the_all_before_flag_is_interpreted
94
+ assert_equal true, @series_index.episode_existing?("The Big Bang Theory",
95
+ "Thee.Big.Bang.Theory.S01E31.Bankgeheimnis.DL.German.HDTV.XviD-GDR")
96
+ end
97
+
98
+ def test_that_the_all_before_flag_is_also_written_to_dumped_index
99
+ filename = @tmp_directory + 'dumped_index.xml'
100
+ @series_index.dump_index_to_file(filename)
101
+
102
+ doc = Nokogiri::XML(File.read(filename))
103
+ elems = doc.css('series[name="The Big Bang Theory"] > episodes > episode[all_before="true"]')
104
+ assert_equal false, elems.empty?
105
+ end
106
+
92
107
  def test_that_you_can_add_new_episodes_to_the_index
93
108
  assert_equal @series_index.episode_existing?("Shameless US",
94
109
  "Shameless.US.S01E09.German"), false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sindex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-10-28 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 811642567388058588
134
+ hash: -599233288800797893
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements:
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  version: '0'
141
141
  segments:
142
142
  - 0
143
- hash: 811642567388058588
143
+ hash: -599233288800797893
144
144
  requirements: []
145
145
  rubyforge_project:
146
146
  rubygems_version: 1.8.24