From 6519fa67933b7f99ad6f70a9cd17d2346142c400 Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Mon, 28 Dec 2020 21:06:18 +0100 Subject: [PATCH] [Bin, Awesome] Add script to read YouTube videos in mpv New script to read YouTube videos in mpv, with possibility to choose the video resolution Also add shortcut in Awesome to invoke this script --- org/config/awesome.org | 3 ++- org/config/bin.org | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/org/config/awesome.org b/org/config/awesome.org index edb5086..eecbb48 100644 --- a/org/config/awesome.org +++ b/org/config/awesome.org @@ -924,7 +924,8 @@ Most of these keybindings are available at root-level of Awesome and will be dec | u | modkey, meta | shell | rofi-umount | volume unmounting helper | rofi | | w | modkey, control | shell | wacom-setup | set up my wacom tablet | rofi | | w | modkey, shift | shell | rofi-wifi-menu | connect to available wifi | rofi | -| y | modkey | shell | rofi-ytdl | download video from web | rofi | +| y | modkey | shell | ytplay | play web video in mpv | rofi | +| y | modkey, shift | shell | rofi-ytdl | download video from web | rofi | ** Awesome :PROPERTIES: diff --git a/org/config/bin.org b/org/config/bin.org index 17bc20d..785423a 100644 --- a/org/config/bin.org +++ b/org/config/bin.org @@ -1268,6 +1268,40 @@ A quick and useful script I often use is a ~curl~ request to [[http://v2.wttr.in end #+END_SRC +* ytplay +:PROPERTIES: +:HEADER-ARGS: :shebang "#!/usr/bin/env fish" :mkdirp yes :tangle ~/.local/bin/ytplay +:CUSTOM_ID: Weather-4ed00bb0 +:END: +~ytplay~ is a simple script I’ve written that allows me to play in mpv any YouTube video at the desired resolution. The script relies on ~dmenu~ (or ~rofi~ in dmenu-mode), ~youtube-dl~ and of course ~mpv~ itself. +#+BEGIN_SRC fish + set URL (rofi -dmenu -i -p "Video URL") + if test -n "$URL" + set FORMAT \ + (youtube-dl --list-formats "$URL" | \ + egrep "webm.*[0-9]+x[0-9]+" | \ + awk '{print $3 " " $1}' | \ + sort -gu | \ + rofi -dmenu -i -p "Resolution" | \ + string split " ") + set FCODE $FORMAT[2] + mpv --ytdl-format=$FCODE "$URL" + end +#+END_SRC + +I’ll even add a ~.desktop~ entry for this script: +#+BEGIN_SRC conf-desktop :tangle ~/.local/share/applications/ytplay.desktop :mkdirp yes + [Desktop Entry] + Type=Application + Version=1.0 + Name=ytplay (YouTube in mpv) + Comment=Play YouTube videos in mpv + Exec=/home/phundrak/.local/bin/ytplay + Path=/home/phundrak/.local/bin + Terminal=false + Categories=Media +#+END_SRC + * ytdl - a ~youtube-dl~ wrapper :PROPERTIES: :HEADER-ARGS: :shebang "#!/usr/bin/env fish" :mkdirp yes :tangle ~/.local/bin/ytdl