Page 1 of 1
How to set transcoding profile by script ?
Posted: Sat Nov 20, 2010 11:07 am
by koczis
Hello,
I'm trying to create a script that would fetch radio channels from the portal open.fm (
http://open.fm - quite popular in Poland) and made the appropriate links to the channels in the media library in the WMS. I have two problems:
1. How can a script set the transcoding profile ?
2. Is there a simple way to convert the UTF8 (ie the java method: \ u0104) on the right for WMS?
A piece of code that creates the link looks like this:
Code: Select all
WmsCreateMediaItem(url, OpenFMFolder.ItemID); // create link
tmpF := WmsFindMediaFolder(OpenFMFolder.ItemID, url);
tmpF.Properties[mpiTitle] := NameCase(Lowercase(title)); // change the title - this is the problem with UTF8, ie: title value is "500 Najwi\u0118kszych Hit\u00d3w" and should be "500 Największych Hitów"
tmpF.Properties[mpiTranscodingActive] := True; // thus attempting to set a profile transcoding but it does not work
tmpF.Properties[mpiTranscodingParams] := 'Music (VLC) - MP3';
Regards,
Koczis
Re: How to set transcoding profile by script ?
Posted: Sat Nov 20, 2010 2:44 pm
by Eugene
Hello,
1.
2. Try
Code: Select all
function JsonDecode(const aText: string): string;
var
i, j : integer;
begin
i := Pos('\', aText);
if i = 0 then
Result := aText
else begin
Result := Copy(aText, 1, i - 1);
j := i;
repeat
if (aText[j] = '\') then begin
inc(j);
case aText[j] of
'\': Result := Result + '\';
'"': Result := Result + '"';
'''': Result := Result + '''';
'/': Result := Result + '/';
'b': Result := Result + #8;
'f': Result := Result + #12;
'n': Result := Result + #10;
'r': Result := Result + #13;
't': Result := Result + #9;
'u':
begin
Result := Result + Chr(StrToInt('$' + Copy(aText, j + 1, 4)));
inc(j, 4);
end;
end
end else
Result := Result + aText[j];
inc(j);
until j > length(aText)
end
end;
Re: How to set transcoding profile by script ?
Posted: Sat Nov 20, 2010 5:27 pm
by koczis
Thanks Eugene !
I put my finished script below - may be useful to someone. Running this script creates a directory 'Open.FM' in which it links to all the radio stations available on the portal open.fm (77 items). Each station has turned profile transcoding 'Music (VLC) - MP3' (works best for me).
BTW - WMS is the best !
Code: Select all
var
iSuccessCount: Integer;
vOpenFMList: Variant;
title: String;
id: String;
tmpStr: String;
i: Integer;
x: Integer;
y: Integer;
url: String;
AllMusicFolder, OpenFMFolder, tmpF: TWmsScriptMediaItem;
const
mpiTranscodingProfile = 50;
function JsonDecode(const aText: string): string;
var
i, j : integer;
begin
i := Pos('\', aText);
if i = 0 then
Result := aText
else begin
Result := Copy(aText, 1, i - 1);
j := i;
repeat
if (aText[j] = '\') then begin
inc(j);
case aText[j] of
'\': Result := Result + '\';
'"': Result := Result + '"';
'''': Result := Result + '''';
'/': Result := Result + '/';
'b': Result := Result + #8;
'f': Result := Result + #12;
'n': Result := Result + #10;
'r': Result := Result + #13;
't': Result := Result + #9;
'u':
begin
Result := Result + Chr(StrToInt('$' + Copy(aText, j + 1, 4)));
inc(j, 4);
end;
end
end else
Result := Result + aText[j];
inc(j);
until j > length(aText)
end
end;
begin
iSuccessCount := 0;
AllMusicFolder := WmsFindMediaFolder(mfAudioAllMusicItemID);
if (AllMusicFolder <> nil) and (AllMusicFolder.ChildCount > 0) then begin
OpenFMFolder := WmsFindMediaFolder(mfAudioInternetRadioItemID, 'Open.FM');
if OpenFMFolder <> nil then begin
OpenFMFolder.DeleteChildItems;
OpenFMFolder.Delete;
end;
OpenFMFolder := WmsFindMediaFolder(mfAudioInternetRadioItemID);
OpenFMFolder.AddFolder('Open.FM');
OpenFMFolder := WmsFindMediaFolder(mfAudioInternetRadioItemID, 'Open.FM');
WmsShowInformation('Load metadata...');
try
vOpenFMList := WmsDownloadURL('http://open.fm/getplaylist.php');
i := 0;
while 1 do
begin
i := i+1;
x := NPos('{"title":', vOpenFMList, i);
if (x<1) then break;
y := NPos('"gg"', vOpenFMList, i);
tmpStr := Copy(vOpenFMList, x+1, y-x-2);
if (Length(tmpStr)>0) then
begin
title := ReplaceStr(ExtractWord(2, ExtractWord(1, tmpStr, ','), ':'), '"', '');
id := ReplaceStr(ExtractWord(2, ExtractWord(2, tmpStr, ','), ':'), '"', '');
url := 'http://gr-relay-5.gaduradio.pl/' + id;
//MessageDlg(url, mtInformation, mbOK, 0)
WmsCreateMediaItem(url, OpenFMFolder.ItemID);
tmpF := WmsFindMediaFolder(OpenFMFolder.ItemID, url);
tmpF.Properties[mpiTitle] := NameCase(Lowercase(JsonDecode(title)));
tmpF.Properties[mpiTranscodingActive] := True;
tmpF.Properties[mpiTranscodingProfile] := 'Music (VLC) - MP3';
iSuccessCount := iSuccessCount + 1;
end;
end;
finally
WmsHideInformation
end;
end;
if iSuccessCount > 0 then
MessageDlg('Load Open.FM list was successful.', mtInformation, mbOK, 0)
else
MessageDlg('No information available for load.', mtError, mbOK, 0);
WmsDatabaseAutoSave;
ProcessMediaResult := True
end.
Regards,
Koczis