Create a gist now

Instantly share code, notes, and snippets.

@ufizo /muz.sh
Created Mar 10, 2013

What would you like to do?
Music scanner script
#!/bin/sh
unset url
pattern="([^\w-]clementine)"
if ps ux | grep -P $pattern | grep -v grep | grep -vq tagreader; then
# $app is running!
url=`lsof -F n -c clementine | grep -i "^.*\.mp3$" | sed 's/^n//g'`
file=`basename "$url"`
# ft it is a mp3 file, get ID3 info
title=`id3info "$url" | grep "Title" | sed 's/^===.*[:].//g'` ; title=$(tr -d '\n' <<<"$title")
artist=`id3info "$url" | grep "performer" | sed 's/^===.*[:].//g'`; artist=$(tr -d '\n' <<<"$artist")
artist=$(tr -d '\n' <<<"$artist")
if [ -z "$title" ] && [ -z "$artist" ]; then
if (( "${#url}" >= 2 )); then
# Cant get id3 info, just print filename
printf "$(date)\tFile: %-70s\n" "$file"
fi
else
printf "$(date)\tTitle: %-50s\tArtist: %-20s\n" "$title" "$artist"
fi
elif ps ux | grep -P "([^\w-]vlc)" | grep -v grep | grep -vq tagreader; then
# $app is running!
url=`lsof -F n -c vlc | grep -i "^.*\.\(flv\|mp4\|mkv\)$" | sed 's/^n//g'`
file=`basename "$url"`
printf "$(date)\tFile: %-70s\n" "$file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment