Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
damiva authored Jan 28, 2022
1 parent cb142e4 commit 0a02720
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 112 deletions.
1 change: 1 addition & 0 deletions assets/Russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
"Compress": "сжатый",
"LIFO": "Сначало новые",
"Up": "Наверх",
"FFmpeg": "Номер порта для FFmpeg",
"About":"- ПО для просмотра контента пользователя и разработки пользовательских плагинов.{br}Данное ПО не предоставляет никакого видео/аудио контента само по себе!"
}
}
1 change: 1 addition & 0 deletions assets/Ukrainian.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
"HasUpdate":"Є оновлення",
"LIFO": "Спочатку нові",
"Up": "Нагору",
"FFmpeg": "Номер порта для FFmpeg",
"About":"- ПЗ для перегляду контенту користувача та розробки плагінів користувача.{br}Дане ПЗ не надає ніякого відео/аудіо контенту саме по собі!"
}
}
139 changes: 86 additions & 53 deletions assets/index.html

Large diffs are not rendered by default.

Binary file modified assets/index.html.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions dialogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func init() {
log.Println(e)
}
boxText[id] = stg.Data
if _, o := boxLang[id]; !o {
boxLang[id] = keyboards[true] != ""
}
if q.Has("addr") {
id += "&addr"
}
Expand Down
58 changes: 58 additions & 0 deletions ffmpeg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"log"
"net/http"
"os"
"os/exec"
"strings"
"time"
)

var logFFmpeg bool
var ffmpegRun *exec.Cmd

func ffmpeg(r *http.Request, src string, args [2][]string) (addr string, err error) {
if stg.FFmpegCMD != "" || stg.FFmpegPORT != "" {
clearFFmpeg()
addr = "http://" + r.Host[:strings.LastIndexByte(r.Host, ':')+1] + stg.FFmpegPORT
args[0] = append(append(args[0], "-i", src), append(args[1], "-listen", "1", addr)...)
mutexF.Lock()
ffmpegRun = exec.Command(stg.FFmpegCMD, args[0]...)
if logFFmpeg {
ffmpegRun.Stdout, ffmpegRun.Stderr = os.Stdout, os.Stderr
} else {
ffmpegRun.Stdout, ffmpegRun.Stderr = nil, nil
}
out.Println(stg.FFmpegCMD, strings.Join(args[0], " "))
if err = ffmpegRun.Start(); err == nil {
go waitFFmpeg()
time.Sleep(time.Second)
}
}
return
}
func checkFFmpeg() (e error) {
c := stg.FFmpegCMD
if c == "" {
c = "ffmpeg"
}
if c, e = exec.LookPath(c); e == nil {
stg.FFmpegCMD = c
}
return
}
func clearFFmpeg() {
if ffmpegRun != nil {
if e := ffmpegRun.Process.Kill(); e != nil {
log.Println("kill ffmpeg error:", e)
}
}
}
func waitFFmpeg() {
if e := ffmpegRun.Wait(); e != nil {
log.Println("ffmpeg:", e)
}
ffmpegRun = nil
mutexF.Unlock()
}
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ import (
)

var (
out = log.New(os.Stdout, "(i) ", log.Flags())
mutex = new(sync.Mutex)
out = log.New(ioutil.Discard, "(i) ", log.Flags())
mutexR = new(sync.Mutex)
mutexF = new(sync.Mutex)
mypath string
started = time.Now()
)

func restart() {
mutex.Lock()
log.Println("Restarting...")
clearFFmpeg()
mutexR.Lock()
os.Exit(0)
}
func check(e error) {
Expand All @@ -55,17 +57,18 @@ func check(e error) {
func main() {
var e error
defer log.Fatalln(recover())
log.SetPrefix("<!> ")
mypath, e = os.Executable()
check(e)
for _, a := range os.Args[1:] {
switch a {
case "-t":
out.SetFlags(0)
log.SetFlags(0)
case "-i":
log.SetPrefix("")
out.SetOutput(ioutil.Discard)
case "+i":
log.SetPrefix("<!> ")
out.SetOutput(os.Stdout)
case "+f":
logFFmpeg = true
case "-s":
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
case "-d":
Expand Down Expand Up @@ -97,6 +100,9 @@ func main() {
log.Println(e)
}
}
if e = checkFFmpeg(); e != nil {
log.Println(e)
}
out.Println(Name, "v.", Vers, "listening at", server.Addr)
check(server.ListenAndServe())
}
21 changes: 13 additions & 8 deletions maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func init() {
}
check(download(u, mypath+".new", nil))
check(os.Chmod(mypath+".new", 0777))
mutex.Lock()
defer mutex.Unlock()
mutexR.Lock()
defer mutexR.Unlock()
check(os.Rename(mypath, mypath+".old"))
if e := os.Rename(mypath+".new", mypath); e != nil {
os.Rename(mypath+".old", mypath)
Expand All @@ -60,12 +60,16 @@ func init() {
}
}
if as[0] != "" {
svcAnswer(w, "execute:http://"+r.Host+"/msx/dialog", dialogStg{
"execute:fetch:http://" + r.Host + "/update?link=" + strings.Join(as, "&dic="),
"{dic:CheckUp|Check updates}:",
Name,
"{dic:HasUpdate|There are updates}:{br}" + Name + " {dic:label:version|Version} " + i.Tag_name + "{br}{br}{dix:Update}Would you like to update?",
})
if r.FormValue("v") == "" {
w.Write([]byte(`{"link":"` + strings.Join(as, "&dic=") + `","tag":"` + i.Tag_name + `"}`))
} else {
svcAnswer(w, "execute:http://"+r.Host+"/msx/dialog", dialogStg{
"execute:fetch:http://" + r.Host + "/update?link=" + strings.Join(as, "&dic="),
"{dic:CheckUp|Check updates}:",
Name,
"{dic:HasUpdate|There are updates}:{br}" + Name + " {dic:label:version|Version} " + i.Tag_name + "{br}{br}{dix:Update}Would you like to update?",
})
}
return
}
}
Expand Down Expand Up @@ -114,6 +118,7 @@ func init() {
panic(e)
}
}
w.Write([]byte("true"))
})
}
func download(src string, dst, opt interface{}) error {
Expand Down
40 changes: 24 additions & 16 deletions menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
} else {
pls += " {col:msx-white}{ico:toggle-on} html5x"
}
l := &plist{Logo: u + "/logotype.png", Menu: []plistObj{ /*{"icon": "history", "label": "{dic:Recent|Continue}...", "data": u + "/msx/recent?id={ID}"}*/ }}
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}"
Expand Down Expand Up @@ -86,22 +86,30 @@ func init() {
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}", "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", "label": "{dic:label:application|Application}", "icon": "monitor", "extensionIcon": "menu-open", "action": "dialog:application"},
}}}}})
"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)
})
}
4 changes: 2 additions & 2 deletions plist.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func mediaList(r *http.Request, hdr, ext, ico string, opt []plistObj, optEach bo
rtn := &plist{
Type: "list", Head: hdr, Ext: ext, Compress: cmp,
Template: plistObj{
"icon": "msx-white-soft:" + ico,
"icon": ico,
"type": "control",
"layout": lay,
"progress": -1,
Expand Down Expand Up @@ -106,7 +106,7 @@ func options(opts ...plistObj) plistObj {
cap := "{dic:caption:options|Options}:"
for i := 0; i < len(opts); i++ {
if opts[i] == nil {
opts[i] = plistObj{"key": "yellow", "label": "{dic:Up|Up}", "action": "focus:index:0"}
opts[i] = plistObj{"key": "yellow", "label": "{dic:Up|Up}", "action": "[cleanup|focus:index:0]"}
}
cap += "{tb}{ico:msx-" + opts[i]["key"].(string) + ":stop} " + opts[i]["label"].(string)
opts[i]["icon"] = "msx-" + opts[i]["key"].(string) + ":stop"
Expand Down
70 changes: 45 additions & 25 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"os"
"os/exec"
"runtime"
"strings"
"time"
Expand All @@ -13,8 +14,8 @@ import (
const pthSettings, cHTML5X, cCompressed, cPhoto, cMarksLIFO = "settings.json", 1, 2, 4, 8

type settings struct {
TorrServer string
Clients map[string]int
TorrServer, FFmpegCMD, FFmpegPORT string
Clients map[string]int
}
type client struct{ Addr, Platform, Player, Vers string }

Expand All @@ -24,11 +25,12 @@ var (
)

func init() {
stg.FFmpegPORT = "8009"
http.Handle("/settings", stg)
}
func (s *settings) save() (e error) {
var f *os.File
mutex.Lock()
mutexR.Lock()
if f, e = os.Create(pthSettings); e == nil {
j := json.NewEncoder(f)
j.SetIndent("", " ")
Expand All @@ -37,7 +39,7 @@ func (s *settings) save() (e error) {
}
f.Close()
}
mutex.Unlock()
mutexR.Unlock()
return
}
func (s *settings) load() (e error) {
Expand All @@ -58,37 +60,55 @@ func (s *settings) load() (e error) {
func (s *settings) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
var (
i struct{ Data interface{} }
i struct {
Code string
Data interface{}
}
a = "error:Unknown operation!"
d interface{}
)
check(json.NewDecoder(r.Body).Decode(&i))
switch v := i.Data.(type) {
case string:
a, d = s.setTorr(v, !r.URL.Query().Has("v"))
check(s.save())
case float64:
s.Clients[r.URL.Query().Get("id")] ^= int(v)
if i.Code != "" {
if i.Code[0] == '#' {
s.FFmpegCMD = i.Code[1:]
if s.FFmpegCMD != "" {
var e error
s.FFmpegCMD, e = exec.LookPath(i.Code[1:])
check(e)
}
} else {
s.FFmpegPORT = i.Code
}
a = "[back|reload:menu]"
check(s.save())
a = "reload:menu"
case map[string]interface{}:
for _, k := range [3]string{pthVideo, pthMusic, pthPhoto} {
if s, o := v[k].(string); o {
if e := os.Remove(k); e != nil && !os.IsNotExist(e) {
panic(e)
} else if s != "" {
if i, e := os.Stat(s); e != nil {
} else {
switch v := i.Data.(type) {
case string:
a, d = s.setTorr(v, !r.URL.Query().Has("v"))
check(s.save())
case float64:
s.Clients[r.URL.Query().Get("id")] ^= int(v)
check(s.save())
a = "reload:menu"
case map[string]interface{}:
for _, k := range [3]string{pthVideo, pthMusic, pthPhoto} {
if s, o := v[k].(string); o {
if e := os.Remove(k); e != nil && !os.IsNotExist(e) {
panic(e)
} else if !i.IsDir() {
panic(s + " is not a directory!")
} else if s != "" {
if i, e := os.Stat(s); e != nil {
panic(e)
} else if !i.IsDir() {
panic(s + " is not a directory!")
}
check(os.Symlink(s, k))
}
check(os.Symlink(s, k))
}
}
a = "info:OK"
default:
a, d = s.inputTorr(r.Host)
}
a = "info:OK"
default:
a, d = s.inputTorr(r.Host)
}
svcAnswer(w, a, d)
} else {
Expand Down
Loading

0 comments on commit 0a02720

Please sign in to comment.