Compare commits
3 commits
98d5674c0e
...
1627302081
Author | SHA1 | Date | |
---|---|---|---|
1627302081 | |||
8c021c1e15 | |||
fa03eb5aad |
|
@ -21,7 +21,7 @@ Optionally, a bang object can contain a "raw" key with a boolean value: if
|
|||
true, arguments are passed without being URL-encoded.
|
||||
|
||||
By default this scripts attempts to load your config file from
|
||||
`~/.config/rofibangs.json`, but you can specify the ROFIBANGS_CONFIG_PATH
|
||||
`~/.config/bangs.json`, but you can specify the BANGS_CONFIG_PATH
|
||||
environment variable or pass the path through the -c command-line option.
|
||||
"""
|
||||
|
||||
|
@ -35,8 +35,8 @@ import webbrowser
|
|||
|
||||
def load_config(config_path=None):
|
||||
if config_path is None:
|
||||
config_path = os.environ.get("ROFIBANGS_CONFIG_PATH") or os.path.expanduser(
|
||||
"~/.config/rofibangs.json"
|
||||
config_path = os.environ.get("BANGS_CONFIG_PATH") or os.path.expanduser(
|
||||
"~/.config/bangs.json"
|
||||
)
|
||||
try:
|
||||
with open(config_path, "rt") as bangs_file:
|
||||
|
@ -84,7 +84,7 @@ def main():
|
|||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("-c", "--config", help="path to JSON config file")
|
||||
ap.add_argument("-l", "--list", action="store_true", help="show available bangs")
|
||||
ap.add_argument("-b", "--bang", help="launch with this bang already set")
|
||||
ap.add_argument("-b", "--bang", nargs="+", help="launch with this bang already set")
|
||||
args = ap.parse_args()
|
||||
|
||||
config = load_config()
|
||||
|
@ -95,7 +95,11 @@ def main():
|
|||
list_bangs(config)
|
||||
return
|
||||
|
||||
if handle := args.bang:
|
||||
if bang_args := args.bang:
|
||||
handle = bang_args[0]
|
||||
if bang_args[1:]:
|
||||
query = " ".join(bang_args[1:])
|
||||
else:
|
||||
query = run_rofi(config, title=handle)
|
||||
else:
|
||||
process_input = "\n".join(i["handle"] for i in config["bangs"]) + "\n"
|
85
clemctl.py
85
clemctl.py
|
@ -1,15 +1,91 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Control Clementine from the command line using dbus."""
|
||||
|
||||
import dbus
|
||||
import argparse
|
||||
|
||||
import dbus # type: ignore
|
||||
|
||||
CLEM_NAME = "org.mpris.MediaPlayer2.clementine"
|
||||
CLEM_PATH = "/org/mpris/MediaPlayer2"
|
||||
CLEM_PLAYER_NAME = "org.mpris.MediaPlayer2.Player"
|
||||
PROPS_NAME = "org.mpris.MediaPlayer2.Player"
|
||||
|
||||
# org.mpris.MediaPlayer2.Player.CanControl
|
||||
# org.mpris.MediaPlayer2.Player.CanGoNext
|
||||
# org.mpris.MediaPlayer2.Player.CanGoPrevious
|
||||
# org.mpris.MediaPlayer2.Player.CanPause
|
||||
# org.mpris.MediaPlayer2.Player.CanPlay
|
||||
# org.mpris.MediaPlayer2.Player.CanSeek
|
||||
# org.mpris.MediaPlayer2.Player.LoopStatus
|
||||
# org.mpris.MediaPlayer2.Player.MaximumRate
|
||||
# org.mpris.MediaPlayer2.Player.Metadata
|
||||
# org.mpris.MediaPlayer2.Player.MinimumRate
|
||||
# org.mpris.MediaPlayer2.Player.Next
|
||||
# org.mpris.MediaPlayer2.Player.OpenUri
|
||||
# org.mpris.MediaPlayer2.Player.Pause
|
||||
# org.mpris.MediaPlayer2.Player.Play
|
||||
# org.mpris.MediaPlayer2.Player.PlayPause
|
||||
# org.mpris.MediaPlayer2.Player.PlaybackStatus
|
||||
# org.mpris.MediaPlayer2.Player.Position
|
||||
# org.mpris.MediaPlayer2.Player.Previous
|
||||
# org.mpris.MediaPlayer2.Player.Rate
|
||||
# org.mpris.MediaPlayer2.Player.Seek
|
||||
# org.mpris.MediaPlayer2.Player.SetPosition
|
||||
# org.mpris.MediaPlayer2.Player.Shuffle
|
||||
# org.mpris.MediaPlayer2.Player.Stop
|
||||
# org.mpris.MediaPlayer2.Player.Volume
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
action_group = parser.add_mutually_exclusive_group()
|
||||
action_group.add_argument("--play", action="store_true")
|
||||
action_group.add_argument("--play-pause", action="store_true")
|
||||
action_group.add_argument("--pause", action="store_true")
|
||||
action_group.add_argument("--stop", action="store_true")
|
||||
action_group.add_argument("--previous", action="store_true")
|
||||
action_group.add_argument("--next", action="store_true")
|
||||
|
||||
subparsers = parser.add_subparsers()
|
||||
|
||||
pos_parser = subparsers.add_parser("position", help="get track position")
|
||||
pos_parser.add_argument("-f", "--format", help="position format")
|
||||
pos_parser.set_defaults(func=handle_position_command)
|
||||
|
||||
args = parser.parse_args()
|
||||
if hasattr(args, "func"):
|
||||
args.func(args)
|
||||
return
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
clem_object = get_clementine_object(bus)
|
||||
if args.play:
|
||||
get_player_interface(clem_object).Play()
|
||||
elif args.play_pause:
|
||||
get_player_interface(clem_object).PlayPause()
|
||||
elif args.pause:
|
||||
get_player_interface(clem_object).Pause()
|
||||
elif args.stop:
|
||||
get_player_interface(clem_object).Stop()
|
||||
elif args.previous:
|
||||
get_player_interface(clem_object).Previous()
|
||||
elif args.next:
|
||||
get_player_interface(clem_object).Next()
|
||||
else:
|
||||
parser.print_usage()
|
||||
|
||||
|
||||
def get_clementine_object(bus):
|
||||
clem_object = bus.get_object(CLEM_NAME, CLEM_PATH)
|
||||
return clem_object
|
||||
|
||||
|
||||
def get_player_interface(clem_object):
|
||||
interface = dbus.Interface(clem_object, dbus_interface=CLEM_PLAYER_NAME)
|
||||
return interface
|
||||
|
||||
|
||||
def handle_position_command(_args):
|
||||
bus = dbus.SessionBus()
|
||||
hour, minutes, seconds = get_position(bus)
|
||||
timestamp = f"{minutes:02}:{seconds:02}"
|
||||
|
@ -18,11 +94,6 @@ def main():
|
|||
print(timestamp)
|
||||
|
||||
|
||||
def get_clementine_object(bus):
|
||||
clem_object = bus.get_object(CLEM_NAME, CLEM_PATH)
|
||||
return clem_object
|
||||
|
||||
|
||||
def get_position(bus):
|
||||
clem_object = get_clementine_object(bus)
|
||||
position = clem_object.Get(CLEM_PLAYER_NAME, "Position")
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
pip3 install python-lsp-server
|
||||
|
||||
ask_install() {
|
||||
packages="$@"
|
||||
read -p "Install $packages? [y/n] " -n 1 -r ; echo
|
||||
[[ "$REPLY" = y ]] && pip3 install $packages
|
||||
}
|
||||
|
||||
ask_install pyflakes
|
||||
ask_install black python-lsp-black
|
||||
ask_install mypy pylsp-mypy
|
||||
ask_install jedi-language-server
|
||||
ask_install pycodestyle
|
||||
ask_install pylint
|
||||
ask_install mypy
|
Loading…
Reference in a new issue