From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH 4/9] dtas-tl prune: cull missing files from tracklist
Date: Sun, 23 Jan 2022 21:37:41 +0000 [thread overview]
Message-ID: <20220123213746.21085-5-e@80x24.org> (raw)
In-Reply-To: <20220123213746.21085-1-e@80x24.org>
This helps for folks creating and replacing many throwaway files
while editing with dtas-splitfx, or compulsive renamers.
---
Documentation/dtas-tl.pod | 4 ++-
bin/dtas-tl | 52 ++++++++++++++++++++++++---------------
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/Documentation/dtas-tl.pod b/Documentation/dtas-tl.pod
index ac1b47d..b5a4b31 100644
--- a/Documentation/dtas-tl.pod
+++ b/Documentation/dtas-tl.pod
@@ -60,6 +60,8 @@ optionally seek to POS. POS should be a timestamp in HH:MM:SS.FRAC format.
=item prev - play the previous track in the tracklist
+=item prune - cull non-existent pathnames from the tracklist
+
=item repeat 1 - repeat the current track
=item repeat false - disable repeat
@@ -120,7 +122,7 @@ No subscription is necessary to post to the mailing list.
=head1 COPYRIGHT
-Copyright 2013-2020 all contributors L<mailto:dtas-all@nongnu.org>
+Copyright all contributors L<mailto:dtas-all@nongnu.org>
License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt>
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 @@ def add_after(c, argv, last_id)
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
next prev parent reply other threads:[~2022-01-23 21:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-23 21:37 [PATCH 0/9] various cuts for memory savings Eric Wong
2022-01-23 21:37 ` [PATCH 1/9] deduplicate and freeze pathnames + metadata Eric Wong
2022-01-23 21:37 ` [PATCH 2/9] player: remove omap conversion Eric Wong
2022-01-23 21:37 ` [PATCH 3/9] dtas: drop unnecessary "require 'yaml'" statements Eric Wong
2022-01-23 21:37 ` Eric Wong [this message]
2022-01-23 21:37 ` [PATCH 5/9] dtas-tl: drop encoding hacks, use binary stdout+stderr Eric Wong
2022-01-23 21:37 ` [PATCH 6/9] use IO#wait_readable consistently Eric Wong
2022-01-23 21:37 ` [PATCH 7/9] get rid of DTAS::Nonblock wrapper for Ruby <= 2.0 Eric Wong
2022-01-23 21:37 ` [PATCH 8/9] unix_accepted: drop Ruby < 2.3 support code Eric Wong
2022-01-23 21:37 ` [PATCH 9/9] do not check IO#closed? before calling IO#close Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/dtas/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220123213746.21085-5-e@80x24.org \
--to=e@80x24.org \
--cc=dtas-all@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).