fix(mpv-pip): Accept newline-separated targets
This commit is contained in:
@@ -5,20 +5,26 @@ MPV=/opt/homebrew/bin/mpv
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: $(basename "$0") <file|url> [file|url ...]" >&2
|
||||
echo " $(basename "$0") mpv://open?url=<url-encoded target>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGETS=()
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == mpv://* ]]; then
|
||||
arg=$(python3 -c '
|
||||
IFS=$'\n' read -d '' -r -a TARGETS < <(python3 -c '
|
||||
import sys, urllib.parse as u
|
||||
q = u.parse_qs(u.urlparse(sys.argv[1]).query)
|
||||
print(q["url"][0])
|
||||
' "$arg")
|
||||
fi
|
||||
TARGETS+=("$arg")
|
||||
done
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
for line in arg.splitlines():
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
if line.startswith("mpv://"):
|
||||
try:
|
||||
parsed = u.urlparse(line)
|
||||
line = u.parse_qs(parsed.query)["url"][0]
|
||||
except (KeyError, IndexError):
|
||||
pass
|
||||
print(line)
|
||||
' "$@") || true
|
||||
|
||||
[[ ${#TARGETS[@]} -eq 0 ]] && exit 1
|
||||
|
||||
"$MPV" --ontop --on-all-workspaces --volume=0 "${TARGETS[@]}" &
|
||||
|
||||
Reference in New Issue
Block a user