create playlist from csv

Hi, still to find out all the details but would this possible knowing playlistname,playoutdate,playoutstarttime?

Kind regards tony

CSV files can be read by the means of TStringList.SetCommaText, like this (untested):

var
  sl, data: TStringList;

begin
  sl := TStringList.Create;
  data := TStringList.Create;
  try
    sl.LoadFromFile('mycsvfile.txt');
    for i := 0 to sl.Count -1 do begin
      data.SetCommaText(sl[i]);
      // the fields of the i-th line can now be accessed by data[0], data[1], etc.  
    end;
  finally
    sl.Free;
    data.Free;
  end;
end.

sl is used to read the lines of the files, data is used to cut each line into its parts.

TStringList has a number of settings to fine-tune the import, e.g. the delimiter character to be used (comma or semicolon).

http://www.delphibasics.co.uk/RTL.asp?Name=TStringList

Cheers Torben, it falls over on line 9 unknown identifier i

Have some more info about this now. The idea is to schedule 3 to 4 weeks from the csv file having manually created the playlists.

Kind Regards Tony

Sorry, you need to declare the variable i as integer of course:

var
  sl, data: TStringList;
  i: integer;

...

Thanks again Torben, now using this code:[code]var
sl, data: TStringList;
i:integer;

begin
sl := TStringList.Create;
data := TStringList.Create;
//try
sl.LoadFromFile(‘mycsv.txt’);
for i := 0 to sl.Count -1 do begin
data.CommaText(sl[i]);
// the fields of the i-th line can now be accessed by data[0], data[1], etc.
end;
// finally
sl.Free;
data.Free;
end;
end.
[/code]

Does not like SetCommaText (unknown identifier).

The error is,
11,21 Type mismatch

Though the above script would be the prefered method, would it also be possible to keep loading a playlist if numbered sequentially with an Action at the end of each playlist (the action attached to an audio file).

If so a pointer for the script would also be most welcome

Kind Regards Tony

btw: I’m still using version 2.1.45.507 on the playout PC

Tony: >cough< it’s SetCommaText, not CommaText. :wink:

BFN
CAD

Hi Cad, thanks for that. SetCommaText had been tried and threw up the inital error, so changed to CommaText. The resulting error is now Line 11,19 so as you say CommaText is also wrong.

Reverted back to the orignal code posted by Torben, adding the integer line. The error is now:

12,12 unknown identifier SetCommaText

Kind Regards tony

OK, Tony.

Without getting hugely technical, that almost certainly means that Torben will need to ‘add’ the ‘SetCommaText’ keyword to mAirListScript. :wink:

BFN
CAD

Thanks cad, I’ll need to wait for Torben as if i remove the offending line the script runs and generates the error cannot find mycsv.txt.

That’s because I removed the text file to see if anything was happening.

Kind Regards tony

Just took a look into the code (TStringList is a Delphi class provided by Pascal Script, not by myself, so I wasn’t aware of the exact methods which get imported).

“CommaText” (without “Set”) is correct, but it’s a class property, so it’s used like a variable:

data.CommaText := sl[i];

The mAirList-specific IPlaylistItem etc “classes” are not classes but interfaces - those do not have properties (at least not in scripting, in pure Delphi they have), so you need to use the Get and Set methods instead.

Hi Torben, just the line I had started to use without any success though.

[code]var
sl,data: TStringList;
i: integer;

begin
sl := TStringList.Create;
data := TStringList.Create;
try
sl.LoadFromFile(‘C:\playlists\mycsv.txt’);
for i := 0 to sl.Count -1 do begin
data.CommaText := sl[i];
// the fields of the i-th line can now be accessed by data[0], data[1], etc.
end;
finally
sl.Free;
data.Free;
end;
end.[/code]

With the text file in place no errors are generated but no new playlist is loaded. Remove the text file and mairList reports it cannot find the text file.

Kind Regards tony

Um … well, you still have to decide what you’re going to do with the data you’re reading in. At the moment, it’s just putting it into an array and then not doing anything with it.

You’ll need to add all the code to create a playlist ‘live,’ or to create a playlist file for loading in later. None of that exists yet: all that your current code is doing is reading in a CSV file.

BFN
CAD

Hi Cad, perhaps then we are trying to do things wrongly.

What we are trying to do is load a series of existing m3u playlists (some playlists being re-used with a different name upto 6 weeks later) in sequence.

On each line of the csv file we have the location and name of the file to load.

I guess much easier would be to number playlists sequentially and then use a script to load the next playlist in the sequence using an action to run the script.

Any pointers appreciated.

Kind Regards Tony

Tony, there are several scripts in here which will load ‘hourly’ playlists.

The ‘trick’ is to name the playlists in a standard format which a script can interpret. A common one is:
yyyy-mm-dd-hh.m3u
… or put another way:
year-month-date-hour.m3u
… so for example, a file might be named:
2009-08-07-18.m3u
… which means it is for playout at 18:00 (6pm) on the 7th of August 2009.

The reason the times and dates in the names are deliberately ‘back-to-front’ is so that when you sort by name, the newest file is at the top and the oldest is at the bottom: which makes it MUCH easier to weed out old files after they are played! :wink: If you used (say) dd-mm-yyyy-hh.m3u as a format, could you imagine how much more work it would be to find the previous month’s files?

A corresponding script in mAirlist would look each hour for the appropriate playout file by ‘building’ the name it would logically need for the upcoming hour, then trying to load it.

It is prudent (but not essential if you DO trust your schedulers!) to have one or more ‘emergency’ playlists which the script can load and run if the expected file for the hour doesn’t exist for whatever reason.

Of course, all the above doesn’t 100% apply if your playlists are not standard one-hour lengths; but you can easily extend the file name format to add minutes as well as hours, and change the associated script to run (say) every 10 minutes instead of every hour.

BFN
CAD

Right, Cad, and don’t forget that these hourly-named playlists can also be loaded through “actions” from e.g. the event scheduler using the variable substitution feature.

And given your post a little while ago in the other thread about using #mAirList INCLUDE in the m3u file, I’m sure that idea could be useful for Tony’s project as well!

BFN
CAD

Hi Torben and Cad, normally we would use a playlist in the time date format. However in this instance playlists are not in a standard hourly or daily format. They may range from 15 to 90 minute pre-recorded shows or Live Assist content.

However the project leaders have decided for now to continue creating an event to load each playlist (which gets reused over a 6 week period). I have suggested creating an action at the end of each playlist to load the next would be easier but am no longer involved.

Thanks both for your time, effort and suggestions on this project.

Kind regards tony