Created
March 10, 2013 15:17
-
-
Save ufizo/5128963 to your computer and use it in GitHub Desktop.
Music scanner script
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
#!/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