Last active
July 25, 2016 05:19
-
-
Save yrps/53cb9e08ebae5ee52b747315ee5a0727 to your computer and use it in GitHub Desktop.
Open archives with the Audacious media player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
exclude="txt|nfo|bat|c|usflib|psflib" | |
invoke="$(basename "$0")" | |
if [ -d "$XDG_RUNTIME_DIR" ]; then | |
dest="$XDG_RUNTIME_DIR/$invoke" | |
else | |
dest="/tmp/$invoke-$USER" | |
fi | |
playlist="$dest/$invoke.m3u" | |
usage() { | |
cat <<USAGE | |
Usage: $invoke ARCHIVE1 [ARCHIVE2]... | |
Extracts archives containing audio files using atool to temporary directory | |
$dest and enqueues the contents. | |
Archives containing playlists will enqueue the playlist contents instead of | |
the files. | |
USAGE | |
} | |
if \! &>/dev/null command -v aunpack; then | |
usage | |
echo >&2 "The atool utility is required." | |
exit 2 | |
fi | |
if [ $# -lt 1 ]; then | |
usage | |
echo >&2 "At least one archive is required." | |
exit 127 | |
fi | |
test -d "$dest" && rm -r "$dest" | |
(umask 077 && mkdir "$dest") | |
# atool does not support: | |
# aunpack --quiet --each --subdir --extract-to="$dest" -- "$@" | |
# Assemble a playlist dynamically. | |
for arch in "$@"; do | |
# Extract archive to its own subdir. | |
dir="$dest/$(basename "$arch").d" | |
aunpack --quiet --extract-to="$dir" -- "$arch" | |
# shellcheck disable=SC2016 | |
archlists="$(find "$dir" -type f -regextype egrep -iregex '.+\.(pls|m3u)' \ | |
-print0 | xargs -0 awk -v subdir="$dir/" '{print subdir $0}' )" | |
if [ -n "$archlists" ]; then | |
# If playlists are in the archive, append their contents | |
echo "$archlists" >>"$playlist" | |
else | |
# otherwise sort and append all audio files from the archive. | |
find "$dir" -type f -regextype egrep ! -iregex ".+\.($exclude)" \ | |
-print | sort >>"$playlist" | |
fi | |
done | |
audacious --enqueue-to-temp "$playlist" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion:
https://ncoop.github.io/2016/07/23/enqueuing-archives-with-audacious-media-player