scre.git
bean.sh
#!/bin/sh
# bean - music downloader
# Copyright (C) 2024 ArcNyxx <me@arcnyxx.net>
# see LICENCE file for licensing information
[ "$#" != 1 ] && { echo 'usage: bean [url]' >&2 ; exit 1 ; }
DIR="`mktemp -d`"
yt-dlp --parse-metadata 'title:%(meta_title)s' \
--parse-metadata 'playlist_title:%(meta_album)s' \
--parse-metadata 'uploader:%(meta_artist)s' \
--parse-metadata '%(playlist_index)s/%(playlist_count)s:%(meta_track)s' \
--parse-metadata ':(?P<meta_comment>)' \
--parse-metadata ':(?P<meta_date>)' \
--parse-metadata ':(?P<meta_description>)' \
--parse-metadata ':(?P<meta_purl>)' \
--parse-metadata ':(?P<meta_synopsis>)' \
-x --audio-format mp3 --use-postprocessor FFmpegMetadata \
-o "$DIR/%(title)s.%(ext)s" "$1"
cd "$DIR"
ls -A * >old
cp old new
IND=1
MAX="`wc -l <old`"
"$EDITOR" new
ALBUM="`ffprobe "\`sed q old\`" 2>&1 | grep album | cut -d: -f2 | xargs`"
ARTIST="`ffprobe "\`sed q old\`" 2>&1 | grep artist | cut -d: -f2 | xargs`"
echo -n "bean: change album name? (currently \"$ALBUM\"): "
read -r ALBUM2
[ "$ALBUM2" ] && ALBUM="$ALBUM2"
echo -n "bean: change artist name? (currently \"$ARTIST\"): "
read -r ARTIST2
[ "$ARTIST2" ] && ARTIST="$ARTIST2"
while [ "$IND" -le "$MAX" ] ; do
OLD="`sed "${IND}q;d" old`"
NEW="`sed "${IND}q;d" new`"
ffmpeg -i "$OLD" -metadata "title=${NEW%.mp3}" -metadata "album=$ALBUM" \
-metadata "artist=$ARTIST" -codec copy out.mp3
mv out.mp3 "`echo "$ARTIST-$ALBUM-${NEW%.mp3}" \
| tr '[:upper:] ' '[:lower:]-' | tr -cd '[:alnum:]-'`.mp3"
rm "$OLD"
IND="$((IND + 1))"
done
cp *.mp3 "$MUSIC"
cd "$OLDPWD"
rm -rf "$DIR"