forked from awesome-jellyfin/clients
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
155 lines (135 loc) · 3.76 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
package main
import (
"fmt"
"gopkg.in/yaml.v3"
"os"
"strings"
)
const (
GoodTrue = "✅"
BadTrue = "☑️"
GoodFalse = "❎"
BadFalse = "❌"
TypeMusic = "🎵"
Official = "🔹"
Beta = "🛠️"
JellyfinOrg = "https://github.com/jellyfin/"
)
func Select[T any](expr bool, whenTrue, whenFalse T) T {
if expr {
return whenTrue
}
return whenFalse
}
func Ref[T any](what T) *T {
return &what
}
func DerefDef[T any](what *T, defaultValue T) T {
if what != nil {
return *what
}
return defaultValue
}
func Deref[T any](what *T) T {
if what != nil {
return *what
}
var def T
return def
}
func main() {
data, err := os.ReadFile("clients.yaml")
if err != nil {
panic(err)
}
var config clientsConfig
if err = yaml.Unmarshal(data, &config); err != nil {
panic(err)
}
// target -> list of clients
identifierClientMap := make(map[string][]*Client)
for _, client := range config.Clients {
for _, targetStr := range client.Targets {
targetStr = strings.TrimSpace(strings.ToLower(targetStr))
identifierClientMap[targetStr] = append(identifierClientMap[targetStr], client)
}
}
for _, target := range config.Targets {
fmt.Printf("## %s\n\n", target.Display)
for has, hasDisplay := range target.Has {
fmt.Printf("### %s\n\n", hasDisplay)
fmt.Println("| Name | OSS | Free | Paid | Downloads |")
fmt.Println("|------|-----|------|------|-----------|")
for _, client := range identifierClientMap[strings.TrimSpace(strings.ToLower(has))] {
var (
name = client.Name
websiteURL string
oss, free, paid string
downloads strings.Builder
)
// if open-source and in the 'jellyfin' GitHub org, mark as official by default
if client.Official == nil && strings.HasPrefix(client.OpenSourceURL, JellyfinOrg) {
client.Official = Ref(true)
}
// make free the default price if open-source
if client.Price.Free == nil && client.OpenSourceURL != "" {
client.Price.Free = Ref(true)
}
/// Pledges
// append official badge
if Deref(client.Official) {
name += " " + Official
}
// append beta badge
if Deref(client.Beta) {
name += " " + Beta
}
// append type badges
for _, t := range client.Types {
if t == "Music" {
name += " " + TypeMusic
}
}
free = Select(DerefDef(client.Price.Free, false), GoodTrue, BadFalse)
paid = Select(DerefDef(client.Price.Paid, false), BadTrue, GoodFalse)
oss = Select(client.OpenSourceURL != "", GoodTrue, BadFalse)
if client.OpenSourceURL != "" {
websiteURL = client.OpenSourceURL
}
if client.Website != "" {
websiteURL = client.Website
}
for _, hoster := range client.Downloads {
if downloads.Len() > 0 {
downloads.WriteString(" ")
}
// Simple Text Download
if hoster.Text != "" {
downloads.WriteString(fmt.Sprintf("[%s](%s)", hoster.Text, hoster.URL))
continue
}
// Icon Download
var downloadMarkdown string
if hoster.Icon != "" {
if icon, ok := config.Icons[hoster.Icon]; ok {
downloadMarkdown = icon.Markdown(hoster.URL)
} else {
panic("cannot find icon " + hoster.Icon + " in config")
}
} else if hoster.IconURL != "" {
downloadMarkdown = (&icon{Single: hoster.IconURL}).Markdown(hoster.URL)
} else if hoster.Text != "" {
downloadMarkdown = fmt.Sprintf("[%s](%s)", hoster.Text, hoster.URL)
} else {
panic("invalid download. specify either icon, icon-url or text")
}
downloads.WriteString(strings.ReplaceAll(
strings.ReplaceAll(downloadMarkdown, "\n", ""), "\t", ""))
}
fmt.Printf("| [%s](%s) | %s | %s | %s | %s |\n",
name, websiteURL, oss, free, paid, downloads.String())
}
fmt.Println()
}
}
}