From 4cd9d512fb1fd9cae18a000bbbb50c227c7d355c Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Thu, 14 Mar 2024 15:18:08 -0400 Subject: [PATCH] added database cleanup logic --- atv/lib/atv/database.rb | 9 +++++++-- atv/lib/atv/player.rb | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/atv/lib/atv/database.rb b/atv/lib/atv/database.rb index d9342a7..90d0065 100644 --- a/atv/lib/atv/database.rb +++ b/atv/lib/atv/database.rb @@ -17,8 +17,10 @@ module ATV if File.exist? @path @data = JSON.parse(File.read(@path)) end + cleanup() scan() save() + pp @data end def save() @@ -40,7 +42,10 @@ module ATV def cleanup() files.each do |f| - @db.delete(f) if not File.exist?(f) + if not File.exist?("#{ATV_ROOT}/#{f["path"]}") + puts "Cleanup #{f["path"]}" + @data.delete(f["path"]) + end end end @@ -48,7 +53,7 @@ module ATV # scan for videos @dirs.each do |dir| Dir.glob("#{@root}/#{dir}/**/*.{mp4,webm,ogg}").each do |f| - short_path = f.sub(%r{[^/]+/}, '').sub("#{@root}/", '') + short_path = f.sub("#{@root}/", '') next if @data[short_path] puts f duration = `#{CMD} \"#{f}\"`.chomp.to_f diff --git a/atv/lib/atv/player.rb b/atv/lib/atv/player.rb index d22ad01..973dceb 100644 --- a/atv/lib/atv/player.rb +++ b/atv/lib/atv/player.rb @@ -21,7 +21,6 @@ module ATV File.open("/tmp/atv.json", "wb") do |f| f.write JSON.dump(export_data) end - pp export_data updated end -- 2.54.0