]> git.mdlowis.com Git - proto/atv.git/commitdiff
update indexing script to skip files it already knows about
authorMike Lowis <mike.lowis@gentex.com>
Tue, 16 Apr 2024 13:58:45 +0000 (09:58 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Tue, 16 Apr 2024 13:58:45 +0000 (09:58 -0400)
atv/bin/atv-gensubs [changed mode: 0644->0755]
atv/bin/atv-index [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index 7ae447e..7347a83
@@ -1,6 +1,7 @@
 #!/bin/env ruby
 
 require 'json'
+require 'fileutils'
 
 IMG_TYPES = %w[jpg jpeg png gif]
 VID_TYPES = %w[mp4 ogg webm]
@@ -23,13 +24,30 @@ def image_duration(path)
 end
 
 ARGV.each do |root|
-  # Generate the index
   index = []
+  existing = {}
+  index_path = "#{root}/index.json"
+
+  # Find all valid references in the existing index
+  if File.exist? index_path
+    JSON.load_file(index_path).each do |e|
+      if File.exist? "#{root}/#{e["path"]}"
+        index << e
+        existing[e["path"]] = true
+      end
+    end
+  end
+
+  # Generate the index
   Dir.glob("#{root}/**/*.#{TYPES}").each do |path|
     ext = path.sub(/.*\.([^.]+)$/, '\1').downcase
     short_path = path.sub("#{root}/", '')
+
+    # Only process files that are not already in the index
+    next if existing[short_path]
     puts short_path
 
+    # OK, let's figure out what it is and add it
     if (VID_TYPES.include?(ext))
       duration = `#{CMD} \"#{path}\"`.chomp.to_f
       index << {
@@ -49,7 +67,8 @@ ARGV.each do |root|
   end
 
   # Save the index to disc
-  File.open("#{root}/index.json", "wb") do |f|
+  File.open("#{index_path}.tmp", "wb") do |f|
     f.write JSON.dump(index)
   end
+  FileUtils.mv("#{index_path}.tmp", index_path)
 end