Created
October 18, 2017 22:41
-
-
Save eyedeekay/e45ef0058f6c93274081710386efbdc9 to your computer and use it in GitHub Desktop.
Fix up metadata for mp3s I downloaded from an open directory
This file contains 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
#! /usr/bin/env bash | |
set -e | |
parent="$1" | |
url="$parent" | |
lynx_links(){ | |
echo "$url" >&2 | |
lynx -listonly -nonumbers -dump "$url" | sed 's| |_|g' | |
} | |
for urlnext in $(lynx_links "$url"); do | |
url="$urlnext" | |
html=$(lynx_links "$url") | |
if [ ! -z "$(echo $html | grep mp3)" ]; then | |
echo "====" >&2 | |
echo -n " $html" | grep "mp3" >&2 | |
for mp in $(find . -type f -name "*.mp3" | sed 's| |;|g'); do | |
f=$(echo $mp | sed 's|;| |g' | sed 's|./||g') | |
echo -n " $f" >&2 | |
if [ ! -z $(echo "$html" | grep -i "$f") ]; then | |
echo -n " $html" | grep -i "$f" >&2 | |
echo "" >&2 | |
content=$(wget -q -O - "$url") | |
artist=$(echo "$content" | hxselect -s '\n' -i -c head 2>/dev/null | grep keywords | sed 's|<meta name="keywords" content="||g' | sed 's|"/>||g') | |
album=$(echo "$content" | hxselect -s '\n' -i -c head 2>/dev/null | grep author | sed 's|<meta name="author" content="||g' | sed 's|"/>||g') | |
title=$(echo "$f" | sed 's|.mp3||g' | tr '_' ' ' | tr -d '1234567890') | |
echo "'eyeD3 -a $artist -A $album -t $title $mp'" | |
eyeD3 -a "$artist" -A "$album" -t "$title" "$f" | |
else | |
echo "no match for $f" >&2 | |
fi | |
done | |
echo "----" >&2 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment