aniview 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3997c84f2c7fe4c76932df56e2974b8e7fcdfdd
4
- data.tar.gz: de56d18cced70e4feb91ad1f54bbf6975eaaa761
3
+ metadata.gz: 2886da682b5b5671858688ae216011d2af04ed3a
4
+ data.tar.gz: b59ed72a1289d7a21eda2b4922674061702a267f
5
5
  SHA512:
6
- metadata.gz: e59457afc95892f3a5002bc9fa01d3433a39a831ea32c5382628939245c3f23e1125c829634f1760b830fc1f2edec1645c58ed9d2d43a30113ceb79060ff7a49
7
- data.tar.gz: c51ed7a61437b2ed9bc3c7a8ea02e4b7b52a04c788bcfedcaa5e8baa54af72025e4ed9d0e29459a2b54b47029650ae825ce07db620cbf0737473383f2ec71a3c
6
+ metadata.gz: c6943259e6c267341c73262ad702fb04bb489c46a88308127a7318b44aed913452a69c212a816cd9b5ac4761b5b1d436aa015708df78c91fe7879ec509c73eca
7
+ data.tar.gz: b5ff1b8ec8ca41dd1a85ca8771ff8ffeb2853a99fbf0469f55cf6f14a4252d4dbe2f097d352b308621a08621fd2929906046e754d0f8fa715f0946f67186ab79
data/bin/aniviewd ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'aniviewd'
5
+ rescue LoadError
6
+ require_relative '../lib/aniviewd' if File.exist?(File.join(File.dirname(__FILE__), '../lib/aniviewd.rb'))
7
+ end
8
+
9
+ unless defined? AniViewd
10
+ puts "cant find aniviewd library"
11
+ exit
12
+ end
13
+
14
+ av = AniViewd.new(ARGV)
15
+
16
+ process = fork do
17
+ av.run
18
+ end
19
+
20
+ Process.detach(process)
data/lib/aniview.rb CHANGED
@@ -11,12 +11,13 @@ require_relative 'aniview/view/delugemenu'
11
11
  require_relative 'aniview/view/prefmenu'
12
12
  require_relative 'aniview/view/schedulemenu'
13
13
  require_relative 'aniview/view/subscriptionmenu'
14
+ require_relative 'aniview/view/statusline'
14
15
 
15
16
  require_relative 'aniview/interface/animeio/animeio'
17
+ require_relative 'aniview/interface/mpv/mpvbridge'
16
18
  require_relative 'aniview/interface/deluge/delugec'
17
19
  require_relative 'aniview/interface/pref/pref'
18
20
  require_relative 'aniview/interface/subscription/subscription'
19
- require_relative 'aniview/interface/subscription/subscriptiondaemon'
20
21
  require_relative 'aniview/interface/schedule/schedule'
21
22
 
22
23
  require_relative 'aniview/util/alogger'
@@ -30,19 +31,31 @@ $stdout.sync = true
30
31
  class AniView
31
32
  def initialize
32
33
 
33
- @term = Term.new
34
+ @term = Term.new
34
35
 
35
- @pref = Pref.new
36
+ @pref = Pref.new
36
37
 
37
- $l = ALogger.new(@pref.parseDir(@pref.get "log_file"), false)
38
+ $l = ALogger.new(@pref.parseDir(@pref.get "log_file"), false)
38
39
 
39
- @aio = AnimeIO.new @pref
40
+ @mpvbridge = MPVBridge.new @pref
41
+
42
+ @aio = AnimeIO.new @pref, @mpvbridge
40
43
 
41
- @schedule = Schedule.new @pref
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
42
51
 
43
- @delugec = DelugeC.new(@pref)
52
+ #file = "/Users/lattis/anime/Tekkonkinkreet/Tekkonkinkreet.mkv"
53
+ #@mpvbridge.play file
44
54
 
45
- @c = AniClient.new @pref
55
+ #while true
56
+ # @statusline.draw
57
+ # sleep 1/45.0
58
+ #end
46
59
 
47
60
  @subscription = Subscription.new(@pref, @schedule, @delugec, @c)
48
61
 
@@ -57,11 +70,11 @@ class AniView
57
70
  end
58
71
 
59
72
  @aiomenu = AioMenu.new(
60
- refresh_function: :getAll,
73
+ refresh_function: :getUnwatched,
61
74
  interface: @aio,
62
- name: @pref.get("menu_titles")["library"],
75
+ name: @pref.get("menu_titles")["unwatched"],
63
76
  pref: @pref,
64
- format: "format_library",
77
+ format: "format_library_unwatched",
65
78
  term: @term
66
79
  )
67
80
  @prefmenu = PrefMenu.new(
@@ -109,7 +122,9 @@ class AniView
109
122
 
110
123
  def cleanup
111
124
  @mthread.exit if @mthread != nil
125
+ @statusthread.exit if @statusthread != nil
112
126
  @term.reset
127
+ @mpvbridge.quit!
113
128
  exit
114
129
  end
115
130
 
@@ -126,9 +141,21 @@ class AniView
126
141
  elsif cmd == "index"
127
142
  @aio.index_anime :force => true, :verbose => true
128
143
  @aiomenu.refresh
144
+ elsif cmd == "help"
145
+ print "\e[1;1H" + Color.white
146
+ puts "Help"
147
+ puts ""
148
+ else
149
+ print "\033[" + String(@term.rows) + ";1H" + Color.red + "error, unknown command"
150
+ @term.getKey
129
151
  end
130
152
  end
131
153
 
154
+ def changeView newView
155
+ @view = newView
156
+ @view.change_screen_size
157
+ end
158
+
132
159
  def run
133
160
 
134
161
  @view = @aiomenu
@@ -153,46 +180,71 @@ class AniView
153
180
  end
154
181
  end
155
182
 
183
+ @statusthread = Thread.new do
184
+ while true
185
+ if @shoulddraw
186
+ @statusline.draw
187
+ end
188
+ sleep 1/25.0
189
+ end
190
+ end
191
+
156
192
  while true
157
- @shoulddraw = true
158
- key = @term.getKey
159
- @shoulddraw = false
160
-
161
- if key == @pref.get("keybindings")["goto_unwatched"]
162
- @view = @aiomenu
163
- @view.setName(@pref.get("menu_titles")["unwatched"])
164
- @view.setFormat("format_library_unwatched")
165
- @view.setRfunc(:getUnwatched)
166
-
167
- elsif key == @pref.get("keybindings")["goto_library"]
168
- @view = @aiomenu
169
- @view.setName(@pref.get("menu_titles")["library"])
170
- @view.setFormat("format_library")
171
- @view.setRfunc(:getAll)
172
-
173
- elsif key == @pref.get("keybindings")["goto_torrents"]
174
- @view = @delugemenu
175
- @view.setName(@pref.get("menu_titles")["torrents"])
176
-
177
- elsif key == @pref.get("keybindings")["goto_preferences"]
178
- @view = @prefmenu
179
- @view.setName(@pref.get("menu_titles")["preferences"])
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
180
230
 
181
- elsif key == @pref.get("keybindings")["goto_schedule"]
182
- @view = @schedulemenu
183
- @view.setName(@pref.get("menu_titles")["schedule"])
184
231
 
185
- elsif key == @pref.get("keybindings")["goto_subscriptions"]
186
- @view = @subscriptionmenu
187
- @view.setName(@pref.get("menu_titles")["subscriptions"])
188
-
189
- elsif key == ":"
190
- cmd = Command.read(@term, ":")
191
- self.runCommand cmd
192
232
 
193
- elsif key == "q"
194
- self.cleanup
195
- end
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
196
248
 
197
249
  @view.control(key)
198
250
  end
@@ -1,4 +1,6 @@
1
1
  require 'socket'
2
+ require_relative '../util/serializer'
3
+
2
4
 
3
5
  #require_relative '../interface/pref/pref'
4
6
 
@@ -20,7 +22,7 @@ class AniClient
20
22
  def sendMsg msg
21
23
  begin
22
24
  s = connect
23
- return "" if s == false
25
+ return "offline" if s == false
24
26
  s.puts msg
25
27
  r = s.gets.chomp
26
28
  s.close
@@ -42,6 +44,14 @@ class AniClient
42
44
  sendMsg "lastchecked"
43
45
  end
44
46
 
47
+ def getItems
48
+ Serializer.d(sendMsg "items")
49
+ end
50
+
51
+ def getAllCereal
52
+ sendMsg "itemshash"
53
+ end
54
+
45
55
  def server?
46
56
  return false unless sendMsg("up?") == "true"
47
57
  return true
@@ -5,8 +5,9 @@ require_relative 'animeseries'
5
5
 
6
6
  class AnimeIO
7
7
 
8
- def initialize(pref)
8
+ def initialize(pref, mpvbridge)
9
9
  @pref = pref
10
+ @mpvbridge = mpvbridge
10
11
  @empty_hash = {
11
12
  "empty" => AnimeFile.new(
12
13
  "empty",
@@ -179,6 +180,6 @@ class AnimeIO
179
180
 
180
181
  #run mpv
181
182
  def watch(file)
182
- pid = spawn("#{@pref.get "watch_command"} '#{file}'")
183
+ @mpvbridge.play file
183
184
  end
184
185
  end
@@ -36,17 +36,17 @@ class DelugeC
36
36
  end
37
37
 
38
38
  def connect
39
+ @connected = false
40
+ @status = "error connecting"
39
41
  begin
40
- @status = "connected"
41
42
  @client.connect
42
- @connected = true
43
43
  rescue Deluge::Rpc::Connection::RPCError
44
- @status = "error connecting"
45
- @connected = false
44
+ @client.close
46
45
  rescue RuntimeError
47
- @status = "error connecting"
48
46
  @client.close
49
- @connected = false
47
+ else
48
+ @status = "connected"
49
+ @connected = true
50
50
  end
51
51
 
52
52
  @client.close unless @connected
@@ -121,14 +121,20 @@ class DelugeC
121
121
  @client.core.remove_torrent(id, withData)
122
122
  end
123
123
 
124
- def addTorrent mag, loc
124
+ def addTorrent mag, loc, verbose: false
125
125
  connect unless @connected
126
126
  return false unless @connected
127
+ puts "[delugec] connected!" if verbose
127
128
  begin
128
129
  tid = @client.core.add_torrent_magnet(mag, {"download_location": loc})
129
130
  rescue Deluge::Rpc::Connection::InvokeTimeoutError
131
+ puts "[delugec] Error: timeout error" if verbose
132
+ tid = nil
133
+ rescue Errno::EPIPE
134
+ puts "[delugec] Error: Errno::EPIPE" if verbose
130
135
  tid = nil
131
136
  end
137
+ p tid
132
138
  return true if tid.class == String and tid.length > 1
133
139
  return false
134
140
  end
@@ -0,0 +1,80 @@
1
+ require 'mpv'
2
+ require_relative '../../util/format'
3
+
4
+ class MPVBridge
5
+ def initialize pref
6
+ @pref = pref
7
+ connect
8
+ end
9
+
10
+ def quit!
11
+ @mpv.quit!
12
+ end
13
+
14
+ def connect
15
+ return unless @mpv == nil or @mpv.client.get_property("idle-active") == nil
16
+ @mpv = MPV::Session.new(user_args: @pref.get("mpv_args").split(" "))
17
+ end
18
+
19
+ def play file
20
+ connect
21
+ @playing_file = file
22
+ @mpv.client.command "loadfile", file.path
23
+ end
24
+
25
+ def playing?
26
+ @mpv.client.get_property("time-pos") != nil
27
+ end
28
+
29
+ def checkSetWatched percentage
30
+ if @playing_file != nil
31
+ swp = Integer(@pref.get "set_watched_percentage")
32
+ pct = Float(percentage)
33
+ if pct >= swp and not @playing_file.seen?
34
+ @playing_file.watch
35
+ end
36
+ end
37
+ end
38
+
39
+ def attributes
40
+ if playing?
41
+
42
+ r = {}
43
+ props = [
44
+ "time-pos",
45
+ "percent-pos",
46
+ "duration"
47
+ ]
48
+ props.each { |prop|
49
+ prop_val = @mpv.client.get_property(prop)
50
+ prop_val = 0 if prop_val == nil
51
+ r.merge!(
52
+ prop[0] => prop_val
53
+ )
54
+ }
55
+
56
+ if @playing_file != nil
57
+ r.merge!("n" => @playing_file.attributes["t"])
58
+ else
59
+ r.merge!("n" => "loading")
60
+ end
61
+
62
+ checkSetWatched r["p"]
63
+
64
+ {
65
+ "t" => Format.format_duration(r["t"]),
66
+ "p" => Format.format_progress(r["p"]),
67
+ "d" => Format.format_duration(r["d"]),
68
+ "n" => r["n"]
69
+ }
70
+ else
71
+ {
72
+ "t" => "0:00",
73
+ "p" => "0",
74
+ "d" => "0:00",
75
+ "n" => "."
76
+ }
77
+ end
78
+ end
79
+
80
+ end
@@ -47,14 +47,14 @@
47
47
  },
48
48
  "format_library_unwatched" :
49
49
  {
50
- "title" : " %t @ $q@ %D %S ",
50
+ "title" : " %t@ %D %S ",
51
51
  "parent" : " %t - %c@ %D %S ",
52
52
  "child" : " %t@ %D %S %r "
53
53
  },
54
54
  "format_torrents" :
55
55
  {
56
56
  "title" : " %t - %s",
57
- "parent" : " %n@ %p "
57
+ "parent" : " %n - %s@ %e %p\\% "
58
58
  },
59
59
  "format_schedule" :
60
60
  {
@@ -71,6 +71,7 @@
71
71
  "title" : " %t",
72
72
  "parent" : " %t@ %v "
73
73
  },
74
+ "format_status" : " %n - %t/%d@ %p ",
74
75
  "deluge_config" :
75
76
  {
76
77
  "host" : "localhost",
@@ -87,11 +88,12 @@
87
88
  {
88
89
  "port" : "21312"
89
90
  },
91
+ "set_watched_percentage" : "80",
90
92
  "log_file" : "$conf_dir/aw.log",
91
93
  "daemon_log_file" : "$conf_dir/server.log",
92
94
  "watch_log" : "$conf_dir/watchlog",
93
95
  "conf_dir" : "~/.config/aniview",
94
- "watch_command" : "mpv -alang jpn -slang eng -msg-level=all=fatal -ass",
96
+ "mpv_args" : "--alang=jpn --slang=eng",
95
97
  "local_anime" : null,
96
98
  "schedule" : []
97
99
  }