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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -12,19 +13,18 @@ import (
|
||||||
|
|
||||||
// Stream Unexported
|
// Stream Unexported
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
URL string
|
URL string `json:"url"`
|
||||||
base64 string
|
Base64 string `json:"base64"`
|
||||||
streamDirPath string
|
Interval int `json:"interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStream creates a new Stream Object
|
// NewStream creates a new Stream Object
|
||||||
func NewStream(URL string) Stream {
|
func NewStream(URL string) Stream {
|
||||||
base64 := URLToBase64(URL)
|
base64 := URLToBase64(URL)
|
||||||
streamDirPath := filepath.Join(".", "streams", base64)
|
|
||||||
return Stream{
|
return Stream{
|
||||||
URL: URL,
|
URL: URL,
|
||||||
base64: base64,
|
Base64: base64,
|
||||||
streamDirPath: streamDirPath,
|
Interval: 5000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,24 +70,25 @@ func (s Stream) SwapInstants(previous string, current string, next string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStreamDirPath returns filepath.Join(".", "streams")
|
// GetStreamJSONPath returns filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||||
func (s Stream) GetStreamDirPath() string {
|
func (s Stream) GetStreamJSONPath() string {
|
||||||
return filepath.Join(".", "streams")
|
return filepath.Join(s.GetStreamStoreDirPath(), "stream.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamStorePathExists returns FileExists(GetStreamDirPath())
|
// WriteStreamJSON writes the Stream struct to GetStreamJSONPath()
|
||||||
func (s Stream) StreamStorePathExists() bool {
|
func (s Stream) WriteStreamJSON() {
|
||||||
return FileExists(s.GetStreamDirPath())
|
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 {
|
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 {
|
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())
|
// PreviousInstantPathExists returns FileExists(GetPreviousInstantPath())
|
||||||
|
@ -100,9 +101,9 @@ func (s Stream) IMReadPrevious() gocv.Mat {
|
||||||
return gocv.IMRead(s.GetPreviousInstantPath(), gocv.IMReadGrayScale)
|
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 {
|
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())
|
// CurrentInstantPathExists returns FileExists(GetCurrentInstantPath())
|
||||||
|
@ -115,9 +116,9 @@ func (s Stream) IMReadCurrent() gocv.Mat {
|
||||||
return gocv.IMRead(s.GetCurrentInstantPath(), gocv.IMReadGrayScale)
|
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 {
|
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())
|
// NextInstantPathExists returns FileExists(GetNextInstantPath())
|
||||||
|
|
17
util.go
17
util.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// URLToBase64 returns the base64 encoding of the URL parameter
|
// 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))
|
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
|
// FileExists returns true if path exists
|
||||||
func FileExists(path string) bool {
|
func FileExists(path string) bool {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
return !os.IsNotExist(err)
|
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