]> git.mdlowis.com Git - proto/atv.git/commitdiff
added database cleanup logic
authorMike Lowis <mike.lowis@gentex.com>
Thu, 14 Mar 2024 19:18:08 +0000 (15:18 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Thu, 14 Mar 2024 19:18:08 +0000 (15:18 -0400)
atv/lib/atv/database.rb
atv/lib/atv/player.rb

index d9342a7e61babe85a8346791d430176e5daee627..90d0065eac464fb6d2fa2cc0e9798f0e81294b9f 100644 (file)
@@ -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
index d22ad019452b3d7c1b32e83ce76a299d77fcc8d2..973dcebcb37aa1cc9922b95f86c1e1f69d210cf4 100644 (file)
@@ -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