Skip to content

Commit 7b82fee

Browse files
Add advertised port (useful to put iptv-proxy behind a reverse proxy) (#77)
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
1 parent 3febbfb commit 7b82fee

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

cmd/root.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var rootCmd = &cobra.Command{
7171
conf := &config.ProxyConfig{
7272
HostConfig: &config.HostConfiguration{
7373
Hostname: viper.GetString("hostname"),
74-
Port: viper.GetInt64("port"),
74+
Port: viper.GetInt("port"),
7575
},
7676
RemoteURL: remoteHostURL,
7777
XtreamUser: config.CredentialString(xtreamUser),
@@ -80,11 +80,16 @@ var rootCmd = &cobra.Command{
8080
M3UCacheExpiration: viper.GetInt("m3u-cache-expiration"),
8181
User: config.CredentialString(viper.GetString("user")),
8282
Password: config.CredentialString(viper.GetString("password")),
83+
AdvertisedPort: viper.GetInt("advertised-port"),
8384
HTTPS: viper.GetBool("https"),
8485
M3UFileName: viper.GetString("m3u-file-name"),
8586
CustomEndpoint: viper.GetString("custom-endpoint"),
8687
}
8788

89+
if conf.AdvertisedPort == 0 {
90+
conf.AdvertisedPort = conf.HostConfig.Port
91+
}
92+
8893
server, err := server.NewServer(conf)
8994
if err != nil {
9095
log.Fatal(err)
@@ -111,15 +116,16 @@ func init() {
111116
// Here you will define your flags and configuration settings.
112117
// Cobra supports persistent flags, which, if defined here,
113118
// will be global for your application.
114-
rootCmd.PersistentFlags().StringVar(&cfgFile, "iptv-proxy-config", "C", "config file (default is $HOME/.iptv-proxy.yaml)")
115-
rootCmd.Flags().StringP("m3u-url", "u", "", `iptv m3u file or url e.g: "http://example.com/iptv.m3u"`)
116-
rootCmd.Flags().StringP("m3u-file-name", "", "iptv.m3u", `name of the new proxified m3u file e.g "http://poxy.com/iptv.m3u"`)
117-
rootCmd.Flags().StringP("custom-endpoint", "", "", `custom endpoint "http://poxy.com/<custom-endpoint>/iptv.m3u"`)
118-
rootCmd.Flags().Int64("port", 8080, "Port to expose the IPTVs endpoints")
119+
rootCmd.PersistentFlags().StringVar(&cfgFile, "iptv-proxy-config", "C", "Config file (default is $HOME/.iptv-proxy.yaml)")
120+
rootCmd.Flags().StringP("m3u-url", "u", "", `Iptv m3u file or url e.g: "http://example.com/iptv.m3u"`)
121+
rootCmd.Flags().StringP("m3u-file-name", "", "iptv.m3u", `Name of the new proxified m3u file e.g "http://poxy.com/iptv.m3u"`)
122+
rootCmd.Flags().StringP("custom-endpoint", "", "", `Custom endpoint "http://poxy.com/<custom-endpoint>/iptv.m3u"`)
123+
rootCmd.Flags().Int("port", 8080, "Iptv-proxy listening port")
124+
rootCmd.Flags().Int("advertised-port", 0, "Port to expose the IPTV file and xtream (by default, it's taking value from port) useful to put behind a reverse proxy")
119125
rootCmd.Flags().String("hostname", "", "Hostname or IP to expose the IPTVs endpoints")
120126
rootCmd.Flags().BoolP("https", "", false, "Activate https for urls proxy")
121-
rootCmd.Flags().String("user", "usertest", "user UNSAFE(temp auth to access proxy)")
122-
rootCmd.Flags().String("password", "passwordtest", "password UNSAFE(auth to access m3u proxy and xtream proxy)")
127+
rootCmd.Flags().String("user", "usertest", "User auth to access proxy (m3u/xtream)")
128+
rootCmd.Flags().String("password", "passwordtest", "Password auth to access proxy (m3u/xtream)")
123129
rootCmd.Flags().String("xtream-user", "", "Xtream-code user login")
124130
rootCmd.Flags().String("xtream-password", "", "Xtream-code password login")
125131
rootCmd.Flags().String("xtream-base-url", "", "Xtream-code base url e.g(http://expample.tv:8080)")

pkg/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c CredentialString) String() string {
3838
// HostConfiguration containt host infos
3939
type HostConfiguration struct {
4040
Hostname string
41-
Port int64
41+
Port int
4242
}
4343

4444
// ProxyConfig Contain original m3u playlist and HostConfiguration
@@ -51,6 +51,7 @@ type ProxyConfig struct {
5151
M3UFileName string
5252
CustomEndpoint string
5353
RemoteURL *url.URL
54+
AdvertisedPort int
5455
HTTPS bool
5556
User, Password CredentialString
5657
}

pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (c *Config) replaceURL(uri string, trackIndex int, xtream bool) (string, er
166166
protocol,
167167
basicAuth,
168168
c.HostConfig.Hostname,
169-
c.HostConfig.Port,
169+
c.AdvertisedPort,
170170
customEnd,
171171
uriPath,
172172
)

pkg/xtream-proxy/xtream-proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (c *Client) Action(config *config.ProxyConfig, action string, q url.Values)
150150
}
151151
respBody, err = c.GetEPG(q["stream_id"][0])
152152
default:
153-
respBody, err = c.login(config.User.String(), config.Password.String(), protocol+"://"+config.HostConfig.Hostname, int(config.HostConfig.Port), protocol)
153+
respBody, err = c.login(config.User.String(), config.Password.String(), protocol+"://"+config.HostConfig.Hostname, config.AdvertisedPort, protocol)
154154
}
155155

156156
return

0 commit comments

Comments
 (0)