report_albumsku 2.33 KB
Newer Older
1
#!/bin/bash -
Dave Morriss's avatar
Dave Morriss committed
2 3 4 5
#===============================================================================
#
#         FILE: report_albumsku
#
6
#        USAGE: ./report_albumsku albumcode
Dave Morriss's avatar
Dave Morriss committed
7 8 9 10 11 12 13 14 15 16
#
#  DESCRIPTION: Report album details from the Magnatune catalogue by album
#               code (which Magnatune calls the 'sku')
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
#      LICENSE: Copyright (c) year 2012, Dave Morriss
17 18
#      CREATED: 2012-10-24 21:15:54
#     REVISION: 2016-01-11 14:15:27
Dave Morriss's avatar
Dave Morriss committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#
#===============================================================================

set -o nounset                              # Treat unset variables as an error

SCRIPT=${0##*/}

#-------------------------------------------------------------------------------
# Directories:
#       $BASEDIR--+
#                 +--Magnatune_Data             Data files here
#                 +--Magnatune_Downloads        Music downloads go here
#                 +--magnatune-downloader       Scripts
#                 +--logs                       Download logs etc (unmanaged)
#-------------------------------------------------------------------------------
#
# Define the place where the scripts and data files are to be stored
#
BASEDIR="$HOME/MusicDownloads"
# Data files go here
DATADIR="$BASEDIR/Magnatune_Data"
# Scripts live here
SCRIPTDIR="$BASEDIR/magnatune-downloader"

#
# Files
#
XSLT="$SCRIPTDIR/parse_album_tracks.xsl"
ALBUMINFO="$DATADIR/album_info_xml"
SUMMARY="$DATADIR/all_albums"

#
# Sanity checks
#
53 54 55 56 57 58
[ -e $BASEDIR ] || { echo "$BASEDIR not found"; exit 1; }
[ -e $DATADIR ] || { echo "$DATADIR not found"; exit 1; }
[ -e $SCRIPTDIR ] || { echo "$SCRIPTDIR not found"; exit 1; }
[ -e $XSLT ] || { echo "$XSLT not found"; exit 1; }
[ -e $ALBUMINFO ] || { echo "$ALBUMINFO not found"; exit 1; }
[ -e $SUMMARY ] || { echo "$SUMMARY not found"; exit 1; }
Dave Morriss's avatar
Dave Morriss committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

#
# Check argument count
#
if [[ $# -ne 1 ]]; then
    echo "Usage: $SCRIPT albumcode"
    exit
fi

#
# Downcase argument and remove illegal characters
#
CODE="${1,,}"
CODE=${CODE/[^a-z0-9-]/}

#
# Check the summary file for the code
#
if [[ $(egrep "^Code: *$CODE$" $SUMMARY) ]]; then
    xsltproc --stringparam code "$CODE" $XSLT $ALBUMINFO
else
    echo "Unable to find album code '$CODE'"
fi

exit

# vim: syntax=sh:ts=8:sw=4:ai:et:tw=78:fo=tcrqn21