-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmenu.go
115 lines (112 loc) · 5.99 KB
/
menu.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
package main
import (
"log"
"net/http"
"os"
"runtime"
"strings"
)
var startFocus string
func init() {
http.HandleFunc("/msx/start.json", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"name":"` + Name + `","version":"` + Vers + `","parameter": "menu:http://{SERVER}/msx/menu.json"}`))
})
http.HandleFunc("/msx/menu.json", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"reuse":false,"cache":false,"restore":false,"name":"` + Name + `","version":"` + Vers +
`","reference":"http://` + r.Host + `/msx/menu?player={PLAYER}&platform={PLATFORM}&id={ID}` + startFocus))
startFocus = ""
if _, e := os.Stat(pthDic); e == nil {
w.Write([]byte(`","dictionary":"http://` + r.Host + "/msx/" + pthDic))
} else if !os.IsNotExist(e) {
log.Println(e)
}
w.Write([]byte(`"}`))
})
http.HandleFunc("/msx/menu", func(w http.ResponseWriter, r *http.Request) {
pls, id, u := strings.SplitN(r.FormValue("player"), "/", 2)[0], r.FormValue("id"), "http://"+r.Host
clients[id] = client{r.RemoteAddr, r.FormValue("platform"), pls, r.FormValue("v")}
if stg.Clients[id]&cHTML5X == 0 {
pls = "{txt:msx-white:" + pls + "} {ico:msx-white:toggle-off} html5x"
} else {
pls += " {col:msx-white}{ico:toggle-on} html5x"
}
l := &plist{Logo: u + "/logotype.png", Menu: []plistObj{}}
for i, f := range [4][2]string{{pthMarks, "bookmarks"}, {pthVideo, "video-library"}, {pthMusic, "library-music"}, {pthPhoto, "photo-library"}} {
if _, e := os.Stat(f[0]); !os.IsNotExist(e) {
c, s := "folder-open", "/?id={ID}"
if i == 0 {
c, s = "cloud-queue", "?id={ID}"
}
l.Menu = append(l.Menu, plistObj{"icon": f[1], "extensionIcon": c, "label": "{dix:" + f[0] + "}My " + f[0], "data": u + "/msx/" + f[0] + s})
}
}
ta := "{dic:label:none|None}"
if stg.TorrServer != "" {
ta = "{col:msx-white}" + stg.TorrServer
l.Menu = append(l.Menu, plistObj{"image": "http://" + stg.TorrServer + "/apple-touch-icon.png", "extensionIcon": "bolt", "label": "{dic:Torrents|My torrents}", "data": u + "/msx/torr?id={ID}"})
}
l.Menu = append(l.Menu, plistObj{"type": "separator"})
if ps, e := plugsInfo(); e == nil {
ml := len(l.Menu)
for _, p := range ps {
if p.Error == "" {
if !p.Torrent || stg.TorrServer != "" {
m := plistObj{"label": p.Label}
if p.Torrent {
m["extensionIcon"] = "bolt"
} else {
m["extensionIcon"] = "cloud-queue"
}
if p.Label == "" {
m["label"] = p.Name
}
if p.URL == "" {
m["data"] = u + "/" + p.Name + "/"
} else {
m["data"] = strings.ReplaceAll(p.URL, "{BASE_URL}", u+"/"+p.Name+"/")
}
if p.Image != "" {
m["image"] = strings.ReplaceAll(p.Image, "{BASE_URL}", u+"/"+p.Name+"/")
} else if p.Icon != "" {
m["icon"] = p.Icon
}
l.Menu = append(l.Menu, m)
}
}
}
if len(l.Menu) > ml {
l.Menu = append(l.Menu, plistObj{"type": "separator"})
}
}
ts := started.UnixMilli()
lst := "{txt:msx-white:dic:Default|default} {ico:msx-white:toggle-off} {dic:Compress|compressed}"
if stg.Clients[id]&cCompressed != 0 {
lst = "{dic:Default|default} {col:msx-white}{ico:toggle-on} {dic:Compress|compressed}"
}
ffport := stg.FFmpegPORT
if ffport == "" {
ffport = "{dic:label:none|none}"
} else {
ffport = "{col:msx-white}" + ffport
}
l.Menu = append(l.Menu, plistObj{"id": "stg", "icon": "settings", "label": "{dic:label:settings|Settings}",
"data": plistObj{"extension": "{ico:msx-white:settings}", "options": options(plistObj{"key": "red", "label": "{dic:label:reload|Reload}", "action": "reload"}),
"pages": []map[string][]plistObj{{"items": {
{"type": "space", "layout": "0,0,12,2", "image": u + "/logotype.png", "imageFiller": "height", "imageWidth": 7, "imagePreload": true,
"headline": "{txt:msx-white-soft:dic:label:version|Version} " + Vers,
"titleHeader": "", "titleFooter": "{ico:http}{tb}{txt:msx-white:" + r.Host +
"}{br}{ico:hardware}{tb}{txt:msx-white:" + runtime.GOOS + "/" + runtime.GOARCH +
"}{br}{ico:web}{tb}{txt:msx-white:https://github.com/" + gitRepo + "}",
"live": plistObj{"type": "schedule", "from": ts, "to": ts, "titleHeader": "{ico:timer}{tb}{txt:msx-white:overflow:text:dhms}"}},
{"type": "space", "layout": "0,2,12,1", "text": "{txt:msx-white:" + Name + "} {dix:About}is a software for playing user's content and developing user's plugins.{br}It does not provide any video/audio content by itself!", "alignment": "center"},
{"id": "update", "type": "control", "layout": "0,3,6,1", "label": "{dic:CheckUp|Check updates}", "icon": "system-update-alt", "action": "execute:fetch:" + u + "/update"},
{"type": "control", "layout": "0,4,6,1", "icon": "smart-display", "label": "{dic:label:player|Player}:", "extensionLabel": pls, "action": "execute:" + u + "/settings?id={ID}", "data": cHTML5X},
{"type": "control", "layout": "0,5,6,1", "label": "{dic:Files|List of files}:", "icon": "format-list-bulleted", "extensionLabel": lst, "action": "execute:" + u + "/settings?id={ID}", "data": cCompressed},
{"id": "dic", "type": "control", "layout": "6,3,6,1", "icon": "language", "label": "{dic:Language|Language}:", "extensionLabel": "default", "action": "panel:" + u + "/msx/dictionary", "live": map[string]string{"type": "setup", "action": "execute:service:info:dictionary:" + u + "/msx/dictionary"}},
{"type": "control", "layout": "6,4,6,1", "icon": "bolt", "label": "TorrServer:", "extensionLabel": ta, "action": "execute:" + u + "/settings", "data": nil},
{"type": "control", "layout": "6,5,6,1", "icon": "compare", "label": "{dic:FFmpeg|Port number for FFmpeg}:", "extensionLabel": ffport, "action": "execute:code:" + u + "/settings", "data": plistObj{"headline": "{dic:FFmpeg|Port for ffmpeg}:", "value": stg.FFmpegPORT}, "enabel": stg.FFmpegCMD != ""},
//{"type": "control", "layout": "6,5,6,1", "label": "{dic:label:application|Application}", "icon": "monitor", "extensionIcon": "menu-open", "action": "dialog:application"},
}}}}})
l.write(w)
})
}