aniview 2.1.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,21 @@ require 'simple-rss'
2
2
  require 'open-uri'
3
3
 
4
4
  require_relative "../schedule/scheduleitem"
5
+ require_relative '../bridge'
5
6
 
6
7
  module Aniview
7
8
  module Interface
8
- class Subscription
9
+ class Subscription < Bridge
10
+
11
+ include Observable
12
+
9
13
  def initialize pref, schedule, delugec, client
10
14
  @c = client
11
15
  @pref = pref
12
16
  @schedule = schedule
13
17
  @delugec = delugec
18
+ #SimpleRSS.feed_tags << :"torrent:magnetURI"
19
+ #&lt;![CDATA[
14
20
  end
15
21
 
16
22
  def log s
@@ -28,6 +34,10 @@ module Aniview
28
34
  def getLastChecked
29
35
  @c.lastchecked
30
36
  end
37
+
38
+ def getNextCheck
39
+ @c.sendMsg "nextcheck"
40
+ end
31
41
 
32
42
  def syncMatches
33
43
  @schedule.mergeItems @c.getItems
@@ -35,6 +45,7 @@ module Aniview
35
45
 
36
46
  def updateFeed
37
47
  begin
48
+ SimpleRSS.item_tags << :"torrent:magnetURI"
38
49
  @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"])
39
50
 
40
51
  rescue SocketError
@@ -67,11 +78,11 @@ module Aniview
67
78
  log "matching all" if verbose
68
79
 
69
80
  total_matches = 0
70
- getAll.each { |subs|
81
+ @schedule.schedule.each { |subs|
71
82
  log "matching #{subs.attributes["r"]}" if verbose
72
83
  matches = match subs.attributes["r"], verbose
73
84
  log "found #{matches.length} matches" if verbose
74
- log "#{matches}" if verbose
85
+ #log "#{matches}" if verbose
75
86
 
76
87
  if matches.length >= 1
77
88
 
@@ -79,8 +90,10 @@ module Aniview
79
90
  newfile = downloaddir + matches[0][:title]
80
91
 
81
92
  next if File.exist? newfile
93
+ log "attempting to downloading file" if verbose
82
94
  log "set download dir to #{newfile}" if verbose
83
- s = @delugec.addTorrent matches[0][:link], @pref.parseDir(subs.attributes["p"]), verbose: true
95
+ log "#{matches[0].link}" if verbose
96
+ s = @delugec.addTorrent matches[0].link, @pref.parseDir(subs.attributes["p"]), verbose: true
84
97
  log "adding torrent, status #{s}" if verbose
85
98
  subs.setSeen if s
86
99
  @schedule.save
@@ -98,23 +111,16 @@ module Aniview
98
111
  end
99
112
  end
100
113
 
101
- def getAll
102
- @schedule.getAll
114
+ def items
115
+ @schedule.items
103
116
  end
104
117
 
105
118
  def editItem loc, newval
106
- @schedule.getAll[loc].setRegexp newval
119
+ @schedule.schedule[loc].setRegexp newval
107
120
  @schedule.save
121
+ changed
122
+ notify_observers
108
123
  end
109
-
110
- def makeHash(arr)
111
- ret = {}
112
- arr.each{ |subs|
113
- ret.merge!(subs => subs)
114
- }
115
- return ret
116
- end
117
-
118
124
  end
119
125
  end
120
126
  end
@@ -19,8 +19,8 @@ module Aniview
19
19
  end
20
20
 
21
21
  def self.error_message
22
+ #use statusline to show error messages
22
23
  print "\e[#{Term.rows};2H Message"
23
- sleep 1
24
24
  end
25
25
 
26
26
  def self.format_duration v
@@ -5,28 +5,18 @@ module Aniview
5
5
  module View
6
6
  class AioMenu < Menu
7
7
  include Aniview::Util
8
- def setmal malanime
9
- @malanime = malanime
10
- end
11
-
12
- def refresh
13
- @items = @interface.makeHash @interface.send(@refresh_function)
14
-
15
- @attributes = {
16
- "t" => @attributes["t"],
17
- "D" => Util.format_duration(getDuration),
18
- "S" => Util.format_size(getSize)
19
- }
20
-
21
- @expanded = -1 if @items.values[@expanded] == nil
22
- fixCursor
23
- end
8
+
9
+ def refresh_attributes
10
+ @attributes = {
11
+ "t" => @attributes["t"],
12
+ "D" => Util.format_duration(getDuration),
13
+ "S" => Util.format_size(getSize)
14
+ }
15
+ end
24
16
 
25
17
  def getDuration
26
- dur = 0
27
- @items.each{ |child|
28
- dur += child[0].attributes["d"]
29
- }
18
+ dur = 0
19
+ @items.each{ |p, c| dur += p.attr["d"] }
30
20
  return dur
31
21
  end
32
22
 
@@ -39,6 +29,7 @@ module Aniview
39
29
  end
40
30
 
41
31
  def customControl(key, sel)
32
+ return if @items == {}
42
33
  path = @items.values[sel["out"]][sel["in"]].path
43
34
 
44
35
  empty = path == "empty"
@@ -56,14 +47,15 @@ module Aniview
56
47
  refresh
57
48
  elsif key == @pref.get("keybindings")["anime_set_watched"] and not empty
58
49
  @interface.addWatched(path)
59
- refresh
60
50
  elsif key == @pref.get("keybindings")["anime_undo_set_watched"]
61
51
  @interface.rmWatched()
62
- refresh
63
52
  elsif key == @pref.get("keybindings")["anime_set_unwatched"] and not empty
64
53
  @interface.rmWatched(path)
65
-
54
+ moveCursor("down")
66
55
  end
56
+
57
+ changed
58
+ notify_observers
67
59
  end
68
60
  end
69
61
  end
@@ -5,43 +5,34 @@ module Aniview
5
5
  module View
6
6
  class DelugeMenu < Menu
7
7
  include Aniview::Util
8
-
9
- def refresh
10
- @items = @interface.makeHash @interface.send(@refresh_function)
11
-
12
- @attributes = {
13
- "t" => @attributes["t"],
8
+ def refresh_attributes
9
+ @attributes = {
10
+ "t" => @attributes["t"],
14
11
  "s" => @interface.getStatus
15
- }
16
-
17
- @expanded = -1 if @items.values[@expanded] == nil
18
- fixCursor
19
- end
12
+ }
13
+ end
20
14
 
21
- def customControl(key, sel)
15
+ def customControl(key, sel)
22
16
 
23
17
  if @items != nil and @items.length > 0
24
18
  item = @items.values[sel["out"]]
25
19
  else
26
20
  item = ""
27
21
  end
28
-
29
- if key == @pref.get("keybindings")["torrents_pause"]
22
+
23
+ if key == @pref.get("keybindings")["torrents_pause"]
30
24
  @interface.toggleTorrent(item)
31
25
  elsif key == @pref.get("keybindings")["torrents_remove"]
32
26
  @interface.removeTorrent(item, false)
33
27
  elsif key == @pref.get("keybindings")["torrents_remove_data"]
34
28
  @interface.removeTorrent(item, true)
35
- elsif key == "enter"
36
-
37
29
  elsif key == "+"
30
+ pause
38
31
  newval = Util.readline(@term, "mag:", "")
39
32
  @interface.addTorrent newval, Dir.home + "/downloads/"
40
-
41
- end
42
- end
43
-
33
+ unpause
34
+ end
35
+ end
44
36
  end
45
37
  end
46
38
  end
47
-
@@ -1,3 +1,5 @@
1
+ require 'benchmark'
2
+
1
3
  require_relative 'color'
2
4
  require_relative '../util/util'
3
5
 
@@ -5,9 +7,15 @@ module Aniview
5
7
  module View
6
8
  class Menu
7
9
  include Aniview::Util
8
- def initialize(refresh_function:,interface:,name:,pref:,format:,term:,children: true)
10
+ include Observable
11
+
12
+ attr_accessor :visible
13
+
14
+ def initialize(refresh_function: :items, interface:, name:, pref:, format:, term:, children: true, visible: false)
9
15
  @attributes = {}
10
16
 
17
+ @visible = visible
18
+
11
19
  @refresh_function = refresh_function
12
20
  @interface = interface
13
21
  setName name
@@ -15,7 +23,7 @@ module Aniview
15
23
  @format = format
16
24
  @term = term
17
25
  @children = children
18
-
26
+
19
27
  @expanded = -1
20
28
  @selected = 0
21
29
 
@@ -23,13 +31,44 @@ module Aniview
23
31
  @items_hash = {}
24
32
  @hashmap = {}
25
33
  @lu = 0
26
-
34
+
27
35
  @oldRows = @term.rows
28
-
36
+
29
37
  refresh
30
-
38
+
31
39
  @view = [0, @term.rows - 3]
32
-
40
+
41
+ @updated = true
42
+
43
+ if @interface.singleton_class.include? Observable
44
+ @interface.add_observer(self, :refresh)
45
+ end
46
+ end
47
+
48
+ def unpause
49
+ unless @interface.singleton_class.include? Observable
50
+ auto_update s: :start
51
+ end
52
+ end
53
+
54
+ def pause
55
+ auto_update s: :stop
56
+ end
57
+
58
+ def auto_update s: :start
59
+ case s
60
+ when :start
61
+ @update_thread = Thread.new do
62
+ while true
63
+ refresh
64
+ changed
65
+ notify_observers
66
+ sleep 0.07
67
+ end
68
+ end
69
+ when :stop
70
+ @update_thread.exit if @update_thread
71
+ end
33
72
  end
34
73
 
35
74
  def setRfunc(new_method)
@@ -41,7 +80,7 @@ module Aniview
41
80
  refreshFormats
42
81
  end
43
82
 
44
- def change_screen_size
83
+ def change_screen_size redraw: true
45
84
  #@term.rows = lines
46
85
  #@term.cols = cols
47
86
  @items_formatted = {}
@@ -50,14 +89,14 @@ module Aniview
50
89
  refresh
51
90
 
52
91
  #if @term.rows > @oldRows
53
-
92
+
54
93
  diff = @term.rows - @oldRows
55
94
  #@view[0] += diff
56
95
  @view[1] += diff
57
96
 
58
97
  @oldRows = @term.rows
59
98
  adjustView
60
- draw
99
+ draw if redraw
61
100
  end
62
101
 
63
102
  def setName(name)
@@ -69,9 +108,13 @@ module Aniview
69
108
  end
70
109
 
71
110
  def refresh
72
- @items = @interface.makeHash @interface.send(@refresh_function)
111
+ @items = @interface.send(@refresh_function)
112
+ refreshFormats
113
+ refresh_attributes
73
114
  @expanded = -1 if @items.values[@expanded] == nil
74
115
  fixCursor
116
+ changed
117
+ notify_observers
75
118
  end
76
119
 
77
120
  def expand(i)
@@ -85,6 +128,8 @@ module Aniview
85
128
  end
86
129
  fixCursor
87
130
  adjustView
131
+ changed
132
+ notify_observers
88
133
  end
89
134
 
90
135
  def resolveSelected(resolve_me=@selected)
@@ -135,123 +180,105 @@ module Aniview
135
180
  end
136
181
  end
137
182
 
138
- def refreshFormats
139
- now = Integer(DateTime.now.strftime('%Q'))
140
- return if now - @lu < 100
141
- @lu = now
183
+ def adjustView
184
+ buffer = 2
185
+ bottom = @term.rows-3
186
+
187
+ diff = 0
188
+ if @selected < @view[0] + buffer #and @selected > buffer
189
+ while @selected < @view[0] + buffer
190
+ @view[0]-=1
191
+ @view[1]-=1
192
+ end
193
+ elsif @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
194
+ while @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
195
+ @view[0]+=1
196
+ @view[1]+=1
197
+ end
198
+ end
142
199
 
200
+ diff = 0 - @view[0] if @view[0] < 0
201
+ diff = bottom - @view[1] if @view[1] < bottom
202
+
203
+ @view[0] += diff
204
+ @view[1] += diff
205
+ end
206
+
207
+ def updated?
208
+ @updated and !(@updated = !@updated)
209
+ end
210
+
211
+ def updated!
212
+ @updated = true
213
+ end
214
+
215
+ def interface
216
+ @interface
217
+ end
218
+
219
+ def refreshFormats
143
220
  @cl = {
144
221
  "s" => Aniview::View::Color.public_send(@pref.get("clr")["selected"]),
145
222
  "1" => Aniview::View::Color.public_send(@pref.get("clr")["primary"]),
146
223
  "2" => Aniview::View::Color.public_send(@pref.get("clr")["secondary"]),
147
224
  "m" => Aniview::View::Color.public_send(@pref.get("clr")["main"]),
148
225
  }
149
-
150
- #@items_formatted = {}
151
- new_items_formatted = {}
152
- new_items_hash = {}
153
- new_hashmap = {}
154
- @items.each_with_index { |item, i|
155
-
156
- #@l.log @items.keys[i]
157
- #
158
- babble = item[0].cereal #Digest::SHA256.bubblebabble String(item[0])
159
-
160
- if @items_hash.key? babble
161
- val = @items_hash[babble]
162
- new_items_hash.merge!(babble => val)
163
- new_items_formatted.merge!(@hashmap[babble] => @items_formatted[@hashmap[babble]])
164
- new_hashmap.merge!(babble => @hashmap[babble])
165
- next
166
- end
167
-
168
- parent = Util.parse_format(
226
+
227
+ nif = {}
228
+
229
+ @items.each { |parent, children|
230
+
231
+ parent_formatted = Util.parse_format(
169
232
  @pref.get(@format)["parent"],
170
- item[0].attributes,
233
+ parent.attributes,
171
234
  @term.cols
172
235
  )
173
236
 
174
- children = []
175
- children_hash = []
176
-
237
+ children_formatted = []
177
238
  if @children
178
- item[1].each { |subitem|
179
-
180
- child_babble = subitem.cereal
181
-
182
- if @items_hash.key? child_babble
183
- val = @items_hash[babble]
184
- new_items_hash.merge!(child_babble => val)
185
- children<<@hashmap[babble]
186
- new_hashmap.merge!(babble => @hashmap[babble])
187
- next
188
- end
189
-
190
- children << Util.parse_format(
239
+ children.each { |child|
240
+ children_formatted << Util.parse_format(
191
241
  @pref.get(@format)["child"],
192
- subitem.attributes,
242
+ child.attributes,
193
243
  @term.cols
194
244
  )
195
- children_hash << subitem.hash
196
-
197
245
  }
198
246
  end
199
247
 
200
- new_items_hash.merge!(babble => children_hash)
201
- new_items_formatted.merge!(parent => children)
202
- new_hashmap.merge!(babble => parent)
248
+ nif.merge!(parent_formatted => children_formatted)
203
249
  }
204
250
 
205
- @items_formatted = new_items_formatted
206
- @items_hash = new_items_hash
207
- @hashmap = new_hashmap
251
+ @items_formatted = nif
208
252
 
209
253
  @title_formatted = Util.parse_format(
210
254
  @pref.get(@format)["title"],
211
255
  @attributes,
212
256
  @term.cols
213
257
  )
214
- end
215
-
216
- def adjustView
217
- buffer = 2
218
- bottom = @term.rows-3
219
-
220
- diff = 0
221
- if @selected < @view[0] + buffer #and @selected > buffer
222
- while @selected < @view[0] + buffer
223
- @view[0]-=1
224
- @view[1]-=1
225
- end
226
- elsif @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
227
- while @selected > @view[1] - (buffer+1) and @selected < getLen - buffer
228
- @view[0]+=1
229
- @view[1]+=1
230
- end
231
- end
232
-
233
- diff = 0 - @view[0] if @view[0] < 0
234
- diff = bottom - @view[1] if @view[1] < bottom
235
-
236
- @view[0] += diff
237
- @view[1] += diff
258
+
259
+ changed
260
+ notify_observers
238
261
  end
239
262
 
240
263
  def draw
241
- refreshFormats
242
- drawFrom(@view[0], @view[1])
243
- end
244
-
245
- def drawFrom(line_on, lines_to_draw)
246
- #print menu header
264
+
265
+ #refresh @items_formatted
266
+ #refreshFormats
267
+
268
+ #set the view
269
+ line_on = @view[0]
270
+ lines_to_draw = @view[1]
271
+
272
+ #print the menu title
247
273
  lo="\e[1;1H"
248
274
  print lo + @cl["m"] + @title_formatted + "\e[K"
249
275
 
276
+ #get the resolved start positions
250
277
  resolved_start_position = resolveSelected line_on
251
-
252
278
  outer_index = resolved_start_position["out"]
253
279
  inner_index = resolved_start_position["in"]
254
280
 
281
+ # if we are starting in the expanded portion, skip its parent
255
282
  if resolved_start_position["in_expanded"]
256
283
  outer_index+=1
257
284
  end
@@ -292,9 +319,14 @@ module Aniview
292
319
  else
293
320
  customControl(key, sel)
294
321
  end
322
+ changed
323
+ notify_observers
295
324
  end
296
325
 
297
326
  def customControl(key, sel); end
327
+
328
+ def refresh_attributes; end
329
+
298
330
  end
299
331
  end
300
332
  end