importing spotlogs into mAirlist playlist

I have put together a script that should do pretty much what you want:

  • It scans the contents of the playlist for items with artist=$TRAFFIC, and title=<name/time of the block> - these items can be placeholders, dummies, 0.1s-silence-audios or whatever.

  • For each found item, it scans the traffic log (saved as yyyy-mm-dd.txt in a given directory) for a block with the same name/time, creates a container from the spots, deletes the placeholder, and inserts the container instead.

The artist/title of the container is set to the same values as the placeholder. That means that you can run the script over and over again, it will replace existing containers (created during earlier runs) with the latest version from the traffic log.

All you have to do is to make sure that your music log contains the placeholders with the correct artist and title.

Are you using M3U as the import format for the music log? If so, it is possible to add some magic lines to them in order to add dummy items.

function CreateTrafficContainer(trafficLog: TStringList; title: string): IContainerPlaylistItem;
var
  i, j: integer;
  line: TStringList;
  fpi: IFilePlaylistItem;
begin
  // Create an empty container
  Result := Factory.CreateContainerPlaylistItem;

  // Set a few properties
  Result.SetTitle(title);
  Result.GetArtists.Add('$TRAFFIC');
  Result.SetItemType(pitAdvertising);

  // The "line" is used to split each line into its comma-delimited components
  line := TStringList.Create;
  try
    // Walk through the traffic log, looking for the start tag
    for i := 0 to trafficLog.Count - 1 do begin
      // Split line
      line.CommaText := trafficLog[i];

      // start tag?
      if (line[0] = '20') and (line[1] = title) then begin

        // parse the remainder of the block
        for j := i + 1 to trafficLog.Count - 1 do begin
          // Split line
          line.CommaText := trafficLog[j];

          // End of block? exit here
          if line[0] = '21' then exit;

          // spot?
          if line[0] = '11' then begin
            // Create a playlist item for the spot
            fpi := Factory.CreateFilePlaylistItem('c:\spotdirectory\' + line[1] + '.mp3', []);
            fpi.SetTitle(line[4]);
            fpi.SetItemType(pitAdvertising);

            // Add spot to container
            Result.GetPlaylist.Add(fpi);
          end;
        end;
        exit;
      end;
    end;

    // Is the execution reaches this line, no block was found
    SystemLog('Warning: did not find any spots for ' + title);
  finally
    line.Free;
  end;
end;


var
  trafficLog: TStringList;
  i: integer;
  cpi: IContainerPlaylistItem;

begin
  trafficLog := TStringList.Create;
  try
    // Load traffic log into string list
    trafficLog.LoadFromFile('c:\temp\' + FormatDateTime('yyyy-mm-dd', now) + '.txt');

    // Lock playlist while the script runs
    CurrentPlaylist.BeginUpdate;
    try
      // Walk through playlist looking for traffic placeholders
      for i := 0 to CurrentPlaylist.GetCount - 1 do
        if CurrentPlaylist.GetItem(i).GetArtistsString = '$TRAFFIC' then begin
          // found a $TRAFFIC item!

          // Generate container from the traffic log,
          // using the placeholder title as the block name
          cpi := CreateTrafficContainer(trafficLog, CurrentPlaylist.GetItem(i).GetTitle);

          // Delete the placeholder, insert the container
          CurrentPlaylist.Delete(i);
          CurrentPlaylist.Insert(i, cpi);
        end;


    finally
      CurrentPlaylist.EndUpdate;
    end;
  finally
    trafficLog.Free;
  end;
end.