Flow Chart for Adding New Media
To Tunes.DB

First, here is a textual version of the steps involved in adding new media to my tunes DB. This is after a form requesting all pertinent data has been filled out and submitted. A 500-line Perl script handles this.

I use a JavaScript player for web-access and it uses the built-in audio player so all audio files must be .mp3 format. But a lot of the music I get is in .flac format (Free Lossless Audio Codec). So they have to be converted. I use flac and ffmpeg for this, called from the Perl script.

All the data is kept in an SQLIte database, and is available locally through a web site running Apache server.

To get the runtime of a CD I use a tool called exiftool to extract meta data from each audio file. I pipe the results of that to grep which filters out only the 'Duration' data. Then a hand-made Perl subroutine totals the minutes and seconds, and finally mangles that into a human-readable string (hh:mm:ss).

Uploading the CD files and DB file to my remote site is done using curl, also called from the Perl script.

All the code for the flow-chart is done using SVG. Check the source code to peek.

  1. connect to the right DB
  2. print all parameters to confirm data (fields in the form)
  3. break out any necessary items from parameters
    1. artist
    2. CD title
    3. genre
    4. tracks
    5. notes
    6. directory name
  4. check if Artist exists in DB
    1. set AddArtist (0,1)
  5. check if Artist.book exists in DB
    1. set AddTitle (0,1)
  6. check format of audio files
    1. convert files to .mp3 if needed
    2. run ffmpeg or flac to convert from .flac or .m4a to .mp3
  7. get total play time of CD
    1. run exiftool from Perl script on each audio file & extract play times
    2. aggregate times into hours, minutes, seconds
  8. copy completed directory to proper location
  9. copy file to backup directories
  10. update local DB if needed
    1. add Artist
    2. add title
    3. add keywords; etc
  11. upload file to remote site
    1. call curl from Perl script to u/l
  12. upload DB file to remote site
    1. call curl from Perl script to u/l

Now the Flow Chart

1 Connect to DB 2 Parse & print parameters 3 Break out parameters Artist CD Title Genre Tracks Notes Target Directory 4 Artist exists in DB? Y AddArtist=0 QUIT N AddArtist=1 5 Title Exists for Artist in DB? Y QUIT N AddTitle=1 6 Convert files to .mp3? Y Do conversion 7 Get playtimes 8 Copy Source Dir to Target Dir 9 Copy Source Dir to Backup Dir 10 Update local DB 11 Upload CD file to Remote 12 Upload DB to Remote 13 All Done Eh! EXIT

That's All Folks