#!/bin/bash
# Author: Jan Christoph Uhde <linux obiwahn org>
#
# Tagging Script for mplayer
#
# The script provides a way to run a command
# on the currently played media file.
#
# Usage:
# Put the following line in your input.conf
# <KEY> run "tagger-script $PPID"
# and the script's location in your $PATH.
#
# Pressing <KEY> will then call the script:E
#

# change this function to you needs
tag () {
	case "$1" in
	*gvfs-metadata*|*log|*mountinfo)
		:
	;;
	*)	
		case "$2" in
		*)
			echo "$1" >> ~/my_tagged_files
		;;
		esac
	;;
	esac
}

mplayer_pid="$1"
while read -r line; do
	if [[ -n "$getnext" ]]; then
		tag "${line:1}"
	fi

	if [[ "$line" == "tREG" ]]; then
		getnext="yes"
	else
		unset getnext
	fi
done < <(lsof -d 0-65535 -a -p "$mplayer_pid" -F tn)
