remove dependency on common from mediabrowser
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
module github.com/hrfee/jfa-go/mediabrowser
|
||||
|
||||
go 1.15
|
||||
|
||||
replace github.com/hrfee/jfa-go/common => ../common
|
||||
|
||||
require github.com/hrfee/jfa-go/common v0.0.0-20210105184019-fdc97b4e86cc
|
||||
|
||||
@@ -10,13 +10,32 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hrfee/jfa-go/common"
|
||||
)
|
||||
|
||||
// TimeoutHandler should recover from an http timeout or panic.
|
||||
type TimeoutHandler func()
|
||||
|
||||
// NewNamedTimeoutHandler returns a new Timeout handler that logs the error.
|
||||
// name is the name of the server to use in the log (e.g Jellyfin/Emby)
|
||||
// addr is the address of the server being accessed
|
||||
// if noFail is false, the program will exit on a timeout.
|
||||
func NewNamedTimeoutHandler(name, addr string, noFail bool) TimeoutHandler {
|
||||
return func() {
|
||||
if r := recover(); r != nil {
|
||||
out := fmt.Sprintf("Failed to authenticate with %s @ %s: Timed out", name, addr)
|
||||
if noFail {
|
||||
log.Print(out)
|
||||
} else {
|
||||
log.Fatalf(out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type serverType int
|
||||
|
||||
const (
|
||||
@@ -57,11 +76,11 @@ type MediaBrowser struct {
|
||||
noFail bool
|
||||
Hyphens bool
|
||||
serverType serverType
|
||||
timeoutHandler common.TimeoutHandler
|
||||
timeoutHandler TimeoutHandler
|
||||
}
|
||||
|
||||
// NewServer returns a new Mediabrowser object.
|
||||
func NewServer(st serverType, server, client, version, device, deviceID string, timeoutHandler common.TimeoutHandler, cacheTimeout int) (*MediaBrowser, error) {
|
||||
func NewServer(st serverType, server, client, version, device, deviceID string, timeoutHandler TimeoutHandler, cacheTimeout int) (*MediaBrowser, error) {
|
||||
mb := &MediaBrowser{}
|
||||
mb.serverType = st
|
||||
mb.Server = server
|
||||
|
||||
@@ -14,7 +14,6 @@ type Time struct {
|
||||
}
|
||||
|
||||
func (t *Time) UnmarshalJSON(b []byte) (err error) {
|
||||
// str := strings.TrimSuffix(strings.TrimPrefix(string(b), "\""), "\"")
|
||||
// Trim quotes from beginning and end, and any number of Zs (indicates UTC).
|
||||
for b[0] == '"' {
|
||||
b = b[1:]
|
||||
@@ -31,12 +30,6 @@ func (t *Time) UnmarshalJSON(b []byte) (err error) {
|
||||
b = b[:i]
|
||||
}
|
||||
t.Time, err = time.Parse("2006-01-02T15:04:05", string(b))
|
||||
// str := string(b) + "Z"
|
||||
// timeJSON := []byte("{ \"parseme\": \"" + str + "\" }")
|
||||
// var parsed magicParse
|
||||
// // Magically turn it into a time.Time
|
||||
// err = json.Unmarshal(timeJSON, &parsed)
|
||||
// t.Time = parsed.Parsed
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user