Script for create sopcast channel list ('http://www.sopcast.com/chlist.xml') in Internet-television folder
1. Settings-Processing-Add
Name: SopCast Channels
Turn on "Button on the main form"
Expression:
Code:
const
CSIDL_LOCAL_APPDATA = $001c;
mpiTranscodingProfile = 50;
function GetItemValue(aItem: TXmlItem; const aValueName: string): string;
var
Item: TXmlItem;
begin
Item := aItem.Find(aValueName);
if Item <> nil then begin
Result := Item.Attributes['en'];
if Result = '' then
Result := Item.Value
end else
Result := ''
end;
var
ChannelItem, GroupItem, SopAddressItem: TXmlItem;
SopItem: TWmsScriptMediaItem;
sChannels, sFolderID, sGroupName,
sChannelInfo, sChannelAddress, sFolderPath,
sStreamType, sSubFolder, sTranscodingProfile: string;
XmlDocument: TXmlDocument;
i, iUnknownCount, j, k: Integer;
begin
XmlDocument := TXmlDocument.Create;
try
XmlDocument.LoadFromString(ReplaceStr(WmsDownloadURL('http://www.sopcast.com/chlist.xml'), #13#10, ' '));
iUnknownCount := 1;
if SameText(XmlDocument.Root.Name, 'channels') then begin
for i := 0 to XmlDocument.Root.Count - 1 do begin
GroupItem := XmlDocument.Root.Items[i];
if SameText(GroupItem.Name, 'group') then begin
sGroupName := GroupItem.Attributes['en'];
if sGroupName = '' then begin
if (GroupItem.Count > 0) and (GroupItem.Items[0].Name = '') then
sGroupName := Trim(GroupItem.Items[0].Value);
if sGroupName = '' then begin
sGroupName := GroupItem.Attributes['cn'];
if sGroupName = '' then begin
sGroupName := Format('Unknown (%d)', [iUnknownCount]);
Inc(iUnknownCount)
end
end
end;
sFolderPath := 'SopCast Channels\' + sGroupName + '\';
for j := 0 to GroupItem.Count - 1 do begin
ChannelItem := GroupItem.Items[j];
if SameText(ChannelItem.Name, 'channel') then begin
sChannelInfo := Format('%s; Class: %s; Region: %s; Language: %s',
[GetItemValue(ChannelItem, 'name'),
GetItemValue(ChannelItem, 'class'),
GetItemValue(ChannelItem, 'region'),
ChannelItem.Attributes['language']]);
sStreamType := GetItemValue(ChannelItem, 'stream_type');
if SameText(sStreamType, 'mp3') or SameText(sStreamType, 'wma') then begin
sFolderID := mfAudioInternetRadioItemID;
sTranscodingProfile := 'Internet-radio (SopCast)'
end else begin
sFolderID := mfVideoInternetTelevisionItemID;
sTranscodingProfile := 'Internet-television (SopCast)'
end;
SopAddressItem := ChannelItem.Find('sop_address');
if (SopAddressItem <> nil) and (SopAddressItem.Count >= 1) then begin
for k := 0 to SopAddressItem.Count - 1 do begin
if SopAddressItem.Count > 1 then
sSubFolder := '\Item' + IntToStr(k + 1)
else
sSubFolder := '';
SopItem := WmsCreateMediaItem(SopAddressItem.items[k].Value,
sFolderID,
sFolderPath + sSubFolder);
SopItem.Properties[mpiTitle] := sChannelInfo;
SopItem.Properties[mpiTranscodingProfile] := sTranscodingProfile
end
end
end
end
end
end
end;
WmsDatabaseAutoSave
finally
XmlDocument.Free
end;
ProcessMediaResult := True
end.
2. Ok,Ok,Ok
3. Press button "SopCast Channels"