mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 18:22:37 +02:00
check videojs extension
This commit is contained in:
parent
545282b439
commit
41c303c110
43
internal/piwigo/active_plugin.go
Normal file
43
internal/piwigo/active_plugin.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package piwigo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ActivePlugin map[string]bool
|
||||||
|
|
||||||
|
func (uft *ActivePlugin) UnmarshalJSON(data []byte) error {
|
||||||
|
var r []struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
State string `json:"state"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*uft = ActivePlugin{}
|
||||||
|
for _, plugin := range r {
|
||||||
|
if plugin.State == "active" {
|
||||||
|
(*uft)[plugin.Id] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uft ActivePlugin) MarshalJSON() ([]byte, error) {
|
||||||
|
keys := make([]string, 0, len(uft))
|
||||||
|
for k := range uft {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return json.Marshal(keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uft ActivePlugin) String() string {
|
||||||
|
keys := make([]string, 0, len(uft))
|
||||||
|
for k := range uft {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return strings.Join(keys, ",")
|
||||||
|
}
|
@ -1,44 +1,17 @@
|
|||||||
package piwigo
|
package piwigo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UploadFileType map[string]bool
|
|
||||||
|
|
||||||
type StatusResponse struct {
|
type StatusResponse struct {
|
||||||
User string `json:"username"`
|
User string `json:"username"`
|
||||||
Role string `json:"status"`
|
Role string `json:"status"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Token string `json:"pwg_token"`
|
Token string `json:"pwg_token"`
|
||||||
UploadFileType UploadFileType `json:"upload_file_types"`
|
UploadFileType UploadFileType `json:"upload_file_types"`
|
||||||
}
|
Plugins ActivePlugin `json:"plugins"`
|
||||||
|
|
||||||
func (uft *UploadFileType) UnmarshalJSON(data []byte) error {
|
|
||||||
var r string
|
|
||||||
if err := json.Unmarshal(data, &r); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*uft = UploadFileType{}
|
|
||||||
for _, v := range strings.Split(r, ",") {
|
|
||||||
(*uft)[v] = true
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (uft UploadFileType) MarshalJSON() ([]byte, error) {
|
|
||||||
return []byte(`"` + uft.String() + `"`), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (uft UploadFileType) String() string {
|
|
||||||
keys := make([]string, 0, len(uft))
|
|
||||||
for k, _ := range uft {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
return strings.Join(keys, ",")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Piwigo) GetStatus() (*StatusResponse, error) {
|
func (p *Piwigo) GetStatus() (*StatusResponse, error) {
|
||||||
@ -52,6 +25,12 @@ func (p *Piwigo) GetStatus() (*StatusResponse, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = p.Post("pwg.plugins.getList", nil, &resp.Plugins)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if resp.User == p.Username {
|
if resp.User == p.Username {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
36
internal/piwigo/upload_file_type.go
Normal file
36
internal/piwigo/upload_file_type.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package piwigo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UploadFileType map[string]bool
|
||||||
|
|
||||||
|
func (uft *UploadFileType) UnmarshalJSON(data []byte) error {
|
||||||
|
var r string
|
||||||
|
if err := json.Unmarshal(data, &r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*uft = UploadFileType{}
|
||||||
|
for _, v := range strings.Split(r, ",") {
|
||||||
|
(*uft)[v] = true
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uft UploadFileType) MarshalJSON() ([]byte, error) {
|
||||||
|
keys := make([]string, 0, len(uft))
|
||||||
|
for k := range uft {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return json.Marshal(keys)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uft UploadFileType) String() string {
|
||||||
|
keys := make([]string, 0, len(uft))
|
||||||
|
for k := range uft {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
return strings.Join(keys, ",")
|
||||||
|
}
|
@ -2,6 +2,7 @@ package piwigocli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -34,11 +35,14 @@ func (c *ImagesUploadCommand) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ext {
|
if _, ok := status.Plugins["piwigo-videojs"]; ok {
|
||||||
case "ogg", "ogv", "mp4", "m4v", "webm", "webmv":
|
switch ext {
|
||||||
err = p.VideoJSSync(resp.ImageId)
|
case "ogg", "ogv", "mp4", "m4v", "webm", "webmv":
|
||||||
if err != nil {
|
fmt.Println("syncing metadata with videojs")
|
||||||
return err
|
err = p.VideoJSSync(resp.ImageId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user