Skip to content

Instantly share code, notes, and snippets.

@ufizo
Created March 10, 2013 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufizo/5128963 to your computer and use it in GitHub Desktop.
Save ufizo/5128963 to your computer and use it in GitHub Desktop.
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