-
Notifications
You must be signed in to change notification settings - Fork 62
/
main.go
189 lines (175 loc) · 3.67 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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/urfave/cli"
)
const (
homeFolderName = ".plex-cli"
)
var (
isVerbose bool
)
type server struct {
Name string `json:"name"`
URL string `json:"url"`
}
func (s server) Serialize() ([]byte, error) {
return json.Marshal(s)
}
func unserializeServer(serializedServer []byte) (server, error) {
var s server
err := json.Unmarshal(serializedServer, &s)
return s, err
}
func main() {
app := cli.NewApp()
app.Name = "plex-cli"
app.Usage = "Interact with your plex server and plex.tv from the command line"
app.Version = "0.0.1"
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose",
Usage: "present more information when executing program",
Destination: &isVerbose,
},
}
app.Commands = []cli.Command{
{
Name: "test",
Usage: "Test your connection to your Plex Media Server",
Action: test,
},
{
Name: "end",
Usage: "End a transcode session",
Action: endTranscode,
},
{
Name: "server-info",
Usage: "Print info about your servers - ip, machine id, access tokens, etc",
Action: getServersInfo,
},
{
Name: "sections",
Usage: "Print info about your server's sections",
Action: getSections,
},
{
Name: "authorize-code",
Usage: "authorize an app (e.g. amazon fire app) with a 4 character `code`. REQUIRES a plex token",
Action: authorizeApp,
},
{
Name: "library",
Usage: "display your libraries",
Action: getLibraries,
},
{
Name: "link-app",
Usage: "presents a 4 character code that can be authorized via https://plex.tv/link",
Action: linkApp,
},
{
Name: "signin",
Usage: "use your username and password to receive a plex auth token",
Action: signIn,
},
{
Name: "sessions",
Usage: "display info on users currently consuming media",
Action: getSessions,
},
{
Name: "pick-server",
Usage: "choose a server to interact with",
Action: pickServer,
},
{
Name: "webhooks",
Usage: "display webhooks associated with your account",
Action: webhooks,
Flags: []cli.Flag{
cli.StringFlag{
Name: "add",
Usage: "create a new webhook",
},
cli.BoolFlag{
Name: "delete",
Usage: "delete a webhook",
},
},
},
{
Name: "search",
Usage: "search for media information on your server",
Action: search,
},
{
Name: "episode",
Usage: "get metadata of an episode of a show",
Action: getEpisode,
},
{
Name: "on-deck",
Usage: "display titles of media that is on deck",
Action: getOnDeck,
},
{
Name: "unlock",
Usage: "remove lock on pid file",
Action: unlock,
},
{
Name: "stop",
Usage: "stop playback on device",
Action: stopPlayback,
},
{
Name: "account",
Usage: "get account info from plex.tv",
Action: getAccountInfo,
},
{
Name: "metadata",
Usage: "get metadata of media on plex server",
Action: getMetadata,
},
{
Name: "download",
Usage: "download media from your plex server",
Action: downloadMedia,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "folders",
Usage: "create folder hierarchy",
},
cli.BoolFlag{
Name: "skip",
Usage: "skip download if file already exists",
},
},
},
{
Name: "playlist",
Usage: "print playlsit items on plex server",
Action: getPlaylist,
},
{
Name: "delete",
Usage: "delete a resource from your plex server",
Subcommands: []cli.Command{
{
Name: "media",
Usage: "delete media from your plex server",
Action: deleteMedia,
},
},
},
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
os.Exit(1)
}
}