wip: xbox game bar support
This commit is contained in:
parent
9ee5507d1f
commit
9cf3092030
|
@ -4,3 +4,4 @@ build
|
|||
dist/
|
||||
.DS_Store
|
||||
Output*
|
||||
Input*
|
||||
|
|
8
go.mod
8
go.mod
|
@ -1,9 +1,15 @@
|
|||
module github.com/fmartingr/games-screenshot-manager
|
||||
|
||||
go 1.15
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/barasher/go-exiftool v1.7.0
|
||||
github.com/gosimple/slug v1.12.0
|
||||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gosimple/unidecode v1.0.1 // indirect
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
)
|
||||
|
|
10
go.sum
10
go.sum
|
@ -1,3 +1,6 @@
|
|||
github.com/barasher/go-exiftool v1.7.0 h1:EOGb5D6TpWXmqsnEjJ0ai6+tIW2gZFwIoS9O/33Nixs=
|
||||
github.com/barasher/go-exiftool v1.7.0/go.mod h1:F9s/a3uHSM8YniVfwF+sbQUtP8Gmh9nyzigNF+8vsWo=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gosimple/slug v1.12.0 h1:xzuhj7G7cGtd34NXnW/yF0l+AGNfWqwgh/IXgFy7dnc=
|
||||
|
@ -10,7 +13,10 @@ github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK
|
|||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/playstation4"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/retroarch"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/steam"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/providers/xbox_game_bar"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/registry"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -32,6 +33,7 @@ func Start() {
|
|||
registry := registry.NewProviderRegistry(logger, cache)
|
||||
registry.Register(minecraft.Name, minecraft.NewMinecraftProvider)
|
||||
registry.Register(playstation4.Name, playstation4.NewPlaystation4Provider)
|
||||
registry.Register(xbox_game_bar.Name, xbox_game_bar.NewXboxGameGarProvider)
|
||||
registry.Register(steam.Name, steam.NewSteamProvider)
|
||||
registry.Register(retroarch.Name, retroarch.NewRetroArchProvider)
|
||||
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package xbox_game_bar
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
exiftool "github.com/barasher/go-exiftool"
|
||||
"github.com/rwcarlsen/goexif/exif"
|
||||
)
|
||||
|
||||
func getExifTagsWithOld(path string) error {
|
||||
fileDescriptor, errFileDescriptor := os.Open(path)
|
||||
if errFileDescriptor != nil {
|
||||
return fmt.Errorf("Couldn't open file %s: %s", path, errFileDescriptor)
|
||||
}
|
||||
|
||||
exifData, errExifData := exif.Decode(fileDescriptor)
|
||||
if errExifData != nil {
|
||||
return fmt.Errorf("Decoding EXIF data from %s: %s", path, errExifData)
|
||||
}
|
||||
|
||||
defer fileDescriptor.Close()
|
||||
|
||||
t, _ := exifData.MarshalJSON()
|
||||
log.Println(t)
|
||||
|
||||
titleTag := "Title"
|
||||
if strings.Contains(path, ".png") {
|
||||
titleTag = "Microsoft Game DVR Title"
|
||||
}
|
||||
title, err := exifData.Get(exif.FieldName(titleTag))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting tag %s from %s: %s", titleTag, path, errExifData)
|
||||
}
|
||||
|
||||
log.Println(title)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getExifTags(path string) error {
|
||||
et, err := exiftool.NewExiftool()
|
||||
if err != nil {
|
||||
fmt.Printf("Error when intializing: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
defer et.Close()
|
||||
|
||||
fileInfos := et.ExtractMetadata(path)
|
||||
|
||||
for _, fileInfo := range fileInfos {
|
||||
if fileInfo.Err != nil {
|
||||
fmt.Printf("Error concerning %v: %v\n", fileInfo.File, fileInfo.Err)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println(fileInfo.GetString("MicrosoftGameDVRTitle"))
|
||||
log.Println(fileInfo.GetString("Title"))
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package xbox_game_bar
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/fmartingr/games-screenshot-manager/internal/models"
|
||||
"github.com/fmartingr/games-screenshot-manager/pkg/helpers"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const Name = "xbox-game-bar"
|
||||
const platformName = "Xbox Game Bar"
|
||||
|
||||
type XboxGameBarProvider struct {
|
||||
logger *logrus.Entry
|
||||
}
|
||||
|
||||
func (p *XboxGameBarProvider) FindGames(options models.ProviderOptions) ([]*models.Game, error) {
|
||||
var userGames []*models.Game
|
||||
|
||||
path := helpers.ExpandUser(options.InputPath)
|
||||
log.Print(path)
|
||||
files, err := ioutil.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading from path %s: %s", options.InputPath, err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
fullPath := filepath.Join(path, file.Name())
|
||||
log.Println(fullPath)
|
||||
|
||||
if strings.Contains(file.Name(), ".png") || strings.Contains(file.Name(), ".mp4") {
|
||||
if err := getExifTags(fullPath); err != nil {
|
||||
p.logger.Errorf("err: %s", err)
|
||||
}
|
||||
|
||||
// game.Screenshots = append(game.Screenshots, models.NewScreenshotWithoutDestination(path+"/"+file.Name()))
|
||||
}
|
||||
}
|
||||
|
||||
return userGames, nil
|
||||
}
|
||||
|
||||
func NewXboxGameGarProvider(logger *logrus.Logger, cache models.Cache) models.Provider {
|
||||
return &XboxGameBarProvider{
|
||||
logger: logger.WithField("from", "provider."+Name),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue