aniview 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,17 +1,21 @@
1
- class Item
2
- def initialize()
3
- @attr = {}
4
- end
5
-
6
- def attributes
7
- return @attr
8
- end
9
-
10
- def cereal
11
- contents = ""
12
- @attr.each{ |a|
13
- contents += String(a[1])
14
- }
15
- return "cereal-"+contents
16
- end
17
- end
1
+ module Aniview
2
+ module Interface
3
+ class Item
4
+ def initialize()
5
+ @attr = {}
6
+ end
7
+
8
+ def attributes
9
+ return @attr
10
+ end
11
+
12
+ def cereal
13
+ contents = ""
14
+ @attr.each{ |a|
15
+ contents += String(a[1])
16
+ }
17
+ return "cereal-"+contents
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,80 +1,85 @@
1
1
  require 'mpv'
2
- require_relative '../../util/format'
2
+ require_relative '../../util/util'
3
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
4
+ module Aniview
5
+ module Interface
6
+ class MPVBridge
7
+ include Aniview::Util
8
+ def initialize pref
9
+ @pref = pref
10
+ connect
35
11
  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")
12
+
13
+ def quit!
14
+ @mpv.quit!
60
15
  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
- }
16
+
17
+ def connect
18
+ return unless @mpv == nil or @mpv.client.get_property("idle-active") == nil
19
+ @mpv = MPV::Session.new(user_args: @pref.get("mpv_args").split(" "))
20
+ end
21
+
22
+ def play file
23
+ connect
24
+ @playing_file = file
25
+ @mpv.client.command "loadfile", file.path
26
+ end
27
+
28
+ def playing?
29
+ @mpv.client.get_property("time-pos") != nil
30
+ end
31
+
32
+ def checkSetWatched percentage
33
+ if @playing_file != nil
34
+ swp = Integer(@pref.get "set_watched_percentage")
35
+ pct = Float(percentage)
36
+ if pct >= swp and not @playing_file.seen?
37
+ @playing_file.watch
38
+ end
39
+ end
40
+ end
41
+
42
+ def attributes
43
+ if playing?
44
+
45
+ r = {}
46
+ props = [
47
+ "time-pos",
48
+ "percent-pos",
49
+ "duration"
50
+ ]
51
+ props.each { |prop|
52
+ prop_val = @mpv.client.get_property(prop)
53
+ prop_val = 0 if prop_val == nil
54
+ r.merge!(
55
+ prop[0] => prop_val
56
+ )
57
+ }
58
+
59
+ if @playing_file != nil
60
+ r.merge!("n" => @playing_file.attributes["t"])
61
+ else
62
+ r.merge!("n" => "loading")
63
+ end
64
+
65
+ checkSetWatched r["p"]
66
+
67
+ {
68
+ "t" => Util.format_duration(r["t"]),
69
+ "p" => Util.format_progress(r["p"]),
70
+ "d" => Util.format_duration(r["d"]),
71
+ "n" => r["n"]
72
+ }
73
+ else
74
+ {
75
+ "t" => "0:00",
76
+ "p" => "0",
77
+ "d" => "0:00",
78
+ "n" => "."
79
+ }
80
+ end
81
+ end
82
+
77
83
  end
78
84
  end
79
-
80
85
  end
@@ -3,137 +3,140 @@ require 'json'
3
3
 
4
4
  require_relative 'prefitem'
5
5
  require_relative '../../view/color'
6
- require_relative '../../util/alogger'
7
6
 
8
- class Pref
9
- def initialize
10
-
11
- @home = Dir.home
12
- @conf = @home + "/.config/aniview"
13
-
14
- File.open(File.join(File.dirname(__FILE__), "/validate.json"), "r") {
15
- |f| @validate = JSON.parse(f.read)
16
- }
17
-
18
- FileUtils.mkdir_p(@conf) unless File.directory?(@conf)
19
-
20
- @pref_file = @conf + "/aniview.json"
21
-
22
- self.defaults if not File.exist?(@pref_file)
23
- self.load
24
- end
25
-
26
- def parseDir path
27
- path = path.gsub("$airing_dir", @pref["airing_dir"])
28
- path = path.gsub("$conf_dir", @pref["conf_dir"])
29
- path = path.gsub("~", Dir.home)
30
- return path
31
- end
32
-
33
- def defaults
34
- File.open(File.join(File.dirname(__FILE__), "/defaults.json"), "r") {|f| @pref = JSON.parse(f.read)}
35
- self.save
36
- end
37
-
38
- def set(s, val)
39
- trail = [s] if s.class == String
40
- trail = s if s.class == Array
41
- if valpref(trail, val, @validate)
42
- @pref = setpref(trail, val, @pref)
43
- end
44
-
45
- save
46
- end
47
-
48
- def setpref(trail, destination, map)
49
- if trail.length == 1
50
- map[trail[0]] = destination
51
- return map
52
- else
53
-
54
- blaze = trail[0]
55
- map[blaze] = setpref(trail[1..-1], destination, map[blaze])
56
-
57
- end
58
- return map
59
- end
60
-
61
- def valpref(trail, destination, map)
62
-
63
- if trail.length == 1
64
- skeys = [
65
- "space",
66
- "up",
67
- "down",
68
- "left",
69
- "right",
70
- "enter"
71
- ]
72
-
73
- case map[trail[0]]
74
- when "key"
75
- return false if destination.length != 1 and not skeys.include? destination
76
-
77
- when "path"
78
- destination.split(":").each { |d|
79
- return false if not Dir.exist?(parseDir d)
80
- }
81
-
82
- when "color"
83
- return false if not Color.method_defined? destination
84
-
85
- when "int"
86
- return false if not destination.scan(/\D/).empty? and destination.length > 1
87
-
88
- when "locked"
89
- return false
90
-
91
- end
92
-
93
- return true
94
-
95
- else
96
- blaze = trail[0]
97
- return valpref(trail[1..-1], destination, map[blaze])
98
- end
99
- end
100
-
101
- def get s
102
- return @pref[s] if @pref.key?(s)
103
- end
104
-
105
- def getAll
106
- ignore = {
107
- "local_anime" => true,
108
- "schedule" => true,
109
- }
110
-
111
- r = {}
112
- @pref.each{ |item|
113
- next if ignore.key? item[0]
114
- title = item[0]
115
- if item[1].class == String
116
- val = item[1]
117
- elsif item[1].class == Array
118
- val = item[1].join(":")
119
- elsif item[1].class == Hash
120
- item[1].each { |subitem|
121
- subtitle = title + "_" + subitem[0]
122
- subval = subitem[1]
123
- r.merge!(PrefItem.new(subtitle, subval, []) => [PrefItem.new("", "", [item[0], subitem[0]])])
124
- }
125
- next
126
- end
127
- r.merge!(PrefItem.new(title, val, []) => [ PrefItem.new("", "", [item[0]]) ] )
128
- }
129
- return r
130
- end
131
-
132
- def save
133
- File.open(@pref_file, "w") { |f| f.write(JSON.pretty_generate(@pref)) }
134
- end
135
-
136
- def load
137
- File.open(@pref_file, "r") {|f| @pref = JSON.parse(f.read)}
138
- end
7
+ module Aniview
8
+ module Interface
9
+ class Pref
10
+ def initialize
11
+
12
+ @home = Dir.home
13
+ @conf = @home + "/.config/aniview"
14
+
15
+ File.open(File.join(File.dirname(__FILE__), "/validate.json"), "r") {
16
+ |f| @validate = JSON.parse(f.read)
17
+ }
18
+
19
+ FileUtils.mkdir_p(@conf) unless File.directory?(@conf)
20
+
21
+ @pref_file = @conf + "/aniview.json"
22
+
23
+ self.defaults if not File.exist?(@pref_file)
24
+ self.load
25
+ end
26
+
27
+ def parseDir path
28
+ path = path.gsub("$airing_dir", @pref["airing_dir"])
29
+ path = path.gsub("$conf_dir", @pref["conf_dir"])
30
+ path = path.gsub("~", Dir.home)
31
+ return path
32
+ end
33
+
34
+ def defaults
35
+ File.open(File.join(File.dirname(__FILE__), "/defaults.json"), "r") {|f| @pref = JSON.parse(f.read)}
36
+ self.save
37
+ end
38
+
39
+ def set(s, val)
40
+ trail = [s] if s.class == String
41
+ trail = s if s.class == Array
42
+ if valpref(trail, val, @validate)
43
+ @pref = setpref(trail, val, @pref)
44
+ end
45
+
46
+ save
47
+ end
48
+
49
+ def setpref(trail, destination, map)
50
+ if trail.length == 1
51
+ map[trail[0]] = destination
52
+ return map
53
+ else
54
+
55
+ blaze = trail[0]
56
+ map[blaze] = setpref(trail[1..-1], destination, map[blaze])
57
+
58
+ end
59
+ return map
60
+ end
61
+
62
+ def valpref(trail, destination, map)
63
+
64
+ if trail.length == 1
65
+ skeys = [
66
+ "space",
67
+ "up",
68
+ "down",
69
+ "left",
70
+ "right",
71
+ "enter"
72
+ ]
73
+
74
+ case map[trail[0]]
75
+ when "key"
76
+ return false if destination.length != 1 and not skeys.include? destination
77
+
78
+ when "path"
79
+ destination.split(":").each { |d|
80
+ return false if not Dir.exist?(parseDir d)
81
+ }
82
+
83
+ when "color"
84
+ return false if not Aniview::View::Color.respond_to? destination
85
+
86
+ when "int"
87
+ return false if not destination.scan(/\D/).empty? and destination.length > 1
88
+
89
+ when "locked"
90
+ return false
91
+
92
+ end
93
+
94
+ return true
95
+
96
+ else
97
+ blaze = trail[0]
98
+ return valpref(trail[1..-1], destination, map[blaze])
99
+ end
100
+ end
101
+
102
+ def get s
103
+ return @pref[s] if @pref.key?(s)
104
+ end
105
+
106
+ def getAll
107
+ ignore = {
108
+ "local_anime" => true,
109
+ "schedule" => true,
110
+ }
111
+
112
+ r = {}
113
+ @pref.each{ |item|
114
+ next if ignore.key? item[0]
115
+ title = item[0]
116
+ if item[1].class == String
117
+ val = item[1]
118
+ elsif item[1].class == Array
119
+ val = item[1].join(":")
120
+ elsif item[1].class == Hash
121
+ item[1].each { |subitem|
122
+ subtitle = title + "_" + subitem[0]
123
+ subval = subitem[1]
124
+ r.merge!(PrefItem.new(subtitle, subval, []) => [PrefItem.new("", "", [item[0], subitem[0]])])
125
+ }
126
+ next
127
+ end
128
+ r.merge!(PrefItem.new(title, val, []) => [ PrefItem.new("", "", [item[0]]) ] )
129
+ }
130
+ return r
131
+ end
132
+
133
+ def save
134
+ File.open(@pref_file, "w") { |f| f.write(JSON.pretty_generate(@pref)) }
135
+ end
136
+
137
+ def load
138
+ File.open(@pref_file, "r") {|f| @pref = JSON.parse(f.read)}
139
+ end
140
+ end
141
+ end
139
142
  end