Class: Aniview::Interface::AnimeIO
- Inherits:
-
Object
- Object
- Aniview::Interface::AnimeIO
- Defined in:
- lib/aniview/interface/animeio/animeio.rb
Instance Method Summary collapse
- #addWatched(file) ⇒ Object
-
#getAll ⇒ Object
return an AnimeFile array of all mkvs in any dir specified in $pref.
- #getAllSeries ⇒ Object
-
#getUnwatched ⇒ Object
return the difference of getAired and getWatched.
- #index_anime(force: false, verbose: false) ⇒ Object
-
#initialize(pref, mpvbridge) ⇒ AnimeIO
constructor
A new instance of AnimeIO.
- #load ⇒ Object
- #logWatched(file) ⇒ Object
- #make_empty_hash ⇒ Object
-
#makeHash(arr) ⇒ Object
convert an AnimeFile array to a hash structured like (string)parent => (AnimeFile array)[child0, child1, child2] and return it.
-
#parent(file) ⇒ Object
returns the parent directory of a file.
- #rmWatched(path = "zoz") ⇒ Object
- #save ⇒ Object
-
#watch(file) ⇒ Object
run mpv.
Constructor Details
#initialize(pref, mpvbridge) ⇒ AnimeIO
Returns a new instance of AnimeIO.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 11 def initialize(pref, mpvbridge) @pref = pref @mpvbridge = mpvbridge @empty_hash = make_empty_hash @watch_log_tag = "♪" @dir_last_modified = {} self.load index_anime end |
Instance Method Details
#addWatched(file) ⇒ Object
187 188 189 190 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 187 def addWatched(file) @@local_anime[file].watch self.save end |
#getAll ⇒ Object
return an AnimeFile array of all mkvs in any dir specified in $pref
160 161 162 163 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 160 def getAll index_anime return @@local_anime.values end |
#getAllSeries ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 165 def getAllSeries arr = getAll last_parent = parent arr[0].path ret = [ last_parent ] arr.each { |animefile| this_parent = parent animefile.path if this_parent != last_parent ret << this_parent end last_parent = this_parent } return ret end |
#getUnwatched ⇒ Object
return the difference of getAired and getWatched
149 150 151 152 153 154 155 156 157 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 149 def getUnwatched index_anime ret = [] #puts @@local_anime @@local_anime.each{ |anime| ret << anime[1] if not anime[1].seen? } return ret end |
#index_anime(force: false, verbose: false) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 40 def index_anime(force: false, verbose: false) ret = {} made_changes = false (@pref.get("anime_locations").split(":")).each { |dir| dir = @pref.parseDir dir dir_mtime = File::Stat.new(dir).mtime if @dir_last_modified.key? dir if @dir_last_modified[dir] == dir_mtime #puts "skipping" next else @dir_last_modified[dir] = dir_mtime end else @dir_last_modified.merge!(dir => dir_mtime) end # puts "not skipping..." #p @dir_last_modified files = Dir.glob("#{dir}*/*.{mkv,avi,mp4}") + Dir.glob("#{dir}/*.{mkv,avi,mp4}") files.each { |file| puts "indexing #{file}" if verbose seen_this = false if @@local_anime != nil and @@local_anime.key?(file) seen_this = @@local_anime[file].seen? last_modified = File::Stat.new(file).mtime if not force or last_modified == @@local_anime[file].last_modified ret.merge!(file => @@local_anime[file]) next end end made_changes = true ret.merge!( file => AnimeFile.new( file, seen_this ) ) } } if @@local_anime != nil @@local_anime.merge!(ret) else @@local_anime = ret end pruned = {} @@local_anime.each{ |a| pruned.merge!(a[0] => a[1]) if File.exist? a[1].path } @@local_anime = pruned puts "made changes" if made_changes self.save if made_changes end |
#load ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 31 def load raw = @pref.get "local_anime" if not raw == nil and raw.class == String @@local_anime = Util.decode_object raw else @@local_anime = {} end end |
#logWatched(file) ⇒ Object
181 182 183 184 185 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 181 def logWatched(file) open(@pref.parseDir(@pref.get("watch_log")), 'a') do |f| f.puts %x(date).chomp + " ./" + File.basename(file) + " " + @watch_log_tag end end |
#make_empty_hash ⇒ Object
22 23 24 25 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 22 def make_empty_hash af = AnimeFile.new("empty") {AnimeSeries.new("empty", [af]) => [af]} end |
#makeHash(arr) ⇒ Object
convert an AnimeFile array to a hash structured like (string)parent => (AnimeFile array)[child0, child1, child2] and return it
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 109 def makeHash(arr) return @empty_hash if arr[0] == nil ret = {} = [] sarr = arr.sort_by {|s| s.path} last_parent = parent sarr[0].path (sarr).each { |animefile| this_parent = parent animefile.path if this_parent != last_parent = .sort_by { |a| a.title } ret.merge!( AnimeSeries.new( last_parent, ) => ) = [animefile] else << animefile end last_parent = this_parent } = .sort_by { |a| a.title } ret.merge!( AnimeSeries.new( parent(sarr[sarr.length - 1].path), ) => ) return Hash[ret.sort_by{ |a| a[0].title}] end |
#parent(file) ⇒ Object
returns the parent directory of a file
103 104 105 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 103 def parent(file) return File.basename(File.dirname(file)) end |
#rmWatched(path = "zoz") ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 192 def rmWatched(path = "zoz") if @@local_anime.key? path @@local_anime[path].unwatch return end r = [] @@local_anime.values.each_with_index{ |v, i| r << {Integer(v.seenOn) => @@local_anime.keys[i]} if v.seen? } return if r.length == 0 last_watched = (r.sort_by{ |h| h.keys.first}.reverse)[0].values[0] @@local_anime[last_watched].unwatch self.save end |
#save ⇒ Object
27 28 29 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 27 def save @pref.set "local_anime", Util.encode_object(@@local_anime) end |
#watch(file) ⇒ Object
run mpv
208 209 210 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 208 def watch(file) @mpvbridge.play file end |