Expand munge* functions
authorAndrew Strong <andrew.david.strong@gmail.com>
Fri, 5 Aug 2016 02:12:59 +0000 (12:12 +1000)
committerAndrew Strong <andrew.david.strong@gmail.com>
Fri, 5 Aug 2016 02:12:59 +0000 (12:12 +1000)
Split user-definable mungefilename function into mungetrackname,
mungeartistname, and mungealbumname, each of which default to
mungefilename. Thanks to Gerald Turner for the patch and
enhancement request.

This closes Issue 39:

   https://abcde.einval.com/bugzilla/show_bug.cgi?id=39

abcde
abcde.1
abcde.conf
changelog

diff --git a/abcde b/abcde
index b9c622c..6b252b9 100755 (executable)
--- a/abcde
+++ b/abcde
@@ -526,9 +526,9 @@ do_replaygain()
                                CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
                                getcddbinfo TRACKNAME
                                splitvarious
-                               TRACKFILE="$(mungefilename "$TRACKNAME")"
-                               ARTISTFILE="$(mungefilename "$TRACKARTIST")"
-                               ALBUMFILE="$(mungefilename "$DALBUM")"
+                               TRACKFILE="$(mungetrackname "$TRACKNAME")"
+                               ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
+                               ALBUMFILE="$(mungealbumname "$DALBUM")"
                                GENRE="$(mungegenre "$GENRE")"
                                YEAR=${CDYEAR:-$CDYEAR}
                                gettracknum
@@ -1574,9 +1574,9 @@ do_move ()
                OUTPUT="$TMPOUTPUT"
 
                # Create ALBUMFILE, ARTISTFILE, TRACKFILE
-               ALBUMFILE="$(mungefilename "$DALBUM")"
-               ARTISTFILE="$(mungefilename "$TRACKARTIST")"
-               TRACKFILE="$(mungefilename "$TRACKNAME")"
+               ALBUMFILE="$(mungealbumname "$DALBUM")"
+               ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
+               TRACKFILE="$(mungetrackname "$TRACKNAME")"
                GENRE="$(mungegenre "$GENRE")"
                YEAR=${CDYEAR:-$CDYEAR}
                # If we want to start the tracks with a given number, we need to modify
@@ -1707,8 +1707,8 @@ do_playlist ()
                # Create a playlist file for the playlist data to go into.
                # We used to wipe it out if it existed. Now we request permission if interactive.
                for LASTTRACK in $TRACKQUEUE; do :; done
-               ALBUMFILE="$(mungefilename "$DALBUM")"
-               ARTISTFILE="$(mungefilename "$DARTIST")"
+               ALBUMFILE="$(mungealbumname "$DALBUM")"
+               ARTISTFILE="$(mungeartistname "$DARTIST")"
                GENRE="$(mungegenre "$GENRE")"
                YEAR=${CDYEAR:-$CDYEAR}
                if [ "$VARIOUSARTISTS" = "y" ] ; then
@@ -1747,9 +1747,9 @@ do_playlist ()
                                CDDBTRACKNUM=$(expr $UTRACKNUM - 1)
                                getcddbinfo TRACKNAME
                                splitvarious
-                               TRACKFILE="$(mungefilename "$TRACKNAME")"
-                               ARTISTFILE="$(mungefilename "$TRACKARTIST")"
-                               ALBUMFILE="$(mungefilename "$DALBUM")"
+                               TRACKFILE="$(mungetrackname "$TRACKNAME")"
+                               ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
+                               ALBUMFILE="$(mungealbumname "$DALBUM")"
                                # If we want to start the tracks with a given number, we need to modify the
                                # TRACKNUM value before evaluation
                                gettracknum
@@ -1903,9 +1903,9 @@ abcde.mkcue () {
        fi
 
        vecho "One track is $ONETRACK"
-       TRACKFILE="$(mungefilename "$TRACKNAME")"
-       ARTISTFILE="$(mungefilename "$TRACKARTIST")"
-       ALBUMFILE="$(mungefilename "$DALBUM")"
+       TRACKFILE="$(mungetrackname "$TRACKNAME")"
+       ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
+       ALBUMFILE="$(mungealbumname "$DALBUM")"
        if [ "$ONETRACK" = "y" ]; then
                if [ "$VARIOUSARTISTS" = "y" ]; then
                        CUEWAVFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
@@ -2264,9 +2264,9 @@ do_cleancue()
                                elif [ "$ONETRACK" = "y" ] &&
                                                echo "$line" | grep '^FILE "dummy.wav" WAVE' > /dev/null 2>&1 ; then
 
-                                       TRACKFILE="$(mungefilename "$TRACKNAME")"
-                                       ARTISTFILE="$(mungefilename "$TRACKARTIST")"
-                                       ALBUMFILE="$(mungefilename "$DALBUM")"
+                                       TRACKFILE="$(mungetrackname "$TRACKNAME")"
+                                       ARTISTFILE="$(mungeartistname "$TRACKARTIST")"
+                                       ALBUMFILE="$(mungealbumname "$DALBUM")"
 
                                        if [ "$VARIOUSARTISTS" = "y" ]; then
                                                OUTPUTFILE="$(eval echo \""$VAONETRACKOUTPUTFORMAT"\" | sed -e 's@^.*/@@').$OUTPUT"
@@ -3108,8 +3108,8 @@ do_cddbedit ()
 do_getalbumart()
 {
        # set variables
-       ALBUMFILE="$(mungefilename "$DALBUM")"
-       ARTISTFILE="$(mungefilename "$DARTIST")"
+       ALBUMFILE="$(mungealbumname "$DALBUM")"
+       ARTISTFILE="$(mungeartistname "$DARTIST")"
        GENRE="$(mungegenre "$GENRE")"
        YEAR=${CDYEAR:-$CDYEAR}
        # have we got a musicbrainz mbid or amazon asin?
@@ -3460,6 +3460,24 @@ mungefilename ()
        echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
 }
 
+# Custom filename munging specific to track names:
+mungetrackname ()
+{
+       mungefilename $@
+}
+
+# Custom filename munging specific to artist names:
+mungeartistname ()
+{
+       mungefilename $@
+}
+
+# Custom filename munging specific to album names:
+mungealbumname ()
+{
+       mungefilename $@
+}
+
 # Custom genre munging:
 mungegenre ()
 {
diff --git a/abcde.1 b/abcde.1
index 565503f..67cb582 100644 (file)
--- a/abcde.1
+++ b/abcde.1
@@ -545,6 +545,10 @@ If you modify this function, it is probably a good idea to keep the forward
 slash munging (UNIX cannot store a file with a '/' char in it) as well as
 the control character munging (NULs can't be in a filename either, and
 newlines and such in filenames are typically not desirable).
+.br
+New to abcde 2.7.3 are the user definable functions mungetrackname, mungeartistname
+and mungealbumname which default to mungefilename. These permit finer-grained
+control of track name, artist name and album name for the ultra-fastidious.
 .TP
 .B mungegenre
 mungegenre () is a shell function used to modify the $GENRE variable. As
index ddbbf41..7c0da02 100644 (file)
 #{
 #      echo "$@" | sed -e 's/^\.*//' -e 's/ /_/g' | tr -d ":><|*/\"'?[:cntrl:]"
 #}
+#
+# Custom filename munging specific to track names:
+# By default this function will call the mungefilename function.
+#mungetrackname ()
+#{
+#      mungefilename $@
+#}
+#
+# Custom filename munging specific to artist names:
+# By default this function will call the mungefilename function.
+#mungeartistname ()
+#{
+#      mungefilename $@
+#}
+#
+# Custom filename munging specific to album names:
+# By default this function will call the mungefilename function.
+#mungealbumname ()
+#{
+#      mungefilename $@
+#}
 
 # Custom genre munging:
 # By default we just transform uppercase to lowercase. Not much of a fancy
index f934a74..0d9825c 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,5 +1,10 @@
 abcde 2.7.3
 
+  * Split user-definable mungefilename function into mungetrackname,
+    mungeartistname, and mungealbumname, each of which default to
+    mungefilename Thanks to Gerald Turner for the patch and enhancement
+    request. This closes Issue 39:
+    https://abcde.einval.com/bugzilla/show_bug.cgi?id=39
   * FAQs: Clarify the exit from multi-result CDDB search.
   * Fix to allow multiple output formats when aac fallback is triggered.
     Thanks to Birk Bremer for the bug report. This closes Issue 35: