✨ Add drop:tmdb command for adding shows/movies to watched log
This commit is contained in:
parent
21d27f8068
commit
88802020fe
10 changed files with 377 additions and 3 deletions
69
cli/tmdb.go
Normal file
69
cli/tmdb.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
Copyright © 2026 Dan Jones <danjones@goodevilgenius.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"my-log-wynter/tmdb"
|
||||
|
||||
mycli "codeberg.org/danjones000/my-log/cli"
|
||||
"codeberg.org/danjones000/my-log/config"
|
||||
"codeberg.org/danjones000/my-log/formatters"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// TmdbDropCmd represents the drop command
|
||||
var TmdbDropCmd = &cobra.Command{
|
||||
Use: "drop:tmdb url",
|
||||
Short: "Add a new show/movie from TMDB to the watched log",
|
||||
// Long: ``,
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if outJson {
|
||||
config.Overrides["output.stdout.config.format"] = "json"
|
||||
}
|
||||
|
||||
url := args[0]
|
||||
log, err := tmdb.Drop(cmd.Context(), url, d.Time())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
form, err := formatters.Preferred()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := form.Log(log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(out) > 0 && out[len(out)-1] != 10 {
|
||||
out = append(out, 10)
|
||||
}
|
||||
fmt.Fprintf(cmd.OutOrStdout(), "%s", out)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
(&d).Set("now")
|
||||
mycli.RootCmd.AddCommand(TmdbDropCmd)
|
||||
TmdbDropCmd.Flags().VarP(&d, "date", "d", "Date for log entry")
|
||||
TmdbDropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue