-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
436 lines (424 loc) · 10.4 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
// ====================================================
// GMDB Copyright(C) 2019 Furkan Türkal
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================
package main
import (
"fmt"
"os"
"time"
"github.com/Dentrax/GMDB/models"
"github.com/Dentrax/GMDB/pkg"
"github.com/Dentrax/GMDB/pkg/config"
"github.com/Dentrax/GMDB/services"
"github.com/urfave/cli/v2"
)
var DefaultPrinter *services.Printer
func main() {
app := &cli.App{}
app.Name = "GMDB"
app.Version = "Alpha v0.1.0"
app.Compiled = time.Now()
app.Authors = []*cli.Author{
&cli.Author{
Name: "Furkan Turkal",
},
}
app.Copyright = "(c) 2020 - Dentrax"
app.Usage = "gmdb"
app.ArgsUsage = "[args and such]"
app.HideHelp = false
app.HideVersion = false
app.Commands = []*cli.Command{
{
Name: "search",
Usage: "Do Search!",
UsageText: "usg text",
Description: "desc",
ArgsUsage: "[arg]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all, a",
Usage: "Search all supported sites (ignore others)",
},
&cli.BoolFlag{
Name: "imdb, i",
Usage: "Search in IMDB",
},
&cli.BoolFlag{
Name: "rottentomatoes, r",
Usage: "Search in RottenTomatoes",
},
&cli.StringFlag{
Name: "url, u",
Usage: "Usage u",
},
&cli.StringFlag{
Name: "search, s",
Usage: "Usage s",
},
&cli.StringFlag{
Name: "filename, f",
Usage: "Usage f",
},
&cli.BoolFlag{
Name: "title, ft",
Usage: "Filter the output by Title",
},
&cli.BoolFlag{
Name: "year, fy",
Usage: "Filter the output by Year",
},
&cli.BoolFlag{
Name: "released, fr",
Usage: "Filter the output by Released",
},
&cli.BoolFlag{
Name: "duration, fz",
Usage: "Filter the output by Duration",
},
&cli.BoolFlag{
Name: "summary, fk",
Usage: "Filter the output by Summary",
},
&cli.BoolFlag{
Name: "directors, fd",
Usage: "Filter the output by Directors",
},
&cli.BoolFlag{
Name: "writers, fw",
Usage: "Filter the output by Writers",
},
&cli.BoolFlag{
Name: "stars, fp",
Usage: "Filter the output by Stars",
},
&cli.BoolFlag{
Name: "genres, fg",
Usage: "Filter the output by Genres",
},
&cli.BoolFlag{
Name: "tagline, fT",
Usage: "Filter the output by Tagline",
},
&cli.BoolFlag{
Name: "summaries, fS",
Usage: "Filter the output by Summaries",
},
&cli.BoolFlag{
Name: "keywords, fK",
Usage: "Filter the output by Keywords",
},
&cli.BoolFlag{
Name: "parental, fP",
Usage: "Filter the output by Parental",
},
},
Action: func(c *cli.Context) error {
filter := models.ResultFilter{}
leastOne := false
if c.Bool("title") {
filter.Title = true
leastOne = true
}
if c.Bool("year") {
filter.Year = true
leastOne = true
}
if c.Bool("released") {
filter.Released = true
leastOne = true
}
if c.Bool("rating") {
filter.Rating = true
leastOne = true
}
if c.Bool("duratin") {
filter.Duration = true
leastOne = true
}
if c.Bool("summary") {
filter.Summary = true
leastOne = true
}
if c.Bool("directors") {
filter.Directors = true
leastOne = true
}
if c.Bool("writers") {
filter.Writers = true
leastOne = true
}
if c.Bool("stars") {
filter.Stars = true
leastOne = true
}
if c.Bool("genres") {
filter.Genres = true
leastOne = true
}
if c.Bool("tagline") {
filter.Tagline = true
leastOne = true
}
if c.Bool("summaries") {
filter.Summaries = true
leastOne = true
}
if c.Bool("parental") {
filter.ParentsGuide = true
leastOne = true
}
if c.Bool("keywords") {
filter.Keywords = true
leastOne = true
}
if c.Bool("all") {
filter.Title = true
filter.Year = true
filter.Released = true
filter.Rating = true
filter.Duration = true
filter.Summary = true
filter.Directors = true
filter.Writers = true
filter.Stars = true
filter.Genres = true
filter.Tagline = true
filter.Summaries = true
filter.Keywords = true
filter.ParentsGuide = true
} else {
if !leastOne {
filter.Title = true
filter.Year = true
filter.Released = true
filter.Rating = true
filter.Duration = true
filter.Summary = true
filter.Directors = true
filter.Writers = true
filter.Stars = true
filter.Genres = true
filter.Tagline = true
filter.Summaries = false
filter.Keywords = true
filter.ParentsGuide = true
}
}
if c.NArg() > 0 {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleSearchTitleRequest(c)
} else {
return cli.NewExitError("No keywords provided", 1)
}
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "learn",
Usage: "Learn and store your Netflix data",
UsageText: "usg text",
Description: "desc",
ArgsUsage: "[arg]",
Action: func(c *cli.Context) error {
if c.NArg() > 0 {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleLearnRequest(c)
} else {
return cli.NewExitError("No keywords provided", 1)
}
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "history",
Usage: "See the search history",
UsageText: "hst text",
Description: "desc",
ArgsUsage: "[arg]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all, a",
Usage: "Get all histories both of search and watch",
},
&cli.BoolFlag{
Name: "search, s",
Usage: "Get search histories",
},
&cli.BoolFlag{
Name: "watch, w",
Usage: "Get watch histories",
},
},
Action: func(c *cli.Context) error {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleHistoryRequest(c)
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "list",
Usage: "List your movies and watch laters",
UsageText: "lst text",
Description: "desc",
ArgsUsage: "[arg]",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all, a",
Usage: "Get all lists both of Watch Later(s) and Like(s)",
},
&cli.BoolFlag{
Name: "watch, w",
Usage: "Get Watch Later list",
},
&cli.BoolFlag{
Name: "like, l",
Usage: "Get Movie Likes list",
},
},
Action: func(c *cli.Context) error {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleMyListRequest(c)
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "note",
Usage: "Write a note for a movie",
UsageText: "nt text",
Description: "desc",
ArgsUsage: "[arg]",
Action: func(c *cli.Context) error {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleNoteRequest(c)
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "torrent",
Usage: "Search on Torrent",
UsageText: "trrnt text",
Description: "desc",
ArgsUsage: "[arg]",
Action: func(c *cli.Context) error {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleTorrentRequest(c, nil)
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
{
Name: "update",
Usage: "Update your stored database",
UsageText: "updt text",
Description: "desc",
ArgsUsage: "[arg]",
Action: func(c *cli.Context) error {
config, err := config.LoadConfig(c.String("config"))
if err != nil {
return cli.NewExitError("Failed to load config", 1)
}
gmdb := &gmdb.App{}
gmdb.Initialize(config)
gmdb.HandleUpdateRequest(c)
return nil
},
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
fmt.Fprintf(c.App.Writer, "Wrong usage: %q \n", err)
return err
},
},
}
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "nobanner, q",
Usage: "Do not print the banner",
},
&cli.StringFlag{
Name: "nocolor, x",
Usage: "Do not use color",
},
&cli.StringFlag{
Name: "config, c",
Usage: "Use custom config path",
},
}
app.Action = func(c *cli.Context) error {
if c.NArg() == 0 {
cli.ShowAppHelpAndExit(c, 1)
}
filter := models.ResultFilter{}
filter.NoBanner = false
filter.NoColor = false
if c.Bool("nobanner") {
filter.NoBanner = true
}
if c.Bool("nocolor") {
filter.NoColor = true
}
return nil
}
app.CommandNotFound = func(c *cli.Context, command string) {
fmt.Fprintf(c.App.Writer, "Wrong command: %q \n", command)
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}