This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
242 lines (186 loc) · 5.78 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
package main
import (
"flag"
"io"
"log"
"github.com/aksiksi/gelatin/emby"
"github.com/aksiksi/gelatin/jellyfin"
gelatin "github.com/aksiksi/gelatin/lib"
)
var (
jellyfinAdminUser string
jellyfinAdminPass string
embyAdminUser string
embyAdminPass string
)
func verifyJellyfin() {
client := jellyfin.NewJellyfinApiClient("http://192.168.0.99:8097", nil)
if err := client.System().Ping(); err != nil {
log.Fatalf("failed to ping: %s", err)
}
adminKey, err := client.User().Authenticate(jellyfinAdminUser, jellyfinAdminPass)
if err != nil {
log.Fatal("failed to authenticate")
}
client.SetApiKey(adminKey)
systemInfo, err := client.System().Info(true)
if err != nil {
log.Fatalf("failed to get system info: %s", err)
}
log.Printf("Jellyfin info: %+v", systemInfo)
logsInfo, err := client.System().GetLogs()
if err != nil {
log.Fatalf("failed to get system logs: %s", err)
}
log.Printf("Jellyfin logs: %+v", logsInfo)
logName, logSize := logsInfo[0].Name, logsInfo[0].Size
data, err := client.System().GetLogFile(logName)
if err != nil {
log.Fatalf("failed to get system log %s: %s", logName, err)
}
logData, _ := io.ReadAll(data)
log.Printf("got log %s, size = %d, expected = %d", logName, len(logData), logSize)
// Query public users
_, err = client.User().GetUsers(true)
if err != nil {
log.Fatalf("failed to query users: %s", err)
}
// Query available users
users, err := client.User().GetUsers(false)
if err != nil {
log.Fatalf("failed to query users: %s", err)
}
log.Printf("Users count: %d", len(users))
// Create a new user
user, err := client.User().CreateUser("test123")
if err != nil {
log.Fatalf("failed to create new user: %s", err)
}
log.Printf("User: %v", user)
// Set user password
err = client.User().UpdatePassword(user.Id, "", "abcd1234", false)
log.Printf("%v", err)
// Make the user an admin
user.Policy.IsAdministrator = true
err = client.User().UpdatePolicy(user.Id, &user.Policy)
if err != nil {
log.Fatal(err)
}
items, err := client.Library().GetItemsByUser(user.Id, map[string]string{
"IncludeItemTypes": "Movie,Series",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Num items: %d", len(items))
log.Printf("Random item: %+v", items[len(items)/2])
// Delete the user
err = client.User().DeleteUser(user.Id)
if err != nil {
log.Fatal(err)
}
}
func verifyEmby() {
client := emby.NewEmbyApiClient("http://192.168.0.99:8096", nil)
if err := client.System().Ping(); err != nil {
log.Fatalf("failed to ping: %s", err)
}
adminKey, err := client.User().Authenticate(embyAdminUser, embyAdminPass)
if err != nil {
log.Fatalf("failed to authenticate")
}
client.SetApiKey(adminKey)
resp, err := client.System().Info(true)
if err != nil {
log.Fatalf("failed to get system info: %s", err)
}
log.Printf("Emby info: %+v", resp)
logsInfo, err := client.System().GetLogs()
if err != nil {
log.Fatalf("failed to get system logs: %s", err)
}
log.Printf("Emby logs: %+v", logsInfo)
logName, logSize := logsInfo[0].Name, logsInfo[0].Size
data, err := client.System().GetLogFile(logName)
if err != nil {
log.Fatalf("failed to get system log %s: %s", logName, err)
}
logData, _ := io.ReadAll(data)
log.Printf("got log %s, size = %d, expected = %d", logName, len(logData), logSize)
// Query public users
_, err = client.User().GetUsers(true)
if err != nil {
log.Fatalf("failed to query users: %s", err)
}
// Query available users
users, err := client.User().GetUsers(false)
if err != nil {
log.Fatalf("failed to query users: %s", err)
}
log.Printf("Users count: %d", len(users))
// Create a new user
user, err := client.User().CreateUser("test123")
if err != nil {
log.Fatalf("failed to create new user: %s", err)
}
log.Printf("User: %v", user)
// Set user password
err = client.User().UpdatePassword(user.Id, "", "abcd1234", false)
log.Printf("%v", err)
// Make the user an admin
user.Policy.IsAdministrator = true
err = client.User().UpdatePolicy(user.Id, &user.Policy)
if err != nil {
log.Fatal(err)
}
items, err := client.Library().GetItemsByUser(user.Id, map[string]string{
"IncludeItemTypes": "Movie,Series",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Num items: %d", len(items))
log.Printf("Random item: %+v", items[len(items)/2])
// Delete the user
err = client.User().DeleteUser(user.Id)
if err != nil {
log.Fatal(err)
}
}
func verifyGelatinClient() {
embyClient := emby.NewEmbyApiClient("http://192.168.0.99:8096", nil)
embyKey, _ := embyClient.User().Authenticate(embyAdminUser, embyAdminPass)
embyClient.SetApiKey(embyKey)
jellyfinClient := jellyfin.NewJellyfinApiClient("http://192.168.0.99:8097", nil)
jellyfinKey, _ := jellyfinClient.User().Authenticate(jellyfinAdminUser, jellyfinAdminPass)
jellyfinClient.SetApiKey(jellyfinKey)
opts := &gelatin.GelatinClientOpts{Interactive: true}
client := gelatin.NewGelatinClient(embyClient, jellyfinClient, opts)
userDiff, err := client.DiffUsers(false)
if err != nil {
log.Fatal(err)
}
log.Printf("User diff: %s", userDiff)
if err := client.MigrateUsers(nil); err != nil {
log.Fatal(err)
}
if err := client.MigrateUserWatchHistory("tksiksi"); err != nil {
log.Print(err)
}
}
func main() {
flag.StringVar(&jellyfinAdminUser, "jellyfin-admin-user", "", "Jellyfin admin username")
flag.StringVar(&jellyfinAdminPass, "jellyfin-admin-pass", "", "Jellyfin admin password")
flag.StringVar(&embyAdminUser, "emby-admin-user", "", "Emby admin username")
flag.StringVar(&embyAdminPass, "emby-admin-pass", "", "Emby admin password")
flag.Parse()
if jellyfinAdminUser == "" || jellyfinAdminPass == "" {
log.Fatal("Jellyfin admin info must be specified")
}
if embyAdminUser == "" || embyAdminPass == "" {
log.Fatal("Emby admin info must be specified")
}
verifyEmby()
verifyJellyfin()
verifyGelatinClient()
}