Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ytdl-mpv): clipboard copy for multi-selection #45

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions bin/ytdl-mpv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _rofi_error() {
}
_copyId() {
if [ "$XCLIP" ]; then
printf '%s' "$1" | xclip -i -selection "clipboard"
printf '%s\n%s' "$1" "$(xclip -o -selection "clipboard")" | xclip -i -selection "clipboard"
_info "Copy in clipboard ... ${1:7}"
fi
}
Expand Down Expand Up @@ -92,6 +92,17 @@ _helpPlay() {
EOF
_rofi -theme-str "$STYLE" -mesg "-- play menu key bindings --" >/dev/null
}
_helpPlaySlim() {
local STYLE="window {width: 32%;} listview {lines: 6;}"
cat <<EOF |
\
[Enter] | Add in playlist
[${copy_id}] | Copy video id
[$(printf '%s' "${multi_select}" | sed 's/Tab/⇄/')] | Multi selection
[$(printf '%s' "${key_return}" | sed 's/Left/←/')] | Return
EOF
_rofi -theme-str "$STYLE" -mesg "-- play menu key bindings --" >/dev/null
}
_helpSearch() {
local STYLE="window {width: 30%;} listview {lines: 5;}"
cat <<EOF |
Expand Down Expand Up @@ -168,6 +179,7 @@ _checkDep() {
type "$dep" >/dev/null 2>&1 || {
if [ "$dep" == "xclip" ]; then
XCLIP=0
_info "Cannot find xclip in your \$PATH. Copy feats are disabled."
else
_die "Cannot find ${dep} in your \$PATH"
fi
Expand Down Expand Up @@ -585,7 +597,10 @@ _startPlay() {
# check if ytdl-mpv is already running, if yes append track to playlist
local args
local STYLE="window {width: ${WIDTH}%;} listview {lines: ${LINEN};}"
# decice which help menu to show
local help_slim
if [ "$(_ytdl_mpvctl check)" == "disabled" ]; then
help_slim=0
args=(-kb-custom-1 "${play_audio}"
-kb-custom-2 "${play_video}"
-kb-custom-3 "${copy_id}"
Expand All @@ -597,12 +612,15 @@ _startPlay() {
-no-custom
-mesg "-- play menu: start audio or video playback, help [Alt+h] --")
else
args=(-kb-custom-5 "${key_return}"
help_slim=1
args=(-kb-custom-3 "${copy_id}"
-kb-custom-4 "${key_help}"
-kb-custom-5 "${key_return}"
-kb-accept-alt "${multi_select}"
-theme-str "$STYLE"
-multi-select
-no-custom
-mesg "-- play menu: add track to current playlist, simply [Enter] --")
-mesg "-- play menu: add track to current playlist, help [Alt+h] --")
fi
# selected track
local strack
Expand All @@ -611,8 +629,30 @@ _startPlay() {
rofi_exit="$?"
# check if help requested
if [[ "${rofi_exit}" -eq 13 ]]; then
_helpPlay
if [ "$help_slim" ]; then
_helpPlaySlim
else
_helpPlay
fi
_startPlay
# check if copy requested
elif [[ "${rofi_exit}" -eq 12 ]]; then
if [ "$XCLIP" ]; then
local IFS
IFS=$'\n'
# flush clipboard
echo -n | xclip -i -selection "clipboard"
for strack in $stracks; do
strack="${strack:9}"
local id
id="ytdl://$(_getCachedIdQuery "$query" "$strack")"
_copyId "$id"
done
return
else
_info "xclip not installed. Copy feats are disabled."
_startPlay
fi
else
if [ -z "$stracks" ]; then
_info "Nothing selected"
Expand All @@ -634,10 +674,10 @@ _startPlay() {
0) "${default_do}" "$id" ;;
10) _playAudio "$id" ;;
11) _playVideo "$id" ;;
12)
_copyId "$id"
return
;;
# 12)
# _copyId "$id"
# return
# ;;
esac
sleep 1
else
Expand Down