✨ Add drop:yt command and refine ytdlp.Drop functionality
This commit is contained in:
parent
ee70f2b96f
commit
b0f6628817
3 changed files with 98 additions and 16 deletions
69
cli/ytdrop.go
Normal file
69
cli/ytdrop.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/ytdlp"
|
||||
|
||||
mycli "codeberg.org/danjones000/my-log/cli"
|
||||
"codeberg.org/danjones000/my-log/config"
|
||||
"codeberg.org/danjones000/my-log/formatters"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var outJson bool
|
||||
|
||||
// YtDropCmd represents the drop command
|
||||
var YtDropCmd = &cobra.Command{
|
||||
Use: "drop:yt url",
|
||||
Short: "Add a new YouTube video 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 := ytdlp.Drop(cmd.Context(), url)
|
||||
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() {
|
||||
mycli.RootCmd.AddCommand(YtDropCmd)
|
||||
YtDropCmd.Flags().BoolVarP(&outJson, "output_json", "o", false, "Output result as JSON")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue