-
Notifications
You must be signed in to change notification settings - Fork 102
/
main.go
264 lines (257 loc) · 8.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package main
import (
_ "embed"
"fmt"
"log"
"os"
"time"
"github.com/jiotv-go/jiotv_go/v3/cmd"
"github.com/jiotv-go/jiotv_go/v3/internal/constants"
"github.com/urfave/cli/v2"
)
//go:embed VERSION
var version string
func main() {
// Set JioTV Go version
constants.Version = version
// Remove Date time from log
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
app := &cli.App{
Name: "JioTV Go",
Usage: "Stream JioTV on any device",
HelpName: "jiotv_go",
Version: version,
Copyright: "© JioTV Go (https://github.com/jiotv-go/jiotv_go)",
Compiled: time.Now(),
Suggest: true,
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"run", "start"},
Usage: "Start JioTV Go server",
Description: "The serve command starts JioTV Go server, and listens on the host and port. The default host is localhost and port is 5001.",
Action: func(c *cli.Context) error {
if c.Bool("skip-update-check") {
fmt.Println("INFO: Skipping update check")
} else {
cmd.PrintIfUpdateAvailable(c)
}
host := c.String("host")
// overwrite host if --public flag is passed
if c.Bool("public") {
fmt.Println("INFO: You are exposing your server to outside your local network (public)!")
fmt.Println("INFO: Overwriting host to [::] for public access")
host = "[::]"
}
port := c.String("port")
configPath := c.String("config")
tls := c.Bool("tls")
tlsCertPath := c.String("tls-cert")
tlsKeyPath := c.String("tls-key")
return cmd.JioTVServer(cmd.JioTVServerConfig{
Host: host,
Port: port,
ConfigPath: configPath,
TLS: tls,
TLSCertPath: tlsCertPath,
TLSKeyPath: tlsKeyPath,
})
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: "",
Usage: "Path to config file",
},
&cli.StringFlag{
Name: "host",
Aliases: []string{"H"},
Value: "localhost",
Usage: "Host to listen on",
},
&cli.StringFlag{
Name: "port",
Aliases: []string{"p"},
Value: "5001",
Usage: "Port to listen on",
},
&cli.BoolFlag{
Name: "public",
Aliases: []string{"P"},
Usage: "Open server to public. This will expose your server outside your local network. Equivalent to passing --host [::]",
},
&cli.BoolFlag{
Name: "tls",
Aliases: []string{"https"},
Usage: "Enable TLS. This will enable HTTPS for the server.",
},
&cli.StringFlag{
Name: "tls-cert",
Aliases: []string{"cert"},
Value: "",
Usage: "Path to TLS certificate file",
},
&cli.StringFlag{
Name: "tls-key",
Aliases: []string{"cert-key"},
Value: "",
Usage: "Path to TLS key file",
},
&cli.BoolFlag{
Name: "skip-update-check",
Usage: "Skip checking for update on startup",
},
},
},
{
Name: "update",
Aliases: []string{"upgrade", "u"},
Usage: "Update JioTV Go to latest version",
Description: "The update command updates JioTV Go by identifying the operating system and architecture, downloading the latest release from GitHub, and replacing the current binary with the latest one.",
Action: func(c *cli.Context) error {
return cmd.Update(c.App.Version, c.String("version"))
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Aliases: []string{"v"},
Value: "",
Usage: "Update to a custom specific version that is not latest",
},
},
},
{
Name: "epg",
Aliases: []string{"e"},
Usage: "Manage EPG",
Description: "The epg command manages EPG. It can be used to generate EPG, regenerate EPG, and delete EPG.",
Subcommands: []*cli.Command{
{
Name: "generate",
Aliases: []string{"gen", "g"},
Usage: "Generate EPG",
Description: "The generate command generates EPG by downloading the latest EPG from JioTV, and saving it to epg.xml.gz. It will delete the existing EPG file if it exists. Once the EPG file is generated, it will automatically updated by the server. If you want to disable, do epg delete command.",
Action: func(c *cli.Context) error {
return cmd.GenEPG()
},
},
{
Name: "delete",
Aliases: []string{"del", "d"},
Usage: "Delete EPG",
Description: "The delete command deletes the existing EPG file if it exists. This will disable EPG on the server.",
Action: func(c *cli.Context) error {
return cmd.DeleteEPG()
},
},
},
},
{
Name: "login",
Aliases: []string{"l"},
Usage: "Manage login",
Description: "The login command manages login. It can be used to login, logout.",
Subcommands: []*cli.Command{
{
Name: "otp",
Aliases: []string{"o"},
Usage: "Login using OTP",
Description: "The otp command logs you in using OTP. It will send OTP to your mobile number, and you have to enter the OTP to login.",
Action: func(c *cli.Context) error {
return cmd.LoginOTP()
},
},
{
Name: "password",
Aliases: []string{"p"},
Usage: "Login using password",
Description: "The password command logs you in using password. It will ask for your username and password, and login using that.",
Action: func(c *cli.Context) error {
return cmd.LoginPassword()
},
},
{
Name: "reset",
Aliases: []string{"lo", "logout"},
Usage: "Logout",
Description: "The logout command logs you out. It will delete the login file.",
Action: func(c *cli.Context) error {
return cmd.Logout()
},
},
},
},
{
Name: "autostart",
Usage: "Manage auto start for bash shell",
Description: "The autostart command manages auto start for bash shell. It can be used to enable or disable auto start. We only support BASH Terminal and recommend on Android Termux.",
Action: func(c *cli.Context) error {
return cmd.AutoStart(c.String("args"))
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "args",
Aliases: []string{"a"},
Value: "",
Usage: "String Value Arguments passed to serve/run/start command while auto starting",
},
},
},
{
Name: "background",
Aliases: []string{"bg"},
Usage: "Run JioTV Go server in the background",
Subcommands: []*cli.Command{
{
Name: "start",
Aliases: []string{"run", "r"},
Usage: "Run JioTV Go server in the background",
Description: "The run command starts JioTV Go server in the background. It runs the JioTVServer function in a separate goroutine.",
Action: func(c *cli.Context) error {
cmd.PrintIfUpdateAvailable(c)
args := c.String("args")
configPath := c.String("config")
return cmd.RunInBackground(args, configPath)
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "args",
Aliases: []string{"a"},
Value: "",
Usage: "String Value Arguments passed to serve/run command while running in the background",
},
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: "",
Usage: "Path to config file",
},
},
},
{
Name: "stop",
Aliases: []string{"k", "kill"},
Usage: "Stop JioTV Go server running in the background",
Description: "The stop command stops the JioTV Go server running in the background.",
Action: func(c *cli.Context) error {
configPath := c.String("config")
return cmd.StopBackground(configPath)
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: "",
Usage: "Path to config file",
},
},
},
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}