Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Save videos: 2022 edition

My current process for running yt-dlp involves detoxing the filenames.

File save-videos.sh.

#!/bin/sh
# Startdate: 2022-09-20
# Purpose: single utility that downloads and safely renames provided files
# Dependencies:
#    yt-dlp
#    detox
#    rename
#    files: config/detoxrc config/safe.tbl
cd "/path/${SUBDIR:+${SUBDIR}}"
mkdir -p temp && { cd temp && USED_TEMP=1 ; }
LANG=latin-1 PYTHONIOENCODING=latin-1 yt-dlp "${@}"
if test "${USED_TEMP}" = "1" ;
then
   # remove weird characters
   detox -f "config/detoxrc" -v *
   # strip the dash that precedes the youtube VID
   rename 's/ -([a-zA-Z0-9_]{11}\.)/ $1/' *
   mv -i * ..
fi

File config/detoxrc:

sequence default {
  uncgi;
  iso8859_1 {
    filename "/usr/share/detox/iso8859_1.tbl";
  };
  safe {
    filename "config/safe.tbl";
  };
  wipeup {
    remove_trailing;
  };
};

And my only differences for config/safe.tbl are:

--- /usr/share/detox/safe.tbl   2022-09-20 15:02:16.000000000 -0400
+++ config/safe.tbl 2022-09-20 10:08:23.326100599 -0400
@@ -99,11 +99,11 @@
 0x09       _   # tab
 0x0A       _   # new line
 0x0D       _   # carriage return
-0x20       _   # space
-0x21       _   # !
+#0x20      _   # space
+0x21       ''  # !
 0x22       _   # "
 0x24       _   # $
-0x27       _   # '
+0x27       ''  # '
 0x2a       _   # *
 0x2f       _   # /
 0x3a       _   # :

I entirely discard exclamation mark ! and single quote ', and do not replace spaces at all.

Comments