From 9f69299e2abb6624d9ccb18099a9504cd03deba0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 21 Jan 2022 19:51:42 +0000 Subject: dtas-tl prune: cull missing files from tracklist This helps for folks creating and replacing many throwaway files while editing with dtas-splitfx, or compulsive renamers. --- bin/dtas-tl | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'bin') diff --git a/bin/dtas-tl b/bin/dtas-tl index 2b34937..767b02d 100755 --- a/bin/dtas-tl +++ b/bin/dtas-tl @@ -21,6 +21,18 @@ def fix_enc!(str, enc) str.force_encoding(Encoding::ASCII_8BIT) unless str.valid_encoding? end +def each_track(c) + enc = Encoding.default_external + get_track_ids(c).each_slice(128) do |track_ids| + res = c.req("tl get #{track_ids.join(' ')}") + res = Shellwords.split(res.sub!(/\A\d+ /, '')) + while line = res.shift + fix_enc!(line, enc) + yield line + end + end +end + def do_edit(c) require 'dtas/edit_client' require 'tempfile' @@ -30,19 +42,13 @@ def do_edit(c) tmp_path = tmp.path orig = [] orig_idx = {} - enc = Encoding.default_external - get_track_ids(c).each_slice(128) do |track_ids| - res = c.req("tl get #{track_ids.join(' ')}") - res = Shellwords.split(res.sub!(/\A\d+ /, '')) - while line = res.shift - line.sub!(/\A(\d+)=/n, '') or abort "unexpected line=#{line.inspect}\n" - fix_enc!(line, enc) - track_id = $1.to_i - orig_idx[track_id] = orig.size - orig << track_id - tmp.write("#{Shellwords.escape(line)} =#{track_id}\n") - end + each_track(c) do |line| + line.sub!(/\A(\d+)=/n, '') or abort "unexpected line=#{line.inspect}\n" + track_id = $1.to_i + orig_idx[track_id] = orig.size + orig << track_id + tmp.write("#{Shellwords.escape(line)} =#{track_id}\n") end tmp.flush @@ -139,15 +145,21 @@ end c = DTAS::UNIXClient.new case cmd = ARGV[0] -when "cat" - enc = Encoding.default_external - get_track_ids(c).each_slice(128) do |track_ids| - res = c.req("tl get #{track_ids.join(' ')}") - res = Shellwords.split(res.sub!(/\A\d+ /, '')) - while line = res.shift - fix_enc!(line, enc) - print "#{line}\n" +when 'cat' + each_track(c) { |line| print "#{line}\n" } +when 'prune' + each_track(c) do |line| + line.sub!(/\A(\d+)=/n, '') or abort "unexpected line=#{line.inspect}\n" + track_id = $1.to_i + ok = false + begin + st = File.stat(line) + ok = st.readable? && st.size? + rescue Errno::ENOENT, Errno::ENOTDIR, Errno::EACCES => e + warn "# #{line}: #{e.class}" + # raise other exceptions end + c.req("tl remove #{track_id}") unless ok end when 'aac' # add-after-current ARGV.shift -- cgit v1.2.3-24-ge0c7