aniview 2.1.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,52 +7,36 @@ module Aniview
7
7
  module Interface
8
8
  class AnimeSeries < Item
9
9
  include Aniview::Util
10
- def initialize(_dir, children)
11
- @path = _dir
12
- @children = children
13
-
14
- dur = getDuration
15
- size = getSize
16
-
17
- @attr = {
18
- "t" => String(@path),
19
- "c" => String(@children.length),
20
- "d" => dur,
21
- "D" => Util.format_duration(dur),
22
- "s" => size,
23
- "S" => Util.format_size(size),
24
- }
25
- end
26
- def getDuration
27
- dur = 0
28
- @children.each{ |child|
29
- dur += child.attributes["d"]
30
- }
31
- return dur
32
- end
33
-
34
- def getSize
35
- size = 0
36
- @children.each{ |child|
37
- size += child.attributes["s"]
38
- }
39
- return size
40
- end
41
-
42
- def oldestChild
43
- oldest = DateTime.now.strftime('%Q')
44
- @children.each{ |child|
45
-
46
- }
47
- end
48
-
49
- def title
50
- return @path
51
- end
10
+
11
+ def initialize(path, children = [])
12
+ @path = path
13
+
14
+ @attr = {
15
+ "t" => String(@path),
16
+ "c" => 0,
17
+ "d" => 0,
18
+ "s" => 0,
19
+ }
20
+
21
+ @children = children
22
+ @children.each { |c| self + c }
23
+ end
24
+
25
+ def + af
26
+ @attr["d"] += af.attr["d"]
27
+ @attr["D"] = Util.format_duration @attr["d"]
28
+ @attr["s"] += af.attr["s"]
29
+ @attr["S"] = Util.format_size @attr["s"]
30
+ @attr["c"] += 1
31
+ end
32
+
33
+ def title
34
+ return @path
35
+ end
52
36
 
53
- def attributes
54
- return @attr
55
- end
37
+ def attributes
38
+ return @attr
39
+ end
56
40
  end
57
41
  end
58
42
  end
@@ -0,0 +1,11 @@
1
+ class Bridge
2
+
3
+ def make_hash
4
+
5
+ end
6
+
7
+ def items
8
+
9
+ end
10
+
11
+ end
@@ -3,11 +3,11 @@ require_relative 'torrentitem'
3
3
 
4
4
  module Aniview
5
5
  module Interface
6
- class DelugeC
7
-
6
+
7
+ class DelugeC < Bridge
8
+
8
9
  def initialize pref
9
10
  @pref = pref
10
-
11
11
  host = @pref.get("deluge_config")["host"]
12
12
  login = @pref.get("deluge_config")["login"]
13
13
  password = @pref.get("deluge_config")["password"]
@@ -32,7 +32,7 @@ module Aniview
32
32
  connect
33
33
 
34
34
  end
35
-
35
+
36
36
  def getStatus
37
37
  @status
38
38
  end
@@ -62,7 +62,7 @@ module Aniview
62
62
  File.open(Dir.home + "/.config/deluge/auth") { |f| f.read }.split(":")
63
63
  end
64
64
 
65
- def getTorrents
65
+ def items
66
66
  connect unless @connected
67
67
  return {} unless @connected
68
68
 
@@ -108,7 +108,7 @@ module Aniview
108
108
  #"tracker_host"
109
109
  ]
110
110
 
111
- return @client.core.get_torrents_status({}, tkeys)
111
+ makeHash @client.core.get_torrents_status({}, tkeys)
112
112
  end
113
113
 
114
114
  def toggleTorrent torrentItem
@@ -132,16 +132,22 @@ module Aniview
132
132
  begin
133
133
  tid = @client.core.add_torrent_magnet(mag, {"download_location": loc})
134
134
  rescue Deluge::Rpc::Connection::InvokeTimeoutError
135
- puts "[delugec] Error: timeout error" if verbose
135
+ #puts "[delugec] Error: timeout error" if verbose
136
136
  tid = nil
137
137
  rescue Errno::EPIPE
138
- puts "[delugec] Error: Errno::EPIPE" if verbose
138
+ #puts "[delugec] Error: Errno::EPIPE" if verbose
139
139
  tid = nil
140
140
  end
141
- p tid
142
141
  return true if tid.class == String and tid.length > 1
142
+ addTorrentCli mag, loc
143
143
  return false
144
144
  end
145
+
146
+ def addTorrentCli mag, loc
147
+ cli_tool = @pref.get("deluge_config")["cli_executable"]
148
+ command = "add #{mag} -p #{Shellwords.escape loc}"
149
+ result = %x(#{cli_tool} '#{command}')
150
+ end
145
151
 
146
152
  def makeHash(arr)
147
153
  ret = {}
@@ -157,7 +163,7 @@ module Aniview
157
163
  )
158
164
  ret.merge!(torrent => torrent)
159
165
  }
160
- return ret
166
+ ret
161
167
  end
162
168
 
163
169
  end
@@ -1,6 +1,9 @@
1
1
  module Aniview
2
2
  module Interface
3
3
  class Item
4
+
5
+ attr_accessor :attr
6
+
4
7
  def initialize()
5
8
  @attr = {}
6
9
  end
@@ -1,20 +1,47 @@
1
1
  require 'mpv'
2
2
  require_relative '../../util/util'
3
+ require 'logger'
3
4
 
4
5
  module Aniview
5
6
  module Interface
6
7
  class MPVBridge
8
+
7
9
  include Aniview::Util
10
+
11
+ include Observable
12
+
13
+ attr_accessor :playing
14
+ attr_accessor :what_changed
15
+
8
16
  def initialize pref
9
17
  @pref = pref
10
18
  @mpv_enabled = true
19
+ @logger = Logger.new('mpv.log')
20
+ @logger.level = Logger::DEBUG
11
21
  connect
22
+ @what_changed = ""
23
+ @playing = false
12
24
  end
13
-
25
+
26
+ def event_handler event
27
+ case event
28
+ when "start-file"
29
+ @playing = true
30
+ @what_changed = "playing_status"
31
+ changed
32
+ notify_observers
33
+ when "end-file"
34
+ @playing = false
35
+ @what_changed = "playing_status"
36
+ changed
37
+ notify_observers
38
+ end
39
+ end
40
+
14
41
  def quit!
15
42
  @mpv.quit! unless @mpv == nil
16
43
  end
17
-
44
+
18
45
  def connect
19
46
  return unless @mpv_enabled
20
47
  return unless @mpv == nil or @mpv.client.get_property("idle-active") == nil
@@ -22,6 +49,7 @@ module Aniview
22
49
  @mpv_enabled = false
23
50
  begin
24
51
  @mpv = MPV::Session.new(user_args: @pref.get("mpv_args").split(" "))
52
+ @mpv.callbacks << MPV::Callback.new(self, :event_handler)
25
53
  rescue MPV::MPVNotAvailableError
26
54
  rescue MPV::MPVUnsupportedFlagError
27
55
  else
@@ -34,11 +62,11 @@ module Aniview
34
62
  connect
35
63
  @playing_file = file
36
64
  @mpv.client.command "loadfile", file.path
65
+ @playing = true
37
66
  end
38
67
 
39
68
  def playing?
40
- return false unless @mpv_enabled
41
- @mpv.client.get_property("time-pos") != nil
69
+ @playing
42
70
  end
43
71
 
44
72
  def checkSetWatched percentage
@@ -47,13 +75,15 @@ module Aniview
47
75
  pct = Float(percentage)
48
76
  if pct >= swp and not @playing_file.seen?
49
77
  @playing_file.watch
78
+ @what_changed = "local_anime"
79
+ changed
80
+ notify_observers
50
81
  end
51
82
  end
52
83
  end
53
84
 
54
85
  def attributes
55
86
  if playing?
56
-
57
87
  r = {}
58
88
  props = [
59
89
  "time-pos",
@@ -80,14 +110,14 @@ module Aniview
80
110
  "t" => Util.format_duration(r["t"]),
81
111
  "p" => Util.format_progress(r["p"]),
82
112
  "d" => Util.format_duration(r["d"]),
83
- "n" => r["n"]
113
+ "n" => r["n"],
84
114
  }
85
115
  else
86
116
  {
87
- "t" => "0:00",
117
+ "t" => "-",
88
118
  "p" => "0",
89
119
  "d" => "0:00",
90
- "n" => "."
120
+ "n" => ".",
91
121
  }
92
122
  end
93
123
  end
@@ -71,24 +71,25 @@
71
71
  "title" : " %t",
72
72
  "parent" : " %t@ %v "
73
73
  },
74
- "format_status" : " %n - %t/%d@ %p ",
74
+ "format_status" : " %n - %t/%d@ %p\\% ",
75
75
  "deluge_config" :
76
76
  {
77
77
  "host" : "localhost",
78
78
  "port" : "58846",
79
79
  "login" : "",
80
- "password" : ""
80
+ "password" : "",
81
+ "cli_executable" : "/Applications/Deluge.app/Contents/MacOS/deluge-console"
81
82
  },
82
83
  "rss_feed" :
83
84
  {
84
- "url" : "https://nyaa.pantsu.cat/feed?c=3_5&s=1&max=100&userID=0&q=",
85
- "refresh_interval" : "150"
85
+ "url" : "https://www.tokyotosho.info/rss.php?filter=1&minMB=100&maxMB=500&reversepolarity=1&entries=300",
86
+ "refresh_interval" : "300"
86
87
  },
87
88
  "daemon" :
88
89
  {
89
90
  "port" : "21312"
90
91
  },
91
- "set_watched_percentage" : "80",
92
+ "set_watched_percentage" : "80",
92
93
  "log_file" : "$conf_dir/aw.log",
93
94
  "daemon_log_file" : "$conf_dir/server.log",
94
95
  "watch_log" : "$conf_dir/watchlog",
@@ -3,12 +3,15 @@ require 'json'
3
3
 
4
4
  require_relative 'prefitem'
5
5
  require_relative '../../view/color'
6
+ require_relative '../bridge'
6
7
 
7
8
  module Aniview
8
9
  module Interface
9
- class Pref
10
+ class Pref < Bridge
11
+
12
+ include Observable
13
+
10
14
  def initialize
11
-
12
15
  @home = Dir.home
13
16
  @conf = @home + "/.config/aniview"
14
17
 
@@ -17,11 +20,13 @@ module Aniview
17
20
  }
18
21
 
19
22
  FileUtils.mkdir_p(@conf) unless File.directory?(@conf)
20
-
23
+
21
24
  @pref_file = @conf + "/aniview.json"
25
+
26
+ @saving = false
22
27
 
23
- self.defaults if not File.exist?(@pref_file)
24
- self.load
28
+ defaults should_save: true if not File.exist?(@pref_file)
29
+ load
25
30
  end
26
31
 
27
32
  def parseDir path
@@ -32,9 +37,9 @@ module Aniview
32
37
  return path
33
38
  end
34
39
 
35
- def defaults(should_save:true)
40
+ def defaults(should_save:false)
36
41
  File.open(File.join(File.dirname(__FILE__), "/defaults.json"), "r") {|f| @pref = JSON.parse(f.read)}
37
- self.save if should_save
42
+ save if should_save
38
43
  end
39
44
 
40
45
  def set(s, val)
@@ -42,9 +47,10 @@ module Aniview
42
47
  trail = s if s.class == Array
43
48
  if valpref(trail, val, @validate)
44
49
  @pref = setpref(trail, val, @pref)
50
+ save
51
+ changed
52
+ notify_observers
45
53
  end
46
-
47
- save
48
54
  end
49
55
 
50
56
  def setpref(trail, destination, map)
@@ -103,13 +109,13 @@ module Aniview
103
109
  def get s
104
110
  return @pref[s] if @pref.key?(s)
105
111
  end
106
-
107
- def getAll
112
+
113
+ def items
108
114
  ignore = {
109
115
  "local_anime" => true,
110
116
  "schedule" => true,
111
117
  }
112
-
118
+
113
119
  r = {}
114
120
  @pref.each{ |item|
115
121
  next if ignore.key? item[0]
@@ -130,17 +136,35 @@ module Aniview
130
136
  }
131
137
  return r
132
138
  end
133
-
139
+
134
140
  def save
141
+ @saving = true
135
142
  File.open(@pref_file, "w") { |f| f.write(JSON.pretty_generate(@pref)) }
143
+ @saving = false
144
+ end
145
+
146
+ def saving?
147
+ @saving
136
148
  end
137
149
 
138
150
  def load
139
151
  begin
140
- File.open(@pref_file, "r") {|f| @pref = JSON.parse(f.read)}
141
- #rescue JSON::ParserError
142
- #defaults should_save: false
152
+ #json = ""
153
+ json = File.open(@pref_file, "r") {|f| f.read}
154
+ #puts json
155
+ if json == ""
156
+ #puts "going to defaults"
157
+ defaults
158
+ return
159
+ end
160
+ @pref = JSON.parse json
161
+ rescue JSON::ParserError
162
+ puts "severe! your preference file #{@pref_file} is corrupted,"
163
+ puts "please fix the file or delete it to restore defaults"
164
+ exit
143
165
  end
166
+ changed
167
+ notify_observers
144
168
  end
145
169
  end
146
170
  end
@@ -78,7 +78,8 @@
78
78
  "host" : "any",
79
79
  "port" : "int",
80
80
  "login" : "any",
81
- "password" : "any"
81
+ "password" : "any",
82
+ "cli_executable" : "any"
82
83
  },
83
84
  "rss_feed" :
84
85
  {
@@ -2,13 +2,18 @@ require 'fileutils'
2
2
 
3
3
  require_relative 'scheduleitem'
4
4
  require_relative '../../util/util'
5
+ require_relative '../bridge'
5
6
 
6
7
  module Aniview
7
8
  module Interface
8
- class Schedule
9
+ class Schedule < Bridge
9
10
 
10
11
  include Aniview::Util
11
12
 
13
+ include Observable
14
+
15
+ attr_accessor :schedule
16
+
12
17
  def initialize pref
13
18
  @pref = pref
14
19
  load
@@ -21,20 +26,20 @@ module Aniview
21
26
  end
22
27
  end
23
28
 
24
- def getAll
29
+ def items
25
30
  empty?
26
- return @schedule
31
+ @schedule.map{ |t| [t,t] }.to_h
27
32
  end
28
33
 
29
34
  def getAllCereal
30
35
  r=""
31
36
  getAll.each { |si| r+=si.cereal }
32
- return r
37
+ r
33
38
  end
34
39
 
35
- def mergeItems items
36
- items.each { |item|
37
- @schedule.each { |schedule_item|
40
+ def mergeItems _items
41
+ _items.each { |item|
42
+ @schedule.each { |schedule_item|
38
43
  if item.id == schedule_item.id
39
44
  m = [schedule_item.attributes["m"], item.attributes["m"]]
40
45
  if m[0] != m[1]
@@ -63,7 +68,7 @@ module Aniview
63
68
  @schedule[loc].setTitle val
64
69
  new_dir = @pref.parseDir @schedule[loc].attributes["p"]
65
70
 
66
- FileUtils.mv old_dir, new_dir unless old_dir == new_dir
71
+ FileUtils.mv old_dir, new_dir unless old_dir.downcase == new_dir.downcase
67
72
 
68
73
  save
69
74
  end
@@ -75,10 +80,12 @@ module Aniview
75
80
 
76
81
  def save
77
82
  @pref.set "schedule", (Util.encode_object @schedule)
83
+ changed
84
+ notify_observers
78
85
  end
79
86
 
80
87
  def load
81
- @pref.load
88
+ #@pref.load
82
89
  raw = @pref.get "schedule"
83
90
  if not raw == nil and raw.class == String
84
91
  @schedule = Util.decode_object raw
@@ -86,15 +93,7 @@ module Aniview
86
93
  empty?
87
94
  end
88
95
  end
89
-
90
- def makeHash(arr)
91
- ret = {}
92
- arr.each{ |t|
93
- ret.merge!(t => t)
94
- }
95
- return ret
96
- end
97
-
96
+
98
97
  end
99
98
  end
100
99
  end