Skip to content

Commit

Permalink
default - allow slideshow to play directories, update dependencies (#200
Browse files Browse the repository at this point in the history
)

* default - allow slideshow to play directories, update dependencies

* default - add image extension filtering

---------

Co-authored-by: Walter White <[email protected]>
  • Loading branch information
walterjwhite and Walter White authored Nov 29, 2024
1 parent 5b15f5d commit da6e6c1
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 87 deletions.
5 changes: 2 additions & 3 deletions cmd/skipad.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ var skipadCmd = &cobra.Command{
if err := app.Skipad(); err != nil {
exit("unable to skip current ad: %v\n", err)
}

},

}

func init() {
rootCmd.AddCommand(skipadCmd)
}
}
61 changes: 56 additions & 5 deletions cmd/slideshow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,88 @@ package cmd
import (
"os"

"io/fs"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"path/filepath"
"strings"
)

type share struct {
files []string
}

// slideshowCmd represents the slideshow command
var slideshowCmd = &cobra.Command{
Use: "slideshow file1 file2 ...",
Short: "Play a slideshow of photos",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
exit("requires files to play in slideshow")
exit("requires files (or directories) to play in slideshow")
}

s := &share{}

for _, arg := range args {
if fileInfo, err := os.Stat(arg); err != nil {
exit("unable to find %q: %v", arg, err)
log.Warn().Msgf("unable to find %q: %v", arg, err)
} else if fileInfo.Mode().IsDir() {
exit("%q is a directory", arg)
log.Debug().Msgf("%q is a directory", arg)

// recursively find files in directory
// TODO: this will consume large amounts of memory as it will hold references to each file (media item) to be served
filepath.WalkDir(arg, s.getFilesRecursively)
} else {
s.files = append(s.files, arg)
}
}
app, err := castApplication(cmd, args)

app, err := castApplication(cmd, s.files)
if err != nil {
exit("unable to get cast application: %v", err)
}

duration, _ := cmd.Flags().GetInt("duration")
repeat, _ := cmd.Flags().GetBool("repeat")
if err := app.Slideshow(args, duration, repeat); err != nil {
if err := app.Slideshow(s.files, duration, repeat); err != nil {
exit("unable to play slideshow on cast application: %v", err)
}
},
}

func (s *share) getFilesRecursively(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

fileInfo, err := os.Stat(path)
if err != nil {
log.Warn().Msgf("Error checking file: %v | %v", path, err)
return nil
}

if !fileInfo.Mode().IsDir() {
if isSupportedImageType(path) {
s.files = append(s.files, path)
} else {
log.Warn().Msgf("excluding %s as it is not a supported image type", path)
}
}

return nil
}

func isSupportedImageType(path string) bool {
switch ext := strings.ToLower(filepath.Ext(path)); ext {
case ".jpg", ".jpeg", ".gif", ".bmp", ".png", ".webp":
return true
default:
return false
}
}

func init() {
rootCmd.AddCommand(slideshowCmd)
slideshowCmd.Flags().Int("duration", 10, "duration of each image on screen")
Expand Down
59 changes: 32 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vishen/go-chromecast
go 1.23.2

require (
cloud.google.com/go/texttospeech v1.9.0
cloud.google.com/go/texttospeech v1.10.0
github.com/buger/jsonparser v1.1.1
github.com/gogo/protobuf v1.3.2
github.com/grandcat/zeroconf v1.0.0
Expand All @@ -14,23 +14,26 @@ require (
github.com/rogpeppe/go-internal v1.13.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
google.golang.org/api v0.204.0
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38
github.com/stretchr/testify v1.10.0
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
google.golang.org/api v0.209.0
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697
)

require github.com/seancfoley/ipaddress-go v1.7.0

require gopkg.in/ini.v1 v1.67.0
require (
github.com/rs/zerolog v1.33.0
gopkg.in/ini.v1 v1.67.0
)

require (
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.10.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
cloud.google.com/go/auth v0.11.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/longrunning v0.6.2 // indirect
cloud.google.com/go/longrunning v0.6.3 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand All @@ -39,9 +42,11 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/nsf/termbox-go v1.1.1 // indirect
Expand All @@ -51,22 +56,22 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.26.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.27.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/grpc v1.68.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit da6e6c1

Please sign in to comment.