diff --git a/cmd/video/insert.go b/cmd/video/insert.go index 95664eb..6ab1531 100644 --- a/cmd/video/insert.go +++ b/cmd/video/insert.go @@ -101,7 +101,6 @@ func init() { ) insertCmd.MarkFlagRequired("file") - insertCmd.MarkFlagRequired("title") insertCmd.MarkFlagRequired("categoryId") insertCmd.MarkFlagRequired("privacy") } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1f5da12..37ab903 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "os/exec" + "path/filepath" "runtime" "gopkg.in/yaml.v3" @@ -43,3 +44,9 @@ func RandomStage() string { state := base64.URLEncoding.EncodeToString(b) return state } + +func GetFileName(file string) string { + base := filepath.Base(file) + fileName := base[:len(base)-len(filepath.Ext(base))] + return fileName +} diff --git a/pkg/yutuber/video/video.go b/pkg/yutuber/video/video.go index 480c5a9..987aab3 100644 --- a/pkg/yutuber/video/video.go +++ b/pkg/yutuber/video/video.go @@ -149,6 +149,10 @@ func (v *video) Insert() { v.Tags = append(v.Tags, "yutu🐰") } + if v.Title == "" { + v.Title = utils.GetFileName(v.File) + } + video := &youtube.Video{ Snippet: &youtube.VideoSnippet{ Title: v.Title,