From: Mike Lowis Date: Tue, 16 Apr 2024 13:58:45 +0000 (-0400) Subject: update indexing script to skip files it already knows about X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e2775cb24ccc1d5b50fe19e5d6ec4776508ace69;p=proto%2Fatv.git update indexing script to skip files it already knows about --- diff --git a/atv/bin/atv-gensubs b/atv/bin/atv-gensubs old mode 100644 new mode 100755 diff --git a/atv/bin/atv-index b/atv/bin/atv-index old mode 100644 new mode 100755 index 7ae447e..7347a83 --- a/atv/bin/atv-index +++ b/atv/bin/atv-index @@ -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