Skip to content

Commit

Permalink
Added Plex support
Browse files Browse the repository at this point in the history
- Hacked in UPnP/SSDP discovery response
- Added automatic tuner count determination
- Fixed lineup.json and discover.json services responding with the wrong listen IP
  • Loading branch information
Craig Moksnes committed Jan 26, 2020
1 parent 18bb41c commit 2ad5d78
Show file tree
Hide file tree
Showing 9 changed files with 879 additions and 77 deletions.
67 changes: 62 additions & 5 deletions ProxyFormUnit.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'Ceton HDHomeRun Proxy'
ClientHeight = 748
ClientHeight = 754
ClientWidth = 435
Fill.Kind = Solid
Position = ScreenCenter
Expand All @@ -17,11 +17,11 @@ object MainForm: TMainForm
object VertScrollBox1: TVertScrollBox
Align = Contents
Size.Width = 435.000000000000000000
Size.Height = 748.000000000000000000
Size.Height = 754.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
Viewport.Width = 435.000000000000000000
Viewport.Height = 748.000000000000000000
Viewport.Height = 754.000000000000000000
object gbGroup: TGroupBox
Align = Top
Padding.Left = 15.000000000000000000
Expand Down Expand Up @@ -73,6 +73,14 @@ object MainForm: TMainForm
Text = 'Request Channels'
OnClick = btnRefreshChannelsClick
end
object lblSelectedChannels: TLabel
Position.X = 125.000000000000000000
Position.Y = 253.000000000000000000
Size.Width = 180.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
end
end
object gbSettings: TGroupBox
Align = Top
Expand All @@ -81,7 +89,7 @@ object MainForm: TMainForm
Size.PlatformDefault = False
StyleLookup = 'gbGroupStyle1'
Text = 'Settings'
TabOrder = 1
TabOrder = 2
object eCetonTunerAddress: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 3
Expand Down Expand Up @@ -165,7 +173,7 @@ object MainForm: TMainForm
Size.PlatformDefault = False
StyleLookup = 'gbGroupStyle1'
Text = 'Statistics'
TabOrder = 2
TabOrder = 3
object lbStats: TListView
ItemAppearanceClassName = 'TCustomizeItemObjects'
ItemEditAppearanceClassName = 'TCustomizeItemObjects'
Expand Down Expand Up @@ -197,6 +205,55 @@ object MainForm: TMainForm
Size.Height = 8.000000000000000000
Size.PlatformDefault = False
end
object GroupBox1: TGroupBox
Align = Top
Position.Y = 748.000000000000000000
Size.Width = 435.000000000000000000
Size.Height = 141.000000000000000000
Size.PlatformDefault = False
StyleLookup = 'gbGroupStyle1'
Text = 'Debug'
Visible = False
TabOrder = 1
object eDebugIP: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
TabOrder = 0
Position.X = 37.000000000000000000
Position.Y = 24.000000000000000000
Size.Width = 129.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
end
object Label5: TLabel
Position.X = 16.000000000000000000
Position.Y = 27.000000000000000000
Size.Width = 17.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
Text = 'IP:'
TabOrder = 1
end
object btnDebugDiscoveryRequest: TButton
Position.X = 16.000000000000000000
Position.Y = 56.000000000000000000
Size.Width = 121.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Text = 'Discovery Request'
OnClick = btnDebugDiscoveryRequestClick
end
end
object Splitter3: TSplitter
Align = Top
Cursor = crVSplit
MinSize = 20.000000000000000000
Position.Y = 748.000000000000000000
Size.Width = 435.000000000000000000
Size.Height = 8.000000000000000000
Size.PlatformDefault = False
Visible = False
end
end
object StyleBook1: TStyleBook
Styles = <
Expand Down
74 changes: 46 additions & 28 deletions ProxyFormUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ interface
REST.json,
REST.Client,

IdGlobal,

HDHR,
Ceton,
SocketUtils,
Expand Down Expand Up @@ -74,6 +76,12 @@ TMainForm = class(TForm, IServiceConfigEvents)
eHDHRListenHTTPPort: TEdit;
eHDHRListenIP: TEdit;
Label4: TLabel;
GroupBox1: TGroupBox;
Splitter3: TSplitter;
eDebugIP: TEdit;
Label5: TLabel;
btnDebugDiscoveryRequest: TButton;
lblSelectedChannels: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure lbChannelsChangeCheck(Sender: TObject);
Expand All @@ -85,6 +93,7 @@ TMainForm = class(TForm, IServiceConfigEvents)
procedure btnRefreshChannelsClick(Sender: TObject);
procedure eHDHRListenHTTPPortChangeTracking(Sender: TObject);
procedure eHDHRListenIPChangeTracking(Sender: TObject);
procedure btnDebugDiscoveryRequestClick(Sender: TObject);
private
{ Private declarations }
fConfigManager: IServiceConfigManager;
Expand All @@ -102,6 +111,7 @@ TMainForm = class(TForm, IServiceConfigEvents)
procedure Save(const aSections: TServiceConfigSections);

procedure UpdateInterface;
procedure UpdateChannelCount;
procedure FillChannels;
procedure FillTunerStatistics;

Expand Down Expand Up @@ -237,6 +247,8 @@ procedure TMainForm.FillChannels;
end
else
lbChannels.Enabled := False;

UpdateChannelCount;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
Expand Down Expand Up @@ -264,38 +276,12 @@ procedure TMainForm.lbChannelsChangeCheck(Sender: TObject);
ConfigManager.UnlockConfig(lConfig);
end;

updateChannelCount;

Save([TServiceConfigSection.Channels]);
end;
end;

{procedure TMainForm.GetConfig;
var
lOldConfig, lNewConfig: TServiceConfig;
begin
lOldConfig := TServiceConfig.Create;
lNewConfig := TServiceConfig.Create;
try
lOldConfig.Ceton.ChannelMap.Exclude := lOldConfig.Ceton.ChannelMap.Exclude + [TChannelMapSection.Items];
lOldConfig.Assign(fConfig);
lNewConfig.Ceton.ChannelMap.Exclude := lNewConfig.Ceton.ChannelMap.Exclude + [TChannelMapSection.Items];
ProxyServiceModule.GetConfig(lNewConfig);
if lNewConfig.ToJSON <> lOldConfig.ToJSON then
begin
// Do not reload channels on every change
lbChannels.Clear;
fConfig.Assign(lNewConfig);
UpdateInterface;
end;
finally
lNewConfig.Free;
lOldConfig.Free;
end;
end;}

procedure TMainForm.BeginInterfaceUpdate;
begin
Inc(fInterfaceUpdateCount);
Expand Down Expand Up @@ -531,4 +517,36 @@ procedure TMainForm.eHDHRListenIPChangeTracking(Sender: TObject);
end;
end;

procedure TMainForm.btnDebugDiscoveryRequestClick(Sender: TObject);
var
lDiscovery: TDiscoveryData;
lBytes: TBytes;
begin
lDiscovery.DeviceType := HDHOMERUN_DEVICE_TYPE_TUNER;
lDiscovery.DeviceID := HDHOMERUN_DEVICE_ID_WILDCARD;

lBytes := TPacket.FromDiscovery(True, lDiscovery).ToBytes;

ProxyServerModule.DiscoveryServer.SendBuffer(eDebugIP.Text, HDHR_DISCOVERY_PORT, TIdBytes(lBytes));
// ProxyServerModule.DiscoveryServer.Broadcast(TIdBytes(lBytes), HDHR_DISCOVERY_PORT);
end;

procedure TMainForm.UpdateChannelCount;
var
i, lChannelCount: Integer;
begin
if fEditingChannels then
begin
lChannelCount := 0;
for i := 0 to lbChannels.Items.Count-1 do
begin
if (TChannelListBoxItem(lbChannels.ListItems[i]).IsChecked) then
Inc(lChannelCount);
end;
lblSelectedChannels.Text := Format('(%d selected)', [lChannelCount]);
end
else
lblSelectedChannels.Text := '';
end;

end.
4 changes: 2 additions & 2 deletions ProxyServerModuleUnit.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ object ProxyServerModule: TProxyServerModule
Left = 88
Top = 56
end
object ConfigTimer: TTimer
OnTimer = ConfigTimerTimer
object ServiceTimer: TTimer
OnTimer = ServiceTimerTimer
Left = 144
Top = 56
end
Expand Down
Loading

0 comments on commit 2ad5d78

Please sign in to comment.