moved GetStreamDir to util
This commit is contained in:
parent
79c7e03620
commit
94c248ba7a
2 changed files with 39 additions and 21 deletions
43
stream.go
43
stream.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -12,19 +13,18 @@ import (
|
|||
|
||||
// Stream Unexported
|
||||
type Stream struct {
|
||||
URL string
|
||||
base64 string
|
||||
streamDirPath string
|
||||
URL string `json:"url"`
|
||||
Base64 string `json:"base64"`
|
||||
Interval int `json:"interval"`
|
||||
}
|
||||
|
||||
// NewStream creates a new Stream Object
|
||||
func NewStream(URL string) Stream {
|
||||
base64 := URLToBase64(URL)
|
||||
streamDirPath := filepath.Join(".", "streams", base64)
|
||||
return Stream{
|
||||
URL: URL,
|
||||
base64: base64,
|
||||
streamDirPath: streamDirPath,
|
||||
URL: URL,
|
||||
Base64: base64,
|
||||
Interval: 5000,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,24 +70,25 @@ func (s Stream) SwapInstants(previous string, current string, next string) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetStreamDirPath returns filepath.Join(".", "streams")
|
||||
func (s Stream) GetStreamDirPath() string {
|
||||
return filepath.Join(".", "streams")
|
||||
// GetStreamJSONPath returns filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||
func (s Stream) GetStreamJSONPath() string {
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||
}
|
||||
|
||||
// StreamStorePathExists returns FileExists(GetStreamDirPath())
|
||||
func (s Stream) StreamStorePathExists() bool {
|
||||
return FileExists(s.GetStreamDirPath())
|
||||
// WriteStreamJSON writes the Stream struct to GetStreamJSONPath()
|
||||
func (s Stream) WriteStreamJSON() {
|
||||
file, _ := json.MarshalIndent(s, "", "")
|
||||
_ = ioutil.WriteFile(s.GetStreamJSONPath(), file, 0644)
|
||||
}
|
||||
|
||||
// GetStreamStoreDirPath returns filepath.Join(s.GetStreamDirPath(), s.base64)
|
||||
// GetStreamStoreDirPath returns filepath.Join(s.GetStreamDirPath(), s.Base64)
|
||||
func (s Stream) GetStreamStoreDirPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64)
|
||||
return filepath.Join(GetStreamDirPath(), s.Base64)
|
||||
}
|
||||
|
||||
// GetPreviousInstantPath returns filepath.Join(GetStreamDirPath(), s.base64, "previous.jpg")
|
||||
// GetPreviousInstantPath returns filepath.Join(GetStreamDirPath(), s.Base64, "previous.jpg")
|
||||
func (s Stream) GetPreviousInstantPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64, "previous.jpg")
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "previous.jpg")
|
||||
}
|
||||
|
||||
// PreviousInstantPathExists returns FileExists(GetPreviousInstantPath())
|
||||
|
@ -100,9 +101,9 @@ func (s Stream) IMReadPrevious() gocv.Mat {
|
|||
return gocv.IMRead(s.GetPreviousInstantPath(), gocv.IMReadGrayScale)
|
||||
}
|
||||
|
||||
// GetCurrentInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg")
|
||||
// GetCurrentInstantPath returns filepath.Join(s.GetStreamDirPath(), s.Base64, "current.jpg")
|
||||
func (s Stream) GetCurrentInstantPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64, "current.jpg")
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "current.jpg")
|
||||
}
|
||||
|
||||
// CurrentInstantPathExists returns FileExists(GetCurrentInstantPath())
|
||||
|
@ -115,9 +116,9 @@ func (s Stream) IMReadCurrent() gocv.Mat {
|
|||
return gocv.IMRead(s.GetCurrentInstantPath(), gocv.IMReadGrayScale)
|
||||
}
|
||||
|
||||
// GetNextInstantPath returns filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg")
|
||||
// GetNextInstantPath returns filepath.Join(s.GetStreamDirPath(), s.Base64, "last.jpg")
|
||||
func (s Stream) GetNextInstantPath() string {
|
||||
return filepath.Join(s.GetStreamDirPath(), s.base64, "last.jpg")
|
||||
return filepath.Join(s.GetStreamStoreDirPath(), "last.jpg")
|
||||
}
|
||||
|
||||
// NextInstantPathExists returns FileExists(GetNextInstantPath())
|
||||
|
|
17
util.go
17
util.go
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// URLToBase64 returns the base64 encoding of the URL parameter
|
||||
|
@ -13,8 +14,24 @@ func URLToBase64(URL string) string {
|
|||
return base64.URLEncoding.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// Base64ToURL returns the string decoded base64 value
|
||||
func Base64ToURL(value string) string {
|
||||
decoded, _ := base64.URLEncoding.DecodeString(value)
|
||||
return string(decoded)
|
||||
}
|
||||
|
||||
// FileExists returns true if path exists
|
||||
func FileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
// GetStreamDirPath returns filepath.Join(".", "streams")
|
||||
func GetStreamDirPath() string {
|
||||
return filepath.Join(".", "streams")
|
||||
}
|
||||
|
||||
// StreamStorePathExists returns FileExists(GetStreamDirPath())
|
||||
func StreamStorePathExists() bool {
|
||||
return FileExists(GetStreamDirPath())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue