aniview 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aniview +2 -3
  3. data/lib/aniview.rb +50 -243
  4. data/lib/aniview/client/aniclient.rb +111 -53
  5. data/lib/aniview/interface/animeio/animefile.rb +73 -64
  6. data/lib/aniview/interface/animeio/animeio.rb +184 -181
  7. data/lib/aniview/interface/animeio/animeseries.rb +53 -48
  8. data/lib/aniview/interface/deluge/delugec.rb +158 -153
  9. data/lib/aniview/interface/deluge/torrentitem.rb +21 -16
  10. data/lib/aniview/interface/item.rb +21 -17
  11. data/lib/aniview/interface/mpv/mpvbridge.rb +78 -73
  12. data/lib/aniview/interface/pref/pref.rb +135 -132
  13. data/lib/aniview/interface/pref/prefitem.rb +16 -15
  14. data/lib/aniview/interface/schedule/schedule.rb +89 -83
  15. data/lib/aniview/interface/schedule/scheduleitem.rb +54 -51
  16. data/lib/aniview/interface/subscription/subscription.rb +111 -108
  17. data/lib/aniview/util/term.rb +39 -36
  18. data/lib/aniview/util/util.rb +149 -0
  19. data/lib/aniview/view/aiomenu.rb +68 -63
  20. data/lib/aniview/view/color.rb +69 -67
  21. data/lib/aniview/view/delugemenu.rb +44 -40
  22. data/lib/aniview/view/menu.rb +281 -286
  23. data/lib/aniview/view/prefmenu.rb +36 -34
  24. data/lib/aniview/view/schedulemenu.rb +32 -29
  25. data/lib/aniview/view/statusline.rb +19 -14
  26. data/lib/aniview/view/subscriptionmenu.rb +35 -32
  27. data/lib/application.rb +260 -0
  28. data/lib/daemon.rb +174 -0
  29. metadata +5 -12
  30. data/bin/aniviewd +0 -20
  31. data/lib/aniview/util/alogger.rb +0 -18
  32. data/lib/aniview/util/command.rb +0 -25
  33. data/lib/aniview/util/format.rb +0 -123
  34. data/lib/aniview/util/online.rb +0 -12
  35. data/lib/aniview/util/serializer.rb +0 -19
  36. data/lib/aniview/util/stringhelp.rb +0 -50
  37. data/lib/aniview/view/emote.rb +0 -345
  38. data/lib/aniviewd.rb +0 -179
@@ -1,36 +1,38 @@
1
1
  require_relative 'menu'
2
- require_relative '../util/format'
3
- require_relative '../util/command'
4
-
5
-
6
- class PrefMenu < Menu
7
-
8
- def refresh
9
- @items = @interface.send(@refresh_func)
10
-
11
- @attributes = {
12
- "t" => @attributes["t"],
13
- }
14
-
15
- @expanded = -1 if @items.values[@expanded] == nil
16
- fixCursor
17
- end
18
-
19
- def customControl(key, sel)
20
- path = @items.values[sel["out"]][0].path
21
- title = @items.keys[sel["out"]].attributes["t"]
22
- value = @items.keys[sel["out"]].attributes["v"]
23
-
24
- if key == "space"
25
- #expand(sel["out"])
26
- elsif key == "r"
27
- refresh
28
- elsif key == "enter"
29
-
30
- newval = Command.read(@term, title + ":", value)
31
-
32
- @interface.set(path, newval)
33
- refresh
34
- end
35
- end
2
+ require_relative '../util/util'
3
+
4
+ module Aniview
5
+ module View
6
+ class PrefMenu < Menu
7
+ include Aniview::Util
8
+ def refresh
9
+ @items = @interface.send(@refresh_function)
10
+
11
+ @attributes = {
12
+ "t" => @attributes["t"],
13
+ }
14
+
15
+ @expanded = -1 if @items.values[@expanded] == nil
16
+ fixCursor
17
+ end
18
+
19
+ def customControl(key, sel)
20
+ path = @items.values[sel["out"]][0].path
21
+ title = @items.keys[sel["out"]].attributes["t"]
22
+ value = @items.keys[sel["out"]].attributes["v"]
23
+
24
+ if key == "space"
25
+ #expand(sel["out"])
26
+ elsif key == "r"
27
+ refresh
28
+ elsif key == "enter"
29
+
30
+ newval = Util.readline(@term, title + ":", value)
31
+
32
+ @interface.set(path, newval)
33
+ refresh
34
+ end
35
+ end
36
+ end
37
+ end
36
38
  end
@@ -1,36 +1,39 @@
1
1
  require_relative 'menu'
2
- require_relative '../util/format'
3
- require_relative '../util/command'
4
-
5
- class ScheduleMenu < Menu
6
-
7
- def refresh
8
- @items = @interface.makeHash @interface.send(@refresh_func)
9
-
10
- @attributes = {
11
- "t" => @attributes["t"],
12
- }
13
-
14
- @expanded = -1 if @items.values[@expanded] == nil
15
- fixCursor
16
- end
17
-
18
- def customControl(key, sel)
19
-
20
- item = @items.values[sel["out"]].attributes["t"]
21
-
22
- if key == @pref.get("keybindings")["schedule_add_item"]
23
- newval = Command.read(@term, "new item:")
24
- @interface.addItem newval
2
+ require_relative '../util/util'
3
+
4
+ module Aniview
5
+ module View
6
+ class ScheduleMenu < Menu
7
+ include Aniview::Util
8
+ def refresh
9
+ @items = @interface.makeHash @interface.send(@refresh_function)
10
+
11
+ @attributes = {
12
+ "t" => @attributes["t"],
13
+ }
25
14
 
26
- elsif key == @pref.get("keybindings")["schedule_delete_item"]
27
- @interface.removeItem sel["out"]
15
+ @expanded = -1 if @items.values[@expanded] == nil
16
+ fixCursor
17
+ end
28
18
 
29
- elsif key == @pref.get("keybindings")["schedule_edit_item"]
30
- newval = Command.read(@term, "edit item:", item)
31
- @interface.editItem sel["out"], newval
19
+ def customControl(key, sel)
20
+
21
+ item = @items.values[sel["out"]].attributes["t"]
22
+
23
+ if key == @pref.get("keybindings")["schedule_add_item"]
24
+ newval = Util.readline(@term, "new item:")
25
+ @interface.addItem newval
26
+
27
+ elsif key == @pref.get("keybindings")["schedule_delete_item"]
28
+ @interface.removeItem sel["out"]
29
+
30
+ elsif key == @pref.get("keybindings")["schedule_edit_item"]
31
+ newval = Util.readline(@term, "edit item:", item)
32
+ @interface.editItem sel["out"], newval
33
+
34
+ end
35
+ end
32
36
 
33
37
  end
34
38
  end
35
-
36
39
  end
@@ -1,18 +1,23 @@
1
- require_relative '../util/format'
1
+ require_relative '../util/util'
2
2
  require_relative 'color'
3
3
 
4
- class StatusLine
5
- def initialize pref, term, mpvbridge
6
- @term = term
7
- @pref = pref
8
- @mpvbridge = mpvbridge
9
- @clr = Color.public_send(@pref.get("clr")["main"])
10
- end
11
-
12
- def draw
13
- status_row = @term.rows - 1
14
- line = Format.parse_format @pref.get("format_status"), @mpvbridge.attributes, @term.cols
15
- #p @mpvbridge.attributes
16
- print "\e[#{status_row};1H" + @clr + line + "\e[K\n\e[2K"
4
+ module Aniview
5
+ module View
6
+ class StatusLine
7
+ include Aniview::Util
8
+ def initialize pref, term, mpvbridge
9
+ @term = term
10
+ @pref = pref
11
+ @mpvbridge = mpvbridge
12
+ @clr = Aniview::View::Color.public_send(@pref.get("clr")["main"])
13
+ end
14
+
15
+ def draw
16
+ status_row = @term.rows - 1
17
+ line = Util.parse_format @pref.get("format_status"), @mpvbridge.attributes, @term.cols
18
+ #p @mpvbridge.attributes
19
+ print "\e[#{status_row};1H" + @clr + line + "\e[K\n\e[2K"
20
+ end
21
+ end
17
22
  end
18
23
  end
@@ -1,38 +1,41 @@
1
1
  require_relative 'menu'
2
- require_relative '../util/format'
3
- require_relative '../util/command'
4
-
5
- class SubscriptionMenu < Menu
6
-
7
- def refresh
8
- @last_checked = Time.now.to_i if @last_checked == nil
2
+ require_relative '../util/util'
3
+
4
+ module Aniview
5
+ module View
6
+ class SubscriptionMenu < Menu
7
+
8
+ include Aniview::Util
9
+
10
+ def refresh
11
+ @last_checked = Time.now.to_i if @last_checked == nil
12
+
13
+ @items = @interface.makeHash @interface.send(@refresh_function)
9
14
 
10
- @items = @interface.makeHash @interface.send(@refresh_func)
11
-
12
- if Time.now.to_i < @last_checked + 10
13
- @attributes["l"] = @interface.getLastChecked
14
- @attributes["d"] = @interface.checkDaemon
15
- @interface.syncMatches
16
- @last_checked = Time.now.to_i
17
- end
18
-
19
- @expanded = -1 if @items.values[@expanded] == nil
20
- fixCursor
21
- end
22
-
23
- def customControl(key, sel)
24
-
25
- item = @items.values[sel["out"]].attributes["r"]
26
-
27
- if key == @pref.get("keybindings")["subscriptions_edit"]
28
- newval = Command.read(@term, "regexp:", item)
29
- @interface.editItem(sel["out"], newval)
30
-
31
- elsif key == "m"
32
- @interface.forceMatch
15
+ if Time.now.to_i < @last_checked + 10
16
+ @attributes["l"] = @interface.getLastChecked
17
+ @attributes["d"] = @interface.checkDaemon
18
+ @interface.syncMatches
19
+ @last_checked = Time.now.to_i
20
+ end
21
+
22
+ @expanded = -1 if @items.values[@expanded] == nil
23
+ fixCursor
24
+ end
25
+
26
+ def customControl(key, sel)
27
+
28
+ item = @items.values[sel["out"]].attributes["r"]
29
+
30
+ if key == @pref.get("keybindings")["subscriptions_edit"]
31
+ newval = Util.readline(@term, "regexp:", item)
32
+ @interface.editItem(sel["out"], newval)
33
+
34
+ elsif key == "m"
35
+ @interface.forceMatch
33
36
 
37
+ end
38
+ end
34
39
  end
35
-
36
40
  end
37
-
38
41
  end
@@ -0,0 +1,260 @@
1
+ require 'highline'
2
+ require 'highline/import'
3
+ require 'thread'
4
+ require 'io/console'
5
+ require 'warning'
6
+
7
+ Warning.ignore([:fixnum, :bignum])
8
+
9
+ require_relative 'aniview/view/aiomenu'
10
+ require_relative 'aniview/view/delugemenu'
11
+ require_relative 'aniview/view/prefmenu'
12
+ require_relative 'aniview/view/schedulemenu'
13
+ require_relative 'aniview/view/subscriptionmenu'
14
+ require_relative 'aniview/view/statusline'
15
+
16
+ require_relative 'aniview/interface/animeio/animeio'
17
+ require_relative 'aniview/interface/mpv/mpvbridge'
18
+ require_relative 'aniview/interface/deluge/delugec'
19
+ require_relative 'aniview/interface/pref/pref'
20
+ require_relative 'aniview/interface/subscription/subscription'
21
+ require_relative 'aniview/interface/schedule/schedule'
22
+
23
+ require_relative 'aniview/util/util'
24
+ require_relative 'aniview/util/term'
25
+
26
+ require_relative 'aniview/client/aniclient'
27
+
28
+ $stdout.sync = true
29
+ module Aniview
30
+ # Main class for the aniview application
31
+ class Application
32
+
33
+ include Util
34
+
35
+ # initializes a new Aniview application
36
+ #
37
+ # @return nil
38
+ #
39
+ def initialize
40
+
41
+ @term = Util::Term.new
42
+
43
+ @pref = Interface::Pref.new
44
+
45
+ @mpvbridge = Interface::MPVBridge.new @pref
46
+
47
+ @aio = Interface::AnimeIO.new @pref, @mpvbridge
48
+
49
+ @schedule = Interface::Schedule.new @pref
50
+
51
+ @delugec = Interface::DelugeC.new @pref
52
+
53
+ @c = Client::AniClient.new @pref
54
+
55
+ @statusline = View::StatusLine.new @pref, @term, @mpvbridge
56
+
57
+ #file = "/Users/lattis/anime/Tekkonkinkreet/Tekkonkinkreet.mkv"
58
+ #@mpvbridge.play file
59
+
60
+ #while true
61
+ # @statusline.draw
62
+ # sleep 1/45.0
63
+ #end
64
+
65
+ @subscription = Interface::Subscription.new(@pref, @schedule, @delugec, @c)
66
+
67
+ if not @c.server?
68
+ #puts "starting server"
69
+ process = fork do
70
+ require_relative 'daemon'
71
+ avd = Daemon.new([])
72
+ avd.run
73
+ end
74
+ Process.detach(process)
75
+ end
76
+
77
+ @aiomenu = View::AioMenu.new(
78
+ refresh_function: :getUnwatched,
79
+ interface: @aio,
80
+ name: @pref.get("menu_titles")["unwatched"],
81
+ pref: @pref,
82
+ format: "format_library_unwatched",
83
+ term: @term
84
+ )
85
+ @prefmenu = View::PrefMenu.new(
86
+ refresh_function: :getAll,
87
+ interface: @pref,
88
+ name: @pref.get("menu_titles")["preferences"],
89
+ pref: @pref,
90
+ format: "format_preferences",
91
+ term: @term,
92
+ children: false
93
+ )
94
+ @delugemenu = View::DelugeMenu.new(
95
+ refresh_function: :getTorrents,
96
+ interface: @delugec,
97
+ name: @pref.get("menu_titles")["torrents"],
98
+ pref: @pref,
99
+ format: "format_torrents",
100
+ term: @term,
101
+ children: false
102
+ )
103
+
104
+ @schedulemenu = View::ScheduleMenu.new(
105
+ refresh_function: :getAll,
106
+ interface: @schedule,
107
+ name: @pref.get("menu_titles")["schedlue"],
108
+ pref: @pref,
109
+ format: "format_schedule",
110
+ term: @term,
111
+ children: false
112
+ )
113
+
114
+ @subscriptionmenu = View::SubscriptionMenu.new(
115
+ refresh_function: :getAll,
116
+ interface: @subscription,
117
+ name: @pref.get("menu_titles")["subscriptions"],
118
+ pref: @pref,
119
+ format: "format_subscriptions",
120
+ term: @term,
121
+ children: false
122
+ )
123
+
124
+ @term.save.hide_cursor.echo_off
125
+ end
126
+
127
+ # Cleans up Aniview, restoring terminal settings and safely exiting all
128
+ # loops
129
+ #
130
+ # @return nil
131
+ #
132
+ def cleanup
133
+ @mthread.exit if @mthread != nil
134
+ @statusthread.exit if @statusthread != nil
135
+ @term.reset
136
+ @mpvbridge.quit!
137
+ exit
138
+ end
139
+
140
+ # Executes an Aniview command
141
+ #
142
+ # @param cmds The command to execute
143
+ #
144
+ # @return nil
145
+ #
146
+ def runCommand(cmds)
147
+ cmd_s = cmds.split
148
+ cmd = cmd_s[0]
149
+ if cmd == "quit"
150
+ self.cleanup
151
+ elsif cmd == "sync"
152
+ #alist = Anilist.new
153
+ #alist.sync
154
+ elsif cmd == "pref"
155
+ @pref.set cmd_s[1], cmd_s[2]
156
+ elsif cmd == "index"
157
+ @aio.index_anime :force => true, :verbose => true
158
+ @aiomenu.refresh
159
+ elsif cmd == "help"
160
+ print "\e[1;1H" + Aniview::View::Color.white
161
+ puts "Help"
162
+ puts ""
163
+ else
164
+ print "\033[" + String(@term.rows) + ";1H" + Aniview::View::Color.red + "error, unknown command"
165
+ @term.getKey
166
+ end
167
+ end
168
+
169
+ # Changes the current view in the app
170
+ #
171
+ # @param newView the view to change to, must inherit Aniview::View::Menu
172
+ #
173
+ # @return nil
174
+ #
175
+ def changeView newView
176
+ @view = newView
177
+ @view.change_screen_size
178
+ end
179
+
180
+
181
+ # Runs the aniview application, this method starts all of the threads
182
+ #
183
+ # @return nil
184
+ #
185
+ def run
186
+
187
+ @view = @aiomenu
188
+
189
+ mutex = Mutex.new
190
+ Signal.trap('SIGWINCH', proc {
191
+ Thread.new { mutex.synchronize { @view.change_screen_size } }
192
+ } )
193
+
194
+ key = ""
195
+ @view.refresh
196
+ @shoulddraw = true
197
+
198
+ Thread.abort_on_exception = true
199
+ @mthread = Thread.new do
200
+ while true
201
+ if @shoulddraw
202
+ @view.draw
203
+ @view.refresh
204
+ end
205
+ sleep 1/45.0
206
+ end
207
+ end
208
+
209
+ @statusthread = Thread.new do
210
+ while true
211
+ if @shoulddraw
212
+ @statusline.draw
213
+ end
214
+ sleep 1/25.0
215
+ end
216
+ end
217
+
218
+ while true
219
+ @shoulddraw = true
220
+ key = @term.getKey
221
+ @shoulddraw = false
222
+
223
+ kb = @pref.get("keybindings")
224
+ nm = @pref.get("menu_titles")
225
+
226
+ case key
227
+ when kb["goto_unwatched"]
228
+ changeView @aiomenu
229
+ @view.setName nm["unwatched"]
230
+ @view.setFormat("format_library_unwatched")
231
+ @view.setRfunc(:getUnwatched)
232
+
233
+ when kb["goto_library"]
234
+ changeView @aiomenu
235
+ @view.setName nm["library"]
236
+ @view.setFormat("format_library")
237
+ @view.setRfunc(:getAll)
238
+
239
+ when kb["goto_torrents"]
240
+ changeView @delugemenu
241
+ @view.setName nm["torrents"]
242
+ when kb["goto_preferences"]
243
+ changeView @prefmenu
244
+ @view.setName nm["preferences"]
245
+ when kb["goto_schedule"]
246
+ changeView @schedulemenu
247
+ @view.setName nm["schedule"]
248
+ when kb["goto_subscriptions"]
249
+ changeView @subscriptionmenu
250
+ @view.setName nm["subscriptions"]
251
+ when ":"
252
+ runCommand Util.readline(@term, ":")
253
+ when "q"
254
+ cleanup
255
+ end
256
+ @view.control(key)
257
+ end
258
+ end
259
+ end
260
+ end