Check if song is already in playlist

Is there a way for Audirvana to check if a song is already in a playlist? I’m adding songs from my local music library to playlists and I often end up adding the same song to a playlist. I would like Audirvana to check to see if the song I am trying to add is already in a playlist and to warn me about this. The TIDAL desktop app does this really well. It should be a simple feature to add in Audirvana.

As it stands now, I have to waste a lot of time sorting my Audirvana playlists by song title and removing duplicates.

As an alternative, is it possible to show a flag next to a track that is already in an Audirvana playlist? This would avoid me adding the track to the same playlist again while I’m browsing my local albums.

I’ve come up with a Python 3 script to make things easier. If you’re NOT familiar with using Terminal on a Mac then this may not be for you.

Summary of issue: Audirvana desktop does not warn you if you attempt to add a song from the library into a playlist if that song already exists in that playlist.

Problem: You Audirvana playlists can end up with many duplicated songs if you are working with many playlists and many thousands of songs in your Library.

  1. You will need to export your playlist from Audirvana: File --> Export Playlist (use relative path names). Note the name and location of your playlist - it will have a .M3U file extension.

  2. Launch Terminal on your Mac and navigate to the location of your saved playlist file(s)

  3. Create a Python 3 script file called dupes.py by inserting these lines (e.g. by using vi):

# Python 3 script to find duplicate song names in M3U playlist file
# Usage: dupes <M3U_File>
# Input: Basic M3U file where each song line is prefiex by #EXTINF
# Output: List of duplicates song names
# Author: Taz
# Date: 01 November 2020
# Revision History:
#
#####################################################################################
# Version                 | Date               | Comments                           #
# ==================================================================================#
# 0.1                     | 01-Nov-2020        | Draft                              #
# ----------------------------------------------------------------------------------#
#                         |                    |                                    #
#####################################################################################

import sys
import collections

# Usage function
def usage():
    print("Usage: dupes -h | <M3U_File>")
    return

# Initialise list of duplicate song titles
songTitles = []

# Check that we are using Python 3
if sys.version_info[0] < 3:
    raise Exception("ERROR: This script requires Python 3")

# Get command line arguments and check if we need to display
# the usage info
arguments = len(sys.argv) - 1
if arguments == 0 or sys.argv[1] == '-h':
    usage()
    sys.exit(0)

# Now we work with the input file which should be an M3U playlist file
# with each song title line beginning with #EXTINF
try:
    with open(sys.argv[1], "r") as sourceFile:
        for lineA in sourceFile:
            # This line should start with #EXTINF
            # If it does not then the M3U file is badly formatted
            # and we exit with an error message
            if not lineA.startswith('#EXTINF'):
                print("ERROR: Missing #EXTINF tag on line", lineA)
                sys.exit(2)
            # print(lineA)

            # Now we try to read the next line that contains the
            # rest of the song fields. A second line for each song
            # must always exist in the M3U file. If it does not
            # exist then we error out.
            try:
                lineB = sourceFile.readline()
                # print("Second line read")

            except Exception:
                print("ERROR: Unable to read second line of song info")
                sys.exit(3)

            # We now have both lines of an M3U song so we will
            # process them

            # Get the display title from lineA
            song_title = lineA.split(',')[1].strip()
            
            # Add the title to songTitles list
            songTitles.append(song_title)

        sourceFile.close()
        
        # Print header information
        print("Playlist name: ", sys.argv[1])
        print("Total number of songs: ", len(songTitles))
        
        # Now find the duplicate song names
        print("\nDuplicates found:\n")
        print(*[item for item, count in collections.Counter(songTitles).items() if count > 1], sep = "\n")

except Exception:
    print("ERROR: M3U playlist file", sys.argv[1], 'not found!')
    sys.exit(1)

sys.exit(0)
  1. Now run the following command in your Terminal session:
python3 dupes.py <M3U_Playlist_File>

Your output should be similar to this:

You can then use this list of duplicated songs as a reference. Go into Audirvana, select the playlist you found duplicates for, sort it by TITLE and locate the songs mentioned in the output of the dupes.py script and delete the duplicated ones from your playlist if they are exactly the same songs - i.e. same title, album, artist, etc.

I hope it’s a useful script for some users of Audirvana!