Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /lineup.m3u representation #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions ProxyWebModuleUnit.dfm
Expand Up @@ -28,6 +28,11 @@ object ProxyWebModule: TProxyWebModule
PathInfo = '/lineup.xml'
OnAction = ProxyWebModuleLineupXMLActionAction
end
item
Name = 'LineupM3UAction'
PathInfo = '/lineup.m3u'
OnAction = ProxyWebModuleLineupM3UActionAction
end
item
Name = 'TunerAction'
PathInfo = '/tuner[0-99]/v*'
Expand Down
28 changes: 28 additions & 0 deletions ProxyWebModuleUnit.pas
Expand Up @@ -50,6 +50,8 @@ TProxyWebModule = class(TWebModule)
Response: TWebResponse; var Handled: Boolean);
procedure ProxyWebModuleLineupXMLActionAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure ProxyWebModuleLineupM3UActionAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure ProxyWebModuleTunerActionAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
procedure WebModuleCreate(Sender: TObject);
Expand Down Expand Up @@ -376,6 +378,32 @@ procedure TProxyWebModule.ProxyWebModuleLineupXMLActionAction(Sender: TObject;
end;
end;

procedure TProxyWebModule.ProxyWebModuleLineupM3UActionAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
lLineup: TLineup;
begin
Handled := True;
try
TLogger.LogFmt(cLogDefault, 'Received lineup.m3u request from %s', [Request.RemoteAddr]);
try
lLineup := TLineup.Create;
try
GetLineup(lLineup);

Response.ContentType := 'audio/x-mpegurl';
Response.Content := lLineup.ToM3U;
finally
lLineup.Free;
end;
finally
TLogger.LogFmt(cLogDefault, 'Finished lineup.m3u request from %s', [Request.RemoteAddr]);
end;
except
HandleException;
end;
end;

procedure TProxyWebModule.CheckClientChannelMapUpdated;
var
lCetonConfig: TCetonConfig;
Expand Down
20 changes: 20 additions & 0 deletions hdhr/HDHR.pas
Expand Up @@ -218,6 +218,7 @@ TLineup = class

function ToJSON: String;
function ToXML: String;
function ToM3U: String;
end;

THDHRUtils = class abstract
Expand Down Expand Up @@ -334,6 +335,25 @@ function TLineup.ToXML: String;
Result := lXMLDoc.XML.Text;
end;

function TLineup.ToM3U: String;
var
out: string;
lItem: TLineupItem;
i: Integer;
begin
out := '#EXTM3U' + #13;

for i := 0 to fList.Count-1 do
begin
lItem := fList[i];

out := out + '#EXTINF:0 channel-number="' + lItem.GuideNumber + '",' + lItem.GuideName + #13;
out := out + lItem.URL + #13 + #13;
end;

Result := out;
end;

{ TTag }

class function TTag.TryFromBytes(const aBytes: TBytes;
Expand Down