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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2886da682b5b5671858688ae216011d2af04ed3a
4
- data.tar.gz: b59ed72a1289d7a21eda2b4922674061702a267f
3
+ metadata.gz: 76fe86faf6063dc4aefae602dce65dc59b0563a6
4
+ data.tar.gz: 0bc9c727056c4b7ce31daea1aeed4e5e89668c4f
5
5
  SHA512:
6
- metadata.gz: c6943259e6c267341c73262ad702fb04bb489c46a88308127a7318b44aed913452a69c212a816cd9b5ac4761b5b1d436aa015708df78c91fe7879ec509c73eca
7
- data.tar.gz: b5ff1b8ec8ca41dd1a85ca8771ff8ffeb2853a99fbf0469f55cf6f14a4252d4dbe2f097d352b308621a08621fd2929906046e754d0f8fa715f0946f67186ab79
6
+ metadata.gz: 801a40242ad37834ebbe5e86f5705bab97bb0d17e5da2bc60f33c79fd443e8efe024b5752e573258ffd1b29c49f5ab047ee171c066f939cd721249e4044f148c
7
+ data.tar.gz: 82d13c551202d58ef28eaf09eac30041fbfa3f1f904627d43ad2f3616ace509140df747631c2f26a8957ddb151d3d17cbd9a200483dd59dffbceefa04960fdfd
data/bin/aniview CHANGED
@@ -6,10 +6,9 @@ rescue LoadError
6
6
  require_relative '../lib/aniview' if File.exist?(File.join(File.dirname(__FILE__), '../lib/aniview.rb'))
7
7
  end
8
8
 
9
- unless defined? AniView
9
+ unless defined? Aniview
10
10
  puts "cant find aniview library"
11
11
  exit
12
12
  end
13
13
 
14
- av = AniView.new
15
- av.run
14
+ Aniview::main(ARGV)
data/lib/aniview.rb CHANGED
@@ -1,252 +1,59 @@
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/alogger'
24
- require_relative 'aniview/util/command'
25
- require_relative 'aniview/util/term'
26
-
27
- require_relative 'aniview/client/aniclient'
28
-
29
- $stdout.sync = true
30
-
31
- class AniView
32
- def initialize
33
-
34
- @term = Term.new
35
-
36
- @pref = Pref.new
37
-
38
- $l = ALogger.new(@pref.parseDir(@pref.get "log_file"), false)
39
-
40
- @mpvbridge = MPVBridge.new @pref
41
-
42
- @aio = AnimeIO.new @pref, @mpvbridge
43
-
44
- @schedule = Schedule.new @pref
45
-
46
- @delugec = DelugeC.new @pref
47
-
48
- @c = AniClient.new @pref
49
-
50
- @statusline = StatusLine.new @pref, @term, @mpvbridge
51
-
52
- #file = "/Users/lattis/anime/Tekkonkinkreet/Tekkonkinkreet.mkv"
53
- #@mpvbridge.play file
1
+ require_relative 'application'
2
+ require_relative 'daemon'
3
+
4
+ # Main namespace for Aniview and all its classes
5
+ module Aniview
6
+
7
+ def self.show_help
8
+ puts "aniview"
9
+ puts "-h : show this message"
10
+ puts "-d <command> : send a command to the daemon"
11
+ puts " help : show help"
12
+ puts " start : start the daemon"
13
+ puts " stop : stop the daemon"
14
+ puts " info : show daemon info"
15
+ puts " up? : check if the daemon is up"
16
+ puts " nani : ###"
17
+ puts " items : check the daemon's items"
18
+ end
54
19
 
55
- #while true
56
- # @statusline.draw
57
- # sleep 1/45.0
58
- #end
59
-
60
- @subscription = Subscription.new(@pref, @schedule, @delugec, @c)
20
+ # initializes either the application or the daemon with given arguments
21
+ # @param argv an array of arguments, if -d is supplied, the remaining
22
+ # arguments will be passed on to the daemon
23
+ #
24
+ # @return nil
25
+ #
26
+ def self.main argv
27
+
28
+ main_class = nil
29
+ daemonize = false
30
+
31
+ argv.each { |arg|
32
+ case arg
33
+ when "-d"
34
+ argv.delete_at(0)
35
+ main_class = Aniview::Daemon.new(argv)
36
+ when "-h"
37
+ self.show_help
38
+ exit
39
+ else
40
+ puts "unknown argument #{arg}"
41
+ self.show_help
42
+ exit
43
+ end
44
+ }
45
+
46
+ main_class = Aniview::Application.new if main_class == nil
61
47
 
62
- if not @c.server?
63
- #puts "starting server"
48
+ if daemonize
64
49
  process = fork do
65
- require_relative 'aniviewd'
66
- avd = AniViewd.new([])
67
- avd.run
50
+ main_class.run
68
51
  end
52
+
69
53
  Process.detach(process)
70
- end
71
-
72
- @aiomenu = AioMenu.new(
73
- refresh_function: :getUnwatched,
74
- interface: @aio,
75
- name: @pref.get("menu_titles")["unwatched"],
76
- pref: @pref,
77
- format: "format_library_unwatched",
78
- term: @term
79
- )
80
- @prefmenu = PrefMenu.new(
81
- refresh_function: :getAll,
82
- interface: @pref,
83
- name: @pref.get("menu_titles")["preferences"],
84
- pref: @pref,
85
- format: "format_preferences",
86
- term: @term,
87
- children: false
88
- )
89
- @delugemenu = DelugeMenu.new(
90
- refresh_function: :getTorrents,
91
- interface: @delugec,
92
- name: @pref.get("menu_titles")["torrents"],
93
- pref: @pref,
94
- format: "format_torrents",
95
- term: @term,
96
- children: false
97
- )
98
-
99
- @schedulemenu = ScheduleMenu.new(
100
- refresh_function: :getAll,
101
- interface: @schedule,
102
- name: @pref.get("menu_titles")["schedlue"],
103
- pref: @pref,
104
- format: "format_schedule",
105
- term: @term,
106
- children: false
107
- )
108
-
109
- @subscriptionmenu = SubscriptionMenu.new(
110
- refresh_function: :getAll,
111
- interface: @subscription,
112
- name: @pref.get("menu_titles")["subscriptions"],
113
- pref: @pref,
114
- format: "format_subscriptions",
115
- term: @term,
116
- children: false
117
- )
118
-
119
- @term.save.hide_cursor.echo_off
120
-
121
- end
122
-
123
- def cleanup
124
- @mthread.exit if @mthread != nil
125
- @statusthread.exit if @statusthread != nil
126
- @term.reset
127
- @mpvbridge.quit!
128
- exit
129
- end
130
-
131
- def runCommand(cmds)
132
- cmd_s = cmds.split
133
- cmd = cmd_s[0]
134
- if cmd == "quit"
135
- self.cleanup
136
- elsif cmd == "sync"
137
- #alist = Anilist.new
138
- #alist.sync
139
- elsif cmd == "pref"
140
- @pref.set cmd_s[1], cmd_s[2]
141
- elsif cmd == "index"
142
- @aio.index_anime :force => true, :verbose => true
143
- @aiomenu.refresh
144
- elsif cmd == "help"
145
- print "\e[1;1H" + Color.white
146
- puts "Help"
147
- puts ""
148
54
  else
149
- print "\033[" + String(@term.rows) + ";1H" + Color.red + "error, unknown command"
150
- @term.getKey
151
- end
152
- end
153
-
154
- def changeView newView
155
- @view = newView
156
- @view.change_screen_size
157
- end
158
-
159
- def run
160
-
161
- @view = @aiomenu
162
-
163
- mutex = Mutex.new
164
- Signal.trap('SIGWINCH', proc {
165
- Thread.new { mutex.synchronize { @view.change_screen_size } }
166
- } )
167
-
168
- key = ""
169
- @view.refresh
170
- @shoulddraw = true
171
-
172
- Thread.abort_on_exception = true
173
- @mthread = Thread.new do
174
- while true
175
- if @shoulddraw
176
- @view.draw
177
- @view.refresh
178
- end
179
- sleep 1/45.0
180
- end
181
- end
182
-
183
- @statusthread = Thread.new do
184
- while true
185
- if @shoulddraw
186
- @statusline.draw
187
- end
188
- sleep 1/25.0
189
- end
55
+ main_class.run
190
56
  end
57
+ end
191
58
 
192
- while true
193
- @shoulddraw = true
194
- key = @term.getKey
195
- @shoulddraw = false
196
-
197
- kb = @pref.get("keybindings")
198
- nm = @pref.get("menu_titles")
199
-
200
- case key
201
- when kb["goto_unwatched"]
202
- changeView @aiomenu
203
- @view.setName nm["unwatched"]
204
- @view.setFormat("format_library_unwatched")
205
- @view.setRfunc(:getUnwatched)
206
-
207
- when kb["goto_library"]
208
- changeView @aiomenu
209
- @view.setName nm["library"]
210
- @view.setFormat("format_library")
211
- @view.setRfunc(:getAll)
212
-
213
- when kb["goto_torrents"]
214
- changeView @delugemenu
215
- @view.setName nm["torrents"]
216
- when kb["goto_preferences"]
217
- changeView @prefmenu
218
- @view.setName nm["preferences"]
219
- when kb["goto_schedule"]
220
- changeView @schedulemenu
221
- @view.setName nm["schedule"]
222
- when kb["goto_subscriptions"]
223
- changeView @subscriptionmenu
224
- @view.setName nm["subscriptions"]
225
- when ":"
226
- runCommand Command.read(@term, ":")
227
- when "q"
228
- cleanup
229
- end
230
-
231
-
232
-
233
- #if key == @pref.get("keybindings")["goto_unwatched"]
234
- # @view.setFormat("format_library_unwatched")
235
- # @view.setRfunc(:getUnwatched)
236
- #
237
- #elsif key == @pref.get("keybindings")["goto_library"]
238
- # @view.setFormat("format_library")
239
- # @view.setRfunc(:getAll)
240
- #
241
- #elsif key == ":"
242
- # cmd = Command.read(@term, ":")
243
- # self.runCommand cmd
244
- #
245
- #elsif key == "q"
246
- # self.cleanup
247
- #end
248
-
249
- @view.control(key)
250
- end
251
- end
252
59
  end
@@ -1,60 +1,118 @@
1
1
  require 'socket'
2
- require_relative '../util/serializer'
2
+ require_relative '../util/util'
3
3
 
4
4
 
5
- #require_relative '../interface/pref/pref'
5
+ module Aniview
6
+ module Client
7
+ class AniClient
8
+ include Aniview::Util
9
+
10
+ # initializes a new AniClient @
11
+ #
12
+ # @param pref see preferences
13
+ #
14
+ # @return nil
15
+ #
16
+ def initialize(pref)
17
+ @pref = pref
18
+ end
6
19
 
7
- class AniClient
8
-
9
- def initialize(pref)
10
- @pref = pref
11
- # @pref = Pref.new if @pref == "no"
12
- end
13
-
14
- def connect
15
- begin
16
- TCPSocket.new 'localhost', @pref.get("daemon")["port"]
17
- rescue Errno::ECONNREFUSED
18
- return false
19
- end
20
- end
21
-
22
- def sendMsg msg
23
- begin
24
- s = connect
25
- return "offline" if s == false
26
- s.puts msg
27
- r = s.gets.chomp
28
- s.close
29
- return r
30
- rescue Errno::ECONNRESET
31
- return ""
20
+ # connects to aniview daemon
21
+ #
22
+ # @return [TCPSocket, false] false if unsuccessful
23
+ #
24
+ def connect
25
+ begin
26
+ TCPSocket.new 'localhost', @pref.get("daemon")["port"]
27
+ rescue Errno::ECONNREFUSED
28
+ return false
29
+ end
30
+ end
31
+
32
+ # sends message to aniview daemon
33
+ #
34
+ # @param msg the message to send
35
+ #
36
+ # @return the daemons response, or "" if there is an error. If the
37
+ # daemon is offline, "offline" is returned
38
+ #
39
+ def sendMsg msg
40
+ begin
41
+ s = connect
42
+ return "offline" if s == false
43
+ s.puts msg
44
+ r = s.gets.chomp
45
+ s.close
46
+ return r
47
+ rescue Errno::ECONNRESET
48
+ return ""
49
+ end
50
+ end
51
+
52
+ # sends the message "quit" to the daemon
53
+ #
54
+ # see #sendMsg
55
+ #
56
+ # @return "okay"
57
+ #
58
+ def stopDaemon
59
+ sendMsg "quit"
60
+ end
61
+
62
+ # sends the message "info" to the daemon
63
+ #
64
+ # see #sendMsg
65
+ #
66
+ # @return daemon info string including uptime and number of loops and
67
+ # matches
68
+ #
69
+ def info
70
+ sendMsg "info"
71
+ end
72
+
73
+ # sends the message "lastchecked" to the daemon
74
+ #
75
+ # see #sendMsg
76
+ #
77
+ # @return string of the last time the daemon checked the rss feed for
78
+ # new matches
79
+ #
80
+ def lastchecked
81
+ sendMsg "lastchecked"
82
+ end
83
+
84
+ # sends the message "items" to the daemon and decodes the serialized
85
+ # object using Util.decode_object
86
+ #
87
+ # see #sendMsg
88
+ #
89
+ # @return The items.
90
+ #
91
+ def getItems
92
+ Util.decode_object(sendMsg "items")
93
+ end
94
+
95
+ # sends the message "itemshash" to the daemon
96
+ #
97
+ # see #sendMsg
98
+ #
99
+ # @return item.cereal of all items
100
+ #
101
+ def getAllCereal
102
+ sendMsg "itemshash"
103
+ end
104
+
105
+ # checks if the server is online (sends message "up?" to the daemon)
106
+ #
107
+ # see #sendMsg
108
+ #
109
+ # @return [true, false]
110
+ #
111
+ def server?
112
+ return false unless sendMsg("up?") == "true"
113
+ return true
114
+ end
115
+
32
116
  end
33
117
  end
34
-
35
- def stopDaemon
36
- sendMsg "quit"
37
- end
38
-
39
- def info
40
- sendMsg "info"
41
- end
42
-
43
- def lastchecked
44
- sendMsg "lastchecked"
45
- end
46
-
47
- def getItems
48
- Serializer.d(sendMsg "items")
49
- end
50
-
51
- def getAllCereal
52
- sendMsg "itemshash"
53
- end
54
-
55
- def server?
56
- return false unless sendMsg("up?") == "true"
57
- return true
58
- end
59
-
60
118
  end