From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 18DE21F852 for ; Sun, 23 Jan 2022 21:38:12 +0000 (UTC) Received: from localhost ([::1]:56288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nBkYt-0007KG-Bq for e@80x24.org; Sun, 23 Jan 2022 16:38:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkYq-0007Hi-MR for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:09 -0500 Received: from dcvr.yhbt.net ([64.71.152.64]:39960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nBkYp-00008W-02 for dtas-all@nongnu.org; Sun, 23 Jan 2022 16:38:08 -0500 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CC0E11FA01 for ; Sun, 23 Jan 2022 21:37:46 +0000 (UTC) From: Eric Wong 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 Message-Id: <20220123213746.21085-5-e@80x24.org> In-Reply-To: <20220123213746.21085-1-e@80x24.org> References: <20220123213746.21085-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=64.71.152.64; envelope-from=e@80x24.org; helo=dcvr.yhbt.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: duct tape audio suite List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+e=80x24.org@nongnu.org Sender: "dtas-all" 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 +Copyright all contributors L License: GPL-3.0+ L 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