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
-
#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 21 22 23 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 11 def initialize(pref, mpvbridge) @pref = pref @mpvbridge = mpvbridge @empty_hash = { "empty" => AnimeFile.new( "empty" ) } @watch_log_tag = "♪" self.load index_anime end |
Instance Method Details
#addWatched(file) ⇒ Object
162 163 164 165 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 162 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
136 137 138 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 136 def getAll return @@local_anime.values end |
#getAllSeries ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 140 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
126 127 128 129 130 131 132 133 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 126 def getUnwatched 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
38 39 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 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 38 def index_anime(force: false, verbose: false) ret = {} (@pref.get("anime_locations").split(":")).each { |dir| dir = @pref.parseDir dir 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 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 self.save end |
#load ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 29 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
156 157 158 159 160 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 156 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 |
#makeHash(arr) ⇒ Object
convert an AnimeFile array to a hash structured like (string)parent => (AnimeFile array)[child0, child1, child2] and return it
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 89 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 ret.merge!( AnimeSeries.new( last_parent, ) => ) = [animefile] else << animefile end last_parent = this_parent } 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
83 84 85 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 83 def parent(file) return File.basename(File.dirname(file)) end |
#rmWatched(path = "zoz") ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 167 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
25 26 27 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 25 def save @pref.set "local_anime", Util.encode_object(@@local_anime) end |
#watch(file) ⇒ Object
run mpv
183 184 185 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 183 def watch(file) @mpvbridge.play file end |