Class: AnimeIO
- Inherits:
-
Object
- Object
- 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) ⇒ 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) ⇒ AnimeIO
Returns a new instance of AnimeIO.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 7 def initialize(pref) @pref = pref @empty_hash = { "empty" => AnimeFile.new( "empty", { "d" => 0, "s" => 0, "r" => "0x0", "a" => "n/a" } ) } @watch_log_tag = "♪" self.load index_anime end |
Instance Method Details
#addWatched(file) ⇒ Object
167 168 169 170 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 167 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
141 142 143 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 141 def getAll return @@local_anime.values end |
#getAllSeries ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 145 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
131 132 133 134 135 136 137 138 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 131 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
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 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 39 def index_anime(force: false, verbose: false) ret = {} (@pref.get("anime_locations").split(":")).each { |dir| Dir.glob("#{dir}*/*.{mkv,avi,mp4}").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? if not force 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
30 31 32 33 34 35 36 37 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 30 def load raw = @pref.get "local_anime" if not raw == nil and raw.class == String @@local_anime = Marshal.load(Base64.decode64(raw)) else @@local_anime = {} end end |
#logWatched(file) ⇒ Object
161 162 163 164 165 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 161 def logWatched(file) open(@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
83 84 85 86 87 88 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 124 125 126 127 128 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 83 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| #puts animefile.path this_parent = parent animefile.path #puts animefile.path #puts this_parent 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), ) => ) #puts ret.inspect #exit return Hash[ret.sort_by{ |a| a[0].title}] end |
#parent(file) ⇒ Object
returns the parent directory of a file
77 78 79 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 77 def parent(file) return File.basename(File.dirname(file)) end |
#rmWatched(path = "zoz") ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 172 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
26 27 28 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 26 def save @pref.saveLocalAnime Base64.encode64(Marshal.dump @@local_anime) end |
#watch(file) ⇒ Object
run mpv
188 189 190 |
# File 'lib/aniview/interface/animeio/animeio.rb', line 188 def watch(file) pid = spawn("mpv -alang jpn -slang eng -msg-level=all=fatal -ass '#{file}'") end |