Random m3u help

Discussion in 'Mac Programming' started by dexterous_, Jan 1, 2016.

Tags:
  1. dexterous_ macrumors newbie

    Joined:
    Jan 1, 2016
    #1
    Looking for some help with what I think should be an achievable script.

    Basically looking for a script that will search subfolders for specific files types (mp3, mp4, m4a) and select one random file from each subfolder, then write this into an m3u.

    The following creates an m3u per subfolder but this isn't what I am after:

    find . -name ‘*.mp3’ -execdir bash -c ‘file=”{}”; printf “%s\n” “${file##*/}” >> “${PWD##*/}.m3u”‘ \;

    Assistance greatly appreciated :)
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    How does that differ from what you want?

    Also, why are you subjecting yourself (or anyone else) to the horrors that are bash?
     
  3. dexterous_ thread starter macrumors newbie

    Joined:
    Jan 1, 2016
    #3
    Would it be possible in applescript?

    Am after a single m3u file that contains one random file from each subfolder.
     
  4. sero macrumors member

    Joined:
    Aug 28, 2008
    #4
    This won't be too hard. Just start with getting a basic find command to return what you want. Then pipe that through a command to randomize the order (I always forget what the BSD work around is for 'sort -R' - you can find it easily enough though) and store it. Then grab the 2nd to last fields separated by '/' - this will be the parent dir name for each file. Pipe that through 'sort -u'. Then you have a list of unique dirs. Now loop through the randomized list and grep each unique dir and pipe the output through head or tail, then redirect to your m3u. done
     

Share This Page