Home > Uncategorized > Script to show id3v2 frames present or absent in a file

Script to show id3v2 frames present or absent in a file

This is a very simple script. See the usage at the top of the script starting on line 28.

#!/bin/bash

# Author: Gabriel Burca (gburca dash mp3 at ebixio dot com)
# Version: 1.0
#
# Copyright (C) 2006-2009  Gabriel Burca (gburca dash mp3 at ebixio dot com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


set -o nounset
set -o errexit

function usage () {
    cat << EOF
Checks for particular id3v2 frames in a set of files.
Usage:
    $0 <option> <FRAME> files...

Options:
    -m | --missing  Show files that are missing the frame
    -h | --has      Show files that have the frame
    -s | --show     Show the contents of the frame
    -a | --all      Show all the frames

For example, to find mp3's with no album art:
    $0 -m APIC *.mp3

Some sample frames:
    APIC    - Cover art
    TIT2    - Song name
    TPE1    - Artist
    TALB    - Album
    TCON    - Genre
EOF
}

function FilesWithoutFrame() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME " 2>&1 > /dev/null
        if [ $? -gt 0 ]; then
            # $file is missing $FRAME
            echo $file
        fi
    done
}

function FilesWithFrame() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME " 2>&1> /dev/null
        if [ $? -eq 0 ]; then
            # $file has $FRAME
            echo $file
        fi
    done
}

function ShowFrameContents() {
    FRAME=$1
    shift

    for file in $@ ; do
        id3v2 -R "$file" | egrep "^$FRAME "
    done
}

function ShowAll() {
    for file in $@; do
        echo
        echo
        id3v2 -R "$file"
    done
}


################################################################################
# main()
################################################################################

if [ $# -lt 2 ]; then
    usage
    exit 1
fi

IFS_orig=$IFS
IFS='
'

case $1 in
    -m | --missing)
        shift
        FilesWithoutFrame $@
        ;;
    -h | --has)
        shift
        FilesWithFrame $@
        ;;
    -s | --show)
        shift
        ShowFrameContents $@
        ;;
    -a | --all)
        shift
        ShowAll $@
        ;;
    *)
        usage
        exit 1
        ;;
esac

IFS=$IFS_orig
Categories: Uncategorized Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.