Skip to content

Commit 520fb7f

Browse files
Big refactoring (#27)
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
1 parent cb94ac2 commit 520fb7f

File tree

27 files changed

+3229
-721
lines changed

27 files changed

+3229
-721
lines changed

cmd/root.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/jamesnetherton/m3u"
1110
"github.com/pierre-emmanuelJ/iptv-proxy/pkg/config"
1211

13-
"github.com/pierre-emmanuelJ/iptv-proxy/pkg/routes"
12+
"github.com/pierre-emmanuelJ/iptv-proxy/pkg/server"
1413

1514
homedir "github.com/mitchellh/go-homedir"
1615
"github.com/spf13/cobra"
@@ -25,15 +24,6 @@ var rootCmd = &cobra.Command{
2524
Short: "Reverse proxy on iptv m3u file and xtream codes server api",
2625
Run: func(cmd *cobra.Command, args []string) {
2726
m3uURL := viper.GetString("m3u-url")
28-
var err error
29-
var playlist m3u.Playlist
30-
if m3uURL != "" {
31-
playlist, err = m3u.Parse(m3uURL)
32-
if err != nil {
33-
log.Fatal(err)
34-
}
35-
}
36-
3727
remoteHostURL, err := url.Parse(m3uURL)
3828
if err != nil {
3929
log.Fatal(err)
@@ -61,7 +51,6 @@ var rootCmd = &cobra.Command{
6151
}
6252

6353
conf := &config.ProxyConfig{
64-
Playlist: &playlist,
6554
HostConfig: &config.HostConfiguration{
6655
Hostname: viper.GetString("hostname"),
6756
Port: viper.GetInt64("port"),
@@ -78,7 +67,12 @@ var rootCmd = &cobra.Command{
7867
CustomEndpoint: viper.GetString("custom-endpoint"),
7968
}
8069

81-
if e := routes.Serve(conf); e != nil {
70+
server, err := server.NewServer(conf)
71+
if err != nil {
72+
log.Fatal(err)
73+
}
74+
75+
if e := server.Serve(); e != nil {
8276
log.Fatal(e)
8377
}
8478
},
@@ -111,7 +105,7 @@ func init() {
111105
rootCmd.Flags().String("xtream-user", "", "Xtream-code user login")
112106
rootCmd.Flags().String("xtream-password", "", "Xtream-code password login")
113107
rootCmd.Flags().String("xtream-base-url", "", "Xtream-code base url e.g(http://expample.tv:8080)")
114-
rootCmd.Flags().Int("m3u-cache-expiration", 24, "M3U cache expiration in hour")
108+
rootCmd.Flags().Int("m3u-cache-expiration", 1, "M3U cache expiration in hour")
115109

116110
if e := viper.BindPFlags(rootCmd.Flags()); e != nil {
117111
log.Fatal("error binding PFlags to viper")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/pierre-emmanuelJ/iptv-proxy
33
require (
44
github.com/gin-contrib/cors v0.0.0-20190226021855-50921afdc5c1
55
github.com/gin-gonic/gin v1.3.0
6+
github.com/grafov/m3u8 v0.11.1
67
github.com/inconshreveable/mousetrap v1.0.0 // indirect
78
github.com/jamesnetherton/m3u v0.1.1-0.20180924175816-16741c7f081c
89
github.com/mitchellh/go-homedir v1.1.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
1414
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
1515
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
1616
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
17+
github.com/grafov/m3u8 v0.11.1 h1:igZ7EBIB2IAsPPazKwRKdbhxcoBKO3lO1UY57PZDeNA=
18+
github.com/grafov/m3u8 v0.11.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
1719
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
1820
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
1921
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
@@ -42,6 +44,7 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
4244
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
4345
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
4446
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
47+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4548
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4649
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
4750
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
@@ -55,6 +58,7 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
5558
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
5659
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
5760
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
61+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
5862
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
5963
github.com/tellytv/go.xtream-codes v0.0.0-20190114013623-9b74dcb500e4 h1:V5xNxrc8ApVSY2uHeVXDkByVB2iAgoOcmWOOu01oATM=
6064
github.com/tellytv/go.xtream-codes v0.0.0-20190114013623-9b74dcb500e4/go.mod h1:gWtQ2uZJ49dBh4cWiFuz7Tb5ALxLB9hY1GFoz34lsGs=

pkg/config/config.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package config
22

33
import (
44
"net/url"
5-
6-
"github.com/jamesnetherton/m3u"
75
)
86

97
// HostConfiguration containt host infos
@@ -14,7 +12,6 @@ type HostConfiguration struct {
1412

1513
// ProxyConfig Contain original m3u playlist and HostConfiguration
1614
type ProxyConfig struct {
17-
Playlist *m3u.Playlist
1815
HostConfig *HostConfiguration
1916
XtreamUser string
2017
XtreamPassword string
@@ -24,6 +21,5 @@ type ProxyConfig struct {
2421
CustomEndpoint string
2522
RemoteURL *url.URL
2623
HTTPS bool
27-
//XXX Very unsafe
28-
User, Password string
24+
User, Password string
2925
}

pkg/m3u/m3u.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)