$/d'; }; done | sort
return
}
# Put the sorted genre IDs one after another into the GENRE_ID variable and call the function above,
# which then will find out which genre's name has this ID and find the genre's artists.
for i in $(cat ${TEMP6}); do
GENRE_ID=${i}
sorted_artists_list_from_genre_id
done > ${TEMP}
cp ${TEMP} ${TEMP5}
return
}
function css_generate() {
echo -en 'body {
color: #fff;
background: #000000;
margin-left: 15%;
margin-right: 15%;
}
p {
margin-top: 0px;
margin-left: 3px;
}
h1 {
letter-spacing: 4px;
margin-bottom: 12px;
color: #fff;
background-color: #000;
}
h2 {
margin-top: 40px;
margin-bottom: 15px;
color: #fff;
background-color: #000;
}
ul {
list-style-type: square;
}
li {
margin-top: 5px;
}
a:link {
font-weight: bold;
text-decoration: none;
color: #7777ff;
background-color: #000;
}
a:visited {
font-weight: bold;
text-decoration: none;
color: #7777ff;
background-color: #000;
}
a:hover, a:active {
text-decoration: underline;
color: #9685BA;
background-color: #000;
}
table {
border-style: none;
}
tr {
border-style: none;
}
td {
border-style: none;
}
' >${DIRECTORY}/${CSSFILE}
return
}
function html_generate_header() {
echo -en "
Amarok collection
" | append_to_html
# Insert COLLECTIONOWNER and COLLECTIONMAIL
if [ ${COLLECTIONOWNER} != "DEFAULT" ]
then
if [ ${COLLECTIONMAIL} != "DEFAULT" ]
then
# Both set.
echo -en "${COLLECTIONOWNER}'s " | append_to_html
else
# Only COLLECTIONOWNER set.
echo -en "${COLLECTIONOWNER}'s " | append_to_html
fi
# Nothing set.
fi
echo -en 'Amarok collection
' | append_to_html
css_generate
return
}
function html_generate_footer() {
echo -e '
' | append_to_html
return
}
function html_export() {
if (( ${SILENT} == 0 ))
then
echo -n "The information is being exported to HTML... please wait."
fi
# OUTPUTHTML will be considered by the print functions.
OUTPUTHTML=1
# Abort if directory doesn't exist.
[ -d ${DIRECTORY} ] || { echo -e "\nThe specified directory does not exist. Exiting."; exit 1; }
HTMLFILE=${DIRECTORY}/${INDEXFILE}
rm -f ${HTMLFILE}
html_generate_header
echo -e "\n generated by amaroKollection ${VERSION} on $(date --iso-8601)\n
\n" | append_to_html
print_collection_statistics
echo -e "Collection lists:
\n Artists and their albums
Genres and their artists
\n" | append_to_html
HTMLFILE=${DIRECTORY}/${ARTISTS_AND_THEIR_ALBUMS_FILE}
rm -f ${HTMLFILE}
html_generate_header
print_artists_and_their_albums
html_generate_footer
HTMLFILE=${DIRECTORY}/${GENRES_AND_THEIR_ARTISTS_FILE}
rm -f ${HTMLFILE}
html_generate_header
print_genres_and_their_artists
html_generate_footer
OUTPUTHTML=0
HTMLFILE=${DIRECTORY}/${INDEXFILE}
html_generate_footer
if (( ${SILENT} == 0 ))
then
echo -e "\rHTML files have been generated. "
fi
return
}
function print_artists_and_their_albums() {
fetch_artists_and_their_albums
case "${OUTPUTHTML}" in
( 1 )
echo -en "Artists and their albums:
\n\n" | append_to_html
echo -en "\n" | append_to_html
sed -i -e 's// <\/ul>\n <\/li>\n - /' -e 's/<\/artistName>/\n
/' -e 's// - /' -e 's/<\/albumName>/<\/li>/' ${TEMP5}
echo -en "
\n \n
\n\n" >> ${TEMP5}
# doh...
tail -n +3 ${TEMP5} | append_to_html
;;
( * )
echo "Artists and their albums:"
echo
sed -e 's///' -e 's/<\/artistName>//' -e 's// /' -e 's/<\/albumName>//' ${TEMP5}
;;
esac
return
}
function print_genres_and_their_artists() {
fetch_genres_and_their_artists
case "${OUTPUTHTML}" in
( 1 )
echo -en "Genres and their artists:
\n\n" | append_to_html
echo -en "\n" | append_to_html
sed -i -e 's// <\/ul>\n <\/li>\n - /' -e 's/<\/genreName>/\n
/' -e 's// - /' -e 's/<\/artistName>/<\/li>/' ${TEMP5}
echo -en "
\n \n
\n\n" >> ${TEMP5}
# doh...
tail -n +3 ${TEMP5} | append_to_html
;;
( * )
echo "Genres and their artists:"
echo
sed -e 's///' -e 's/<\/genreName>//' -e 's// /' -e 's/<\/artistName>//' ${TEMP5}
;;
esac
return
}
function zip_htmls() {
echo -n "Packing HTML files into ${DIRECTORY}/${ZIPFILE}..."
zip ${DIRECTORY}/${ZIPFILE} ${DIRECTORY}/${INDEXFILE} ${DIRECTORY}/${CSSFILE} ${DIRECTORY}/${ARTISTS_AND_THEIR_ALBUMS_FILE} ${DIRECTORY}/${GENRES_AND_THEIR_ARTISTS_FILE} >/dev/null
rm -f ${DIRECTORY}/${INDEXFILE} ${DIRECTORY}/${CSSFILE} ${DIRECTORY}/${ARTISTS_AND_THEIR_ALBUMS_FILE} ${DIRECTORY}/${GENRES_AND_THEIR_ARTISTS_FILE} >/dev/null
echo -e "\rHTML files have been added to ${DIRECTORY}/${ZIPFILE}."
return
}
function print_collection_statistics() {
case "${OUTPUTHTML}" in
( 1 )
echo -en "Collection statistics:
| Track count |
${COLLECTION_TRACKS} |
| Album count |
${COLLECTION_ALBUMS} |
| Artist count |
${COLLECTION_ARTISTS} |
| Genre count |
${COLLECTION_GENRES} |
| Compilation count |
${COLLECTION_COMPILATIONS} |
" | append_to_html
;;
( * )
echo "Collection statistics:"
echo
echo "Track count: ${COLLECTION_TRACKS}"
echo "Album count: ${COLLECTION_ALBUMS}"
echo "Artist count: ${COLLECTION_ARTISTS}"
echo "Genre count: ${COLLECTION_GENRES}"
echo "Compilation count: ${COLLECTION_COMPILATIONS}"
;;
esac
return
}
function print_help() {
echo "This bash script extracts information from Amarok's collection database."
echo
echo "Specify one of the following parameters:"
echo
echo " -h --help Display this message."
echo " -s --statistics Display collection statistics."
echo " -a --albums Display artists and their albums."
echo " -g --genres Display genres and their artists."
echo " -x --export [directory] Export all available information to HTML files;"
echo " [directory] is the name of the target directory."
echo " The directory must exist if specified."
echo " -z --zipexp [directory] Same as -x but put the resulting HTML files into"
echo " a ZIP archive in [directory]."
echo " The directory must exist if specified."
echo
echo "Hint: The script has a configration section at the top, where you can"
echo " adapt some variables to your needs."
return
}
## MAIN
if (( ${SILENT} == 0 ))
then
echo
echo "amaroKollection ${VERSION} (${RELEASE})"
echo
fi
case "$1" in
("-h" | "--help")
print_help
;;
("-s" | "--statistics")
print_collection_statistics
;;
("-a" | "--albums")
print_artists_and_their_albums
;;
("-g" | "--genres")
print_genres_and_their_artists
;;
("-x" | "--export")
if [ "$2" != "" ]; then DIRECTORY="$2"; fi
html_export
;;
("-z" | "--zipexp")
if [ "$2" != "" ]; then DIRECTORY="$2"; fi
html_export
zip_htmls
;;
*)
print_help
;;
esac
if (( ${SILENT} == 0 ))
then
echo
fi
exit_amaroKollection
### THE END