dotfiles/.config/fish/functions/ytmpv.fish

107 lines
3.1 KiB
Fish
Raw Normal View History

2022-02-28 08:13:49 +00:00
function ytmpv -d 'A script to help queue youtube videos on MPV'
2022-03-09 21:29:18 +00:00
set -l queue ~/.ytmpv_queue
2024-07-05 09:54:32 +00:00
set -l downloads ~/.ytmpv_downloads/
2022-03-09 21:29:18 +00:00
if command --query prime-run
set --function --export __NV_PRIME_RENDER_OFFLOAD 1
set --function --export __GLX_VENDOR_LIBRARY_NAME nvidia
end
2022-03-09 21:29:18 +00:00
if not test -f $queue
touch $queue
end
2024-07-05 09:54:32 +00:00
if not test -d $downloads
mkdir $downloads
end
2022-02-28 08:13:49 +00:00
while read -P 'url(s)/command (play)> ' -l video
switch $video
case cl clear
clear
case c copy
set -l video (fromcb)
2022-09-23 05:34:50 +00:00
string split ' ' $video >>$queue
2022-02-28 08:13:49 +00:00
case d destroy
2022-09-23 05:34:50 +00:00
rm -r $queue
2022-03-09 21:29:18 +00:00
break
2024-07-05 09:54:32 +00:00
case dd destroy-downloads
rm -r $downloads
break
2022-05-12 23:08:48 +00:00
case e edit
$EDITOR $queue
2022-02-28 08:13:49 +00:00
case f fg
tmux attach -t ytmpv
case h help
functions ytmpv
case l list
2022-03-09 21:29:18 +00:00
cat $queue
2022-09-23 05:34:50 +00:00
case q quit
return
2024-07-05 09:54:32 +00:00
case dl download
tmux attach -t ytmpv
tmux new-session -s ytmpv -- \
yt-dlp \
--format-sort 'height:1080' \
--batch-file $queue \
--path $downloads
break
case pd play-downloads
tmux attach -t ytmpv
tmux new-session -s ytmpv -- \
mpv \
--ytdl \
--save-position-on-quit \
$downloads
break
2022-02-28 08:13:49 +00:00
case p play
2022-03-09 21:29:18 +00:00
tmux attach -t ytmpv
2022-09-23 05:34:50 +00:00
tmux new-session -s ytmpv -- \
mpv \
--ytdl \
--save-position-on-quit \
--playlist=$queue
2022-03-09 21:29:18 +00:00
break
2022-09-23 05:34:50 +00:00
case pl play-login
read -P 'username> ' -l username
read -P 'password> ' -s -l password
tmux attach -t ytmpv
tmux new-session -s ytmpv -- \
mpv \
--ytdl \
--ytdl-raw-options=username=$username,password=$password \
--save-position-on-quit \
--playlist=$queue
break
case s stream
2022-03-09 21:29:18 +00:00
tmux attach -t ytmpv
2022-09-23 05:34:50 +00:00
tmux new-session -s ytmpv -- \
streamlink \
--player mpv \
(cat $queue) \
best
2022-02-28 08:13:49 +00:00
break
case dwl destroy-watch-later
rm -r ~/.local/state/mpv/watch_later/
break
2022-02-28 08:13:49 +00:00
case '*'
2022-03-09 21:29:18 +00:00
if test -z "$video"
tmux attach -t ytmpv
2022-09-23 05:34:50 +00:00
tmux new-session -s ytmpv -- \
mpv \
--ytdl \
--save-position-on-quit \
--playlist=$queue
2022-03-09 21:29:18 +00:00
break
end
2022-09-23 05:34:50 +00:00
string split ' ' $video >>$queue
2022-02-28 08:13:49 +00:00
end
end
ytmpv
end