dotfiles/.local/bin/tools/startmpv

20 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/zsh
if echo "$1" | grep -qE 'youtube.*list'; then
# this script uses https://github.com/maxime-aknin/youtube-playlist-video-ids to gather video ids
# please install this first and specify the path to this cloned repo below
js_playlist_index_loc="$HOME/src/youtube-playlist-video-ids"
# The above mentioned script needs Youtube API access, (see the repo for more info on that)
# I've saved my API key in my password manager, I reccomend you to do something similar.
2023-10-12 15:12:12 +02:00
API_key="$(pass show 'dev/Youtube Data API v3' | head -n1 )"
2021-06-12 18:27:40 +02:00
index="$(echo "$1" | perl -pe "s|&index=([0-9]+)|\1|")"
playlist_id="$( echo "$1" | perl -pe "s|^.*?(\?\|&)list=(.*?)|\2|; s|&index=[0-9]+||" )"
notify-send "startmpv" "Searching for all videos in playlist..."
curl "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=500&playlistId=$playlist_id&key=$API_key" |
2021-06-12 18:27:40 +02:00
jq '.items[].snippet.resourceId.videoId' |
sed 's/^/https:\/\/www.youtube.com\/watch?v=/' |
xargs mpv --ytdl-format='bestvideo[ext=mp4][width<=1920][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best' ||
notify-send "startmpv" "An error has occured with playlist $playlist_id"
else
mpv --ytdl-format='bestvideo[ext=mp4][width<=1920][height<=1080]+bestaudio[ext=m4a]/best[ext=mp4]/best' "$1"
fi