Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default - allow slideshow to play directories, update dependencies #200

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
54 changes: 49 additions & 5 deletions cmd/slideshow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,81 @@ 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() {
filename := path

if strings.HasSuffix(strings.ToLower(path), "jpg") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind updating this to be a list of all supported filetypes if we're going to filter like this: https://github.com/vishen/go-chromecast/blob/master/application/application.go#L714-L722?

If you wanted, feel free to add a flag to filter only specific image types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to use the list of file extensions in the other file.

Thanks,

Walter

s.files = append(s.files, filename)
} else {
log.Warn().Msgf("excluding %s as it is not a jpeg", filename)
}
}

return nil
}

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