position

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use: "position",
	Example: `
  waybar-lyric position 20s # Set the player position to 20 seconds
  waybar-lyric position --lyric 1 # Set the player position to first lyrics line
  waybar-lyric position -- -10s # Set player position 10 seconds before the end
  waybar-lyric position -- 20% # Set player position to 20% of total length
  `,
	Short: "Set player position",
	Args:  cobra.ExactArgs(1),

	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		conn, err := dbus.SessionBus()
		if err != nil {
			return fmt.Errorf("failed to create dbus connection: %w", err)
		}
		slog.Debug("Created dbus session bus")

		mp, err := player.Select(conn)
		if err != nil {
			return fmt.Errorf("failed to select player: %w", err)
		}
		slog.Debug("Selected player", "player", mp.GetName())

		length, err := mp.GetLength()
		if err != nil {
			return fmt.Errorf("failed to get song duration: %v", err)
		}

		input := args[0]

		if strings.HasSuffix(input, "%") {
			return setPercentPosition(mp, input, length)
		}

		if !lyricsLine {
			return setExactPosition(mp, input, length)
		}

		info, err := player.Parse(mp)
		if err != nil {
			return fmt.Errorf("failed to parse player informations: %w", err)
		}

		slog.Debug("Parsed player information",
			"title", info.Title,
			"artist", info.Artist,
		)

		lyrics, err := lyric.GetLyrics(cmd.Context(), info)
		if err != nil {
			return fmt.Errorf("failed to fetch lyrics: %w", err)
		}

		return setLyricPosition(mp, lyrics.Lines, input)
	},
}

Command is the position changer command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL