1
0
Fork 0

Compare commits

..

No commits in common. "1627302081ab94edae639ead6d8e85c29c18b496" and "98d5674c0e63d6e3b97cff11761b75126ab21bc5" have entirely different histories.

3 changed files with 18 additions and 92 deletions

View file

@ -1,91 +1,15 @@
#!/usr/bin/env python3
"""Control Clementine from the command line using dbus."""
import argparse
import dbus # type: ignore
import dbus
CLEM_NAME = "org.mpris.MediaPlayer2.clementine"
CLEM_PATH = "/org/mpris/MediaPlayer2"
CLEM_PLAYER_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
PROPS_NAME = "org.mpris.MediaPlayer2.Player"
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}"
@ -94,6 +18,11 @@ def handle_position_command(_args):
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")

View file

@ -1,12 +1,13 @@
#!/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 jedi-language-server
ask_install pycodestyle
ask_install pylint
ask_install mypy
ask_install pyflakes
ask_install black python-lsp-black
ask_install mypy pylsp-mypy

View file

@ -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/bangs.json`, but you can specify the BANGS_CONFIG_PATH
`~/.config/rofibangs.json`, but you can specify the ROFIBANGS_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("BANGS_CONFIG_PATH") or os.path.expanduser(
"~/.config/bangs.json"
config_path = os.environ.get("ROFIBANGS_CONFIG_PATH") or os.path.expanduser(
"~/.config/rofibangs.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", nargs="+", help="launch with this bang already set")
ap.add_argument("-b", "--bang", help="launch with this bang already set")
args = ap.parse_args()
config = load_config()
@ -95,11 +95,7 @@ def main():
list_bangs(config)
return
if bang_args := args.bang:
handle = bang_args[0]
if bang_args[1:]:
query = " ".join(bang_args[1:])
else:
if handle := args.bang:
query = run_rofi(config, title=handle)
else:
process_input = "\n".join(i["handle"] for i in config["bangs"]) + "\n"