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,18 +1,19 @@
1
1
  require_relative '../item'
2
2
 
3
- class PrefItem < Item
4
- def initialize(title, value, path_ = [])
5
- @path = path_
6
- @attr = {
7
- "t" => title,
8
- "v" => value,
9
- }
10
- end
3
+ module Aniview
4
+ module Interface
5
+ class PrefItem < Item
6
+ def initialize(title, value, path_ = [])
7
+ @path = path_
8
+ @attr = {
9
+ "t" => title,
10
+ "v" => value,
11
+ }
12
+ end
11
13
 
12
- def attributes
13
- return @attr
14
- end
15
- def path
16
- return @path
17
- end
18
- end
14
+ def path
15
+ return @path
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,94 +1,100 @@
1
1
  require 'fileutils'
2
2
 
3
3
  require_relative 'scheduleitem'
4
- require_relative '../../util/serializer'
4
+ require_relative '../../util/util'
5
5
 
6
- class Schedule
6
+ module Aniview
7
+ module Interface
8
+ class Schedule
7
9
 
8
- def initialize pref
9
- @pref = pref
10
- load
11
- end
12
-
13
- def empty?
14
- if @schedule == nil or @schedule.length == 0
15
- @schedule = [ScheduleItem.new("no schedule", "")]
16
- save
17
- end
18
- end
19
-
20
- def getAll
21
- empty?
22
- return @schedule
23
- end
24
-
25
- def getAllCereal
26
- r=""
27
- getAll.each { |si| r+=si.cereal }
28
- return r
29
- end
10
+ include Aniview::Util
30
11
 
31
- def mergeItems items
32
- items.each { |item|
33
- @schedule.each { |schedule_item|
34
- if item.id == schedule_item.id
35
- m = [schedule_item.attributes["m"], item.attributes["m"]]
36
- if m[0] != m[1]
37
- schedule_item.setmatched m[1]
38
- end
12
+ def initialize pref
13
+ @pref = pref
14
+ load
15
+ end
16
+
17
+ def empty?
18
+ if @schedule == nil or @schedule.length == 0
19
+ @schedule = [ScheduleItem.new("no schedule", "")]
20
+ save
39
21
  end
40
- }
41
- }
42
- save
43
- end
44
-
45
- def addItem item
46
- @schedule.delete_at 0 if @schedule[0].attributes["t"] == "no schedule"
22
+ end
23
+
24
+ def getAll
25
+ empty?
26
+ return @schedule
27
+ end
28
+
29
+ def getAllCereal
30
+ r=""
31
+ getAll.each { |si| r+=si.cereal }
32
+ return r
33
+ end
34
+
35
+ def mergeItems items
36
+ items.each { |item|
37
+ @schedule.each { |schedule_item|
38
+ if item.id == schedule_item.id
39
+ m = [schedule_item.attributes["m"], item.attributes["m"]]
40
+ if m[0] != m[1]
41
+ schedule_item.setmatched m[1]
42
+ end
43
+ end
44
+ }
45
+ }
46
+ save
47
+ end
48
+
49
+ def addItem item
50
+ @schedule.delete_at 0 if @schedule[0].attributes["t"] == "no schedule"
51
+
52
+ new_item = ScheduleItem.new(item, @pref.get("airing_dir"))
53
+
54
+ FileUtils.mkdir_p @pref.parseDir new_item.attributes["p"]
55
+
56
+ @schedule << new_item
57
+
58
+ save
59
+ end
60
+
61
+ def editItem loc, val
62
+ old_dir = @pref.parseDir @schedule[loc].attributes["p"]
63
+ @schedule[loc].setTitle val
64
+ new_dir = @pref.parseDir @schedule[loc].attributes["p"]
65
+
66
+ FileUtils.mv old_dir, new_dir unless old_dir == new_dir
67
+
68
+ save
69
+ end
70
+
71
+ def removeItem loc
72
+ @schedule.delete_at loc
73
+ save
74
+ end
75
+
76
+ def save
77
+ @pref.set "schedule", (Util.encode_object @schedule)
78
+ end
79
+
80
+ def load
81
+ @pref.load
82
+ raw = @pref.get "schedule"
83
+ if not raw == nil and raw.class == String
84
+ @schedule = Util.decode_object raw
85
+ else
86
+ empty?
87
+ end
88
+ end
89
+
90
+ def makeHash(arr)
91
+ ret = {}
92
+ arr.each{ |t|
93
+ ret.merge!(t => t)
94
+ }
95
+ return ret
96
+ end
47
97
 
48
- new_item = ScheduleItem.new(item, @pref.get("airing_dir"))
49
-
50
- FileUtils.mkdir_p @pref.parseDir new_item.attributes["p"]
51
-
52
- @schedule << new_item
53
-
54
- save
55
- end
56
-
57
- def editItem loc, val
58
- old_dir = @pref.parseDir @schedule[loc].attributes["p"]
59
- @schedule[loc].setTitle val
60
- new_dir = @pref.parseDir @schedule[loc].attributes["p"]
61
-
62
- FileUtils.mv old_dir, new_dir unless old_dir == new_dir
63
-
64
- save
65
- end
66
-
67
- def removeItem loc
68
- @schedule.delete_at loc
69
- save
70
- end
71
-
72
- def save
73
- @pref.set "schedule", (Serializer.e @schedule)
74
- end
75
-
76
- def load
77
- @pref.load
78
- raw = @pref.get "schedule"
79
- if not raw == nil and raw.class == String
80
- @schedule = Serializer.d raw
81
- else
82
- empty?
83
98
  end
84
99
  end
85
-
86
- def makeHash(arr)
87
- ret = {}
88
- arr.each{ |t|
89
- ret.merge!(t => t)
90
- }
91
- return ret
92
- end
93
-
94
100
  end
@@ -1,56 +1,59 @@
1
1
  require_relative '../item'
2
2
  require 'securerandom'
3
3
 
4
- class ScheduleItem < Item
5
-
6
- def initialize(title, dir)
7
- @dirpath = dir
8
- @basepath = escapePath title
9
-
10
- @attr = {
11
- "t" => title,
12
- "f" => title[0..4] + "…",
13
- "r" => title,
14
- "p" => @dirpath + @basepath,
15
- "m" => "never"
16
- }
17
-
18
- @lastseen = 0
19
- @id = SecureRandom.uuid
20
- end
21
-
22
- def updataDir nd
23
- @dirpath = nd
24
- @attr["p"] = nd + @basepath
25
- end
26
-
27
- def escapePath path
28
- path_ = path.gsub(":", "_")
29
- path_.gsub("/", ":")
30
- end
31
-
32
- def setTitle newtitle
33
- @attr["t"] = newtitle
34
- @attr["f"] = newtitle[0..4] + "…"
35
- @attr["p"] = @dirpath + escapePath(newtitle)
36
- end
37
-
38
- def setRegexp regexp
39
- @attr["r"] = regexp
40
- end
41
-
42
- def setSeen
43
- @lastseen = Time.now.to_s
44
- @attr["m"] = @lastseen
45
- end
46
-
47
- def setmatched date
48
- @attr["m"] = date
49
- end
50
-
51
- def id
52
- id = SecureRandom.uuid if @id == nil
53
- @id
4
+ module Aniview
5
+ module Interface
6
+ class ScheduleItem < Item
7
+ def initialize(title, dir)
8
+ @dirpath = dir
9
+ @basepath = escapePath title
10
+
11
+ @attr = {
12
+ "t" => title,
13
+ "f" => title[0..4] + "…",
14
+ "r" => title,
15
+ "p" => @dirpath + @basepath,
16
+ "m" => "never"
17
+ }
18
+
19
+ @lastseen = 0
20
+ @id = SecureRandom.uuid
21
+ end
22
+
23
+ def updataDir nd
24
+ @dirpath = nd
25
+ @attr["p"] = nd + @basepath
26
+ end
27
+
28
+ def escapePath path
29
+ path_ = path.gsub(":", "_")
30
+ path_.gsub("/", ":")
31
+ end
32
+
33
+ def setTitle newtitle
34
+ @attr["t"] = newtitle
35
+ @attr["f"] = newtitle[0..4] + "…"
36
+ @attr["p"] = @dirpath + escapePath(newtitle)
37
+ end
38
+
39
+ def setRegexp regexp
40
+ @attr["r"] = regexp
41
+ end
42
+
43
+ def setSeen
44
+ @lastseen = Time.now.to_s
45
+ @attr["m"] = @lastseen
46
+ end
47
+
48
+ def setmatched date
49
+ @attr["m"] = date
50
+ end
51
+
52
+ def id
53
+ id = SecureRandom.uuid if @id == nil
54
+ @id
55
+ end
56
+
57
+ end
54
58
  end
55
-
56
59
  end
@@ -1,118 +1,121 @@
1
1
  require 'simple-rss'
2
2
  require 'open-uri'
3
3
 
4
- require_relative "../../util/stringhelp"
5
4
  require_relative "../schedule/scheduleitem"
6
5
 
7
-
8
- class Subscription
9
- def initialize pref, schedule, delugec, client
10
- @c = client
11
- @pref = pref
12
- @schedule = schedule
13
- @delugec = delugec
14
- end
15
-
16
- def log s
17
- puts "#{Time.now.to_s} [subscription] " + s
18
- end
19
-
20
- def checkDaemon
21
- if @c.server?
22
- "daemon up"
23
- else
24
- "daemon down"
25
- end
26
- end
27
-
28
- def getLastChecked
29
- @c.lastchecked
30
- end
31
-
32
- def syncMatches
33
- @schedule.mergeItems @c.getItems
34
- end
35
-
36
- def updateFeed
37
- begin
38
- @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"])
39
-
40
- rescue SocketError
41
- @rss = nil
42
-
43
- #rescue
44
- # @rss = nil
45
-
46
- end
47
- end
48
-
49
- def feed
50
- @rss
51
- end
52
-
53
- def match regexp, verbose=false
54
- re = Regexp.new regexp
55
- matches = []
56
- @rss.items.each{ |item|
57
- #log "-> checking against #{item[:title]}" if verbose
58
- re.match item[:title] { matches << item }
59
- }
60
- return matches
61
- end
62
-
63
- def matchAll (verbose: false)
64
- updateFeed if @rss == nil
65
- return [] if @rss == nil
66
-
67
- log "matching all" if verbose
68
-
69
- total_matches = 0
70
- getAll.each { |subs|
71
- log "matching #{subs.attributes["r"]}" if verbose
72
- matches = match subs.attributes["r"], verbose
73
- log "found #{matches.length} matches" if verbose
74
- log "#{matches}" if verbose
75
-
76
- if matches.length >= 1
77
-
78
- downloaddir = @pref.parseDir(subs.attributes["p"]) + "/"
79
- newfile = downloaddir + matches[0][:title]
80
-
81
- next if File.exist? newfile
82
- log "set download dir to #{newfile}" if verbose
83
- s = @delugec.addTorrent matches[0][:link], @pref.parseDir(subs.attributes["p"]), verbose: true
84
- log "adding torrent, status #{s}" if verbose
85
- subs.setSeen if s
6
+ module Aniview
7
+ module Interface
8
+ class Subscription
9
+ def initialize pref, schedule, delugec, client
10
+ @c = client
11
+ @pref = pref
12
+ @schedule = schedule
13
+ @delugec = delugec
14
+ end
15
+
16
+ def log s
17
+ puts "#{Time.now.to_s} [subscription] " + s
18
+ end
19
+
20
+ def checkDaemon
21
+ if @c.server?
22
+ "daemon up"
23
+ else
24
+ "daemon down"
25
+ end
26
+ end
27
+
28
+ def getLastChecked
29
+ @c.lastchecked
30
+ end
31
+
32
+ def syncMatches
33
+ @schedule.mergeItems @c.getItems
34
+ end
35
+
36
+ def updateFeed
37
+ begin
38
+ @rss = SimpleRSS.parse open(@pref.get("rss_feed")["url"])
39
+
40
+ rescue SocketError
41
+ @rss = nil
42
+
43
+ #rescue
44
+ # @rss = nil
45
+
46
+ end
47
+ end
48
+
49
+ def feed
50
+ @rss
51
+ end
52
+
53
+ def match regexp, verbose=false
54
+ re = Regexp.new regexp
55
+ matches = []
56
+ @rss.items.each{ |item|
57
+ #log "-> checking against #{item[:title]}" if verbose
58
+ re.match item[:title] { matches << item }
59
+ }
60
+ return matches
61
+ end
62
+
63
+ def matchAll (verbose: false)
64
+ updateFeed if @rss == nil
65
+ return [] if @rss == nil
66
+
67
+ log "matching all" if verbose
68
+
69
+ total_matches = 0
70
+ getAll.each { |subs|
71
+ log "matching #{subs.attributes["r"]}" if verbose
72
+ matches = match subs.attributes["r"], verbose
73
+ log "found #{matches.length} matches" if verbose
74
+ log "#{matches}" if verbose
75
+
76
+ if matches.length >= 1
77
+
78
+ downloaddir = @pref.parseDir(subs.attributes["p"]) + "/"
79
+ newfile = downloaddir + matches[0][:title]
80
+
81
+ next if File.exist? newfile
82
+ log "set download dir to #{newfile}" if verbose
83
+ s = @delugec.addTorrent matches[0][:link], @pref.parseDir(subs.attributes["p"]), verbose: true
84
+ log "adding torrent, status #{s}" if verbose
85
+ subs.setSeen if s
86
+ @schedule.save
87
+ total_matches+=1
88
+ end
89
+ }
90
+ log "match complete, #{total_matches} found" if verbose
91
+ return total_matches
92
+ end
93
+
94
+ def forceMatch
95
+ @mthread = Thread.new do
96
+ updateFeed
97
+ matchAll
98
+ end
99
+ end
100
+
101
+ def getAll
102
+ @schedule.getAll
103
+ end
104
+
105
+ def editItem loc, newval
106
+ @schedule.getAll[loc].setRegexp newval
86
107
  @schedule.save
87
- total_matches+=1
88
108
  end
89
- }
90
- log "match complete, #{total_matches} found" if verbose
91
- return total_matches
92
- end
93
-
94
- def forceMatch
95
- @mthread = Thread.new do
96
- updateFeed
97
- matchAll
109
+
110
+ def makeHash(arr)
111
+ ret = {}
112
+ arr.each{ |subs|
113
+ ret.merge!(subs => subs)
114
+ }
115
+ return ret
116
+ end
117
+
98
118
  end
99
119
  end
100
-
101
- def getAll
102
- @schedule.getAll
103
- end
104
-
105
- def editItem loc, newval
106
- @schedule.getAll[loc].setRegexp newval
107
- @schedule.save
108
- end
109
-
110
- def makeHash(arr)
111
- ret = {}
112
- arr.each{ |subs|
113
- ret.merge!(subs => subs)
114
- }
115
- return ret
116
- end
117
-
118
120
  end
121
+