better format

This commit is contained in:
2021-11-28 19:08:26 +01:00
parent c3ea47b305
commit e2f1478fec

48
md
View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
checkMetadata() { checkMetadata() {
ffprobe "$1" 2>&1 | grep -e artist -e title ffprobe "$1" 2>&1 | grep -ie artist -e title
while true; do while true; do
printf "correct metadata? [Y] | [n]: " printf "correct metadata? [Y] | [n]: "
read -r yn < /dev/tty read -r yn < /dev/tty
@ -11,28 +11,40 @@ checkMetadata() {
esac esac
done done
} }
cd ~/Medien/Musik/2020 || exit
download_dir="$(mktemp -d)" download_dir="$(mktemp -d)"
file_name="$(youtube-dl "ytsearch:$1 lyrics" \ temp_dir="$(mktemp -d)"
--extract-audio \ for song in "$@"; do
file_name="$(youtube-dl "ytsearch:$song lyrics" \
-f bestaudio/best \
--output "$download_dir/%(title)s.%(ext)s" \ --output "$download_dir/%(title)s.%(ext)s" \
--metadata-from-title "%(artist)s - %(title)s" \ --metadata-from-title "%(artist)s - %(title)s" \
--audio-quality 0 \
--audio-format mp3 \
--embed-thumbnail \
--add-metadata \ --add-metadata \
|awk '$1 == "[ffmpeg]" && $2 == "Destination:" {print substr($0, index($0,$3))}')" |awk '$1 == "[download]" && $2 == "Destination:" {print substr($0, index($0,$3))}')"
r128gain "$file_name" 2> /dev/null case "$(echo "$file_name" | awk -F . '{print $NF}')" in
temp_dir="$(mktemp -d)" "webm")
temp_file="$temp_dir/0.mp3" new_filename="${file_name%.*}".opus
cp "$file_name" "$temp_file" mkvextract tracks "$file_name" "0:$new_filename" > /dev/null
idntag "$temp_file" > /dev/null file_name="$new_filename"
temp_file=$(echo "$temp_dir"/*) ;;
if checkMetadata "$temp_file"; then "m4a")
;;
*)
echo "unsupported file type"
exit 1
;;
esac
r128gain "$file_name" 2> /dev/null
temp_file="$temp_dir/$(basename "$file_name")"
cp "$file_name" "$temp_file"
idntag "$temp_file"
temp_file=$(echo "$temp_dir"/*)
if checkMetadata "$temp_file"; then
mv "$temp_file" . mv "$temp_file" .
elif checkMetadata "$file_name"; then elif checkMetadata "$file_name"; then
mv "$file_name" . mv "$file_name" .
else else
echo "enter it manually" echo "enter it manually"
fi fi
done
rm -rf "$temp_dir" "$download_dir" rm -rf "$temp_dir" "$download_dir"
mpc update > /dev/null