From 9e94049968f282a2a82292ca822392af2292974d Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Fri, 10 Apr 2020 16:38:44 +0200 Subject: [PATCH] Add scripts to download youtube videos --- dotfiles/qutebrowser.org | 71 ++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/dotfiles/qutebrowser.org b/dotfiles/qutebrowser.org index 88cfbb6..c7d7ebf 100644 --- a/dotfiles/qutebrowser.org +++ b/dotfiles/qutebrowser.org @@ -268,10 +268,10 @@ Open Youtube video using =mpv= config.bind(',M', 'hint links spawn --detach mpv --force-window yes {hint-url}') #+END_SRC -Cast Youtube to Chromecast +Download Youtube video / entire playlist #+begin_src python - config.bind(',c', 'spawn --userscript ~/.config/qutebrowser/userscripts/cast.sh {url}') - config.bind(',C', 'hint links spawn --userscript ~/.config/qutebrowser/userscripts/cast.sh {hint-url}') + config.bind(',v', 'spawn --userscript ~/.config/qutebrowser/userscripts/yt-download.sh {url}') + config.bind(',V', 'hint links spawn --userscript ~/.config/qutebrowser/userscripts/yt-download.sh {hint-url}') #+END_SRC Add page to Bookmarks using =buku= @@ -293,7 +293,7 @@ Org Capture Download a torrent #+begin_src python - config.bind(',t', 'hint links spawn --userscript torrent-add {hint-url}') + config.bind(',t', 'hint links spawn torrent-add {hint-url}') #+end_src Annotate with Hypothesis @@ -307,14 +307,14 @@ See Amazon price history using CamelCamelCamel #+end_src * Userscripts -** Create a new password :PROPERTIES: -:header-args: :tangle ~/.config/qutebrowser/userscripts/add-passowrd.sh -:header-args+: :comments both :mkdirp yes -:header-args+: :shebang "#!/usr/bin/env bash" +:header-args:bash: :shebang "#!/usr/bin/env bash" +:header-args:bash+: :comments both :mkdirp yes :END: -#+begin_src bash +** Create a new password + +#+begin_src bash :tangle ~/.config/qutebrowser/userscripts/add-passowrd.sh url=$(echo "$QUTE_URL" | awk -F[/:] '{print $4}' | rofi -p "URL" -dmenu -lines 1) username=$(echo -e "dehaeze.thomas@gmail.com\nthomas.dehaeze@esrf.fr\ntdehaeze" | rofi -p "Username" -dmenu -lines 5) password=$(rofi -p "Password" -dmenu -password -lines 1) @@ -329,23 +329,31 @@ See Amazon price history using CamelCamelCamel fi #+end_src -** Cast Youtube to Chromecast -:PROPERTIES: -:header-args: :tangle ~/.config/qutebrowser/userscripts/cast.sh -:header-args+: :comments both :mkdirp yes -:header-args+: :shebang "#!/usr/bin/env bash" -:END: +** Download Youtube Video -#+begin_src bash - youtube-dl -o - $1 | castnow --quiet - +#+begin_src bash :tangle ~/.config/qutebrowser/userscripts/yt-download.sh + cd ~/Documents/to-watch/; + + if [[ "$1" == *"list"* ]]; then + choice=$(echo -e "Video\nPlaylist" | rofi -dmenu -only-match -i) + fi + + if [ -n "$choice" ] && [ "$choice" = "Playlist" ]; then + dunstify --replace=19243 "Youtube " "Downloading Playlist..."; + youtube-dl -i -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' "$1" -o "%(playlist_title)s/%(playlist_index)s-%(title)s.%(ext)s" && \ + dunstify --replace=19243 "Youtube " "Downloaded" || \ + dunstify --replace=19243 --urgency=critical "Youtube " "Failed to download" + else + dunstify --replace=19243 "Youtube " "Downloading Video..."; + youtube-dl --no-playlist -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' "$1" && \ + dunstify --replace=19243 "Youtube " "Downloaded" || \ + dunstify --replace=19243 --urgency=critical "Youtube " "Failed to download" + fi #+end_src ** Password_fill_rc -:PROPERTIES: -:header-args+: :tangle ~/.config/qutebrowser/password_fill_rc -:END: -#+begin_src bash +#+begin_src bash :tangle ~/.config/qutebrowser/password_fill_rc # Show all password fields in the menu query_entries() { # safe queried url for choose_entry @@ -368,13 +376,8 @@ See Amazon price history using CamelCamelCamel #+end_src ** Org-Capture -:PROPERTIES: -:header-args: :tangle ~/.config/qutebrowser/userscripts/org-capture.sh -:header-args+: :comments both :mkdirp yes -:header-args+: :shebang "#!/usr/bin/env bash" -:END: -#+begin_src bash +#+begin_src bash :tangle ~/.config/qutebrowser/userscripts/org-capture.sh readonly CAPTURE_SCRIPT=~/.config/qutebrowser/userscripts/org-protocol-capture-html.sh if [[ "$QUTE_MODE" = "hints" ]]; then @@ -519,13 +522,8 @@ Send to Emacs #+end_src ** Add Url to Buku using Rofi -:PROPERTIES: -:header-args: :tangle ~/.config/qutebrowser/userscripts/buku-rofi.sh -:header-args+: :comments both :mkdirp yes -:header-args+: :shebang "#!/usr/bin/env bash" -:END: -#+begin_src bash +#+begin_src bash :tangle ~/.config/qutebrowser/userscripts/buku-rofi.sh title=$(echo "$QUTE_TITLE" | rofi -p "Title" -dmenu -lines 1) tags=$(buku -t --nc --np | sed -e 's/\s*[[:digit:]]*\.\s*\(.*\)\s*([[:digit:]]*)\s*/\1/' -e '/^\s*$/d' | sort | uniq | rofi -p "Tags" -dmenu) @@ -533,12 +531,7 @@ Send to Emacs #+end_src ** Add Url to Buku without asking for information -:PROPERTIES: -:header-args: :tangle ~/.config/qutebrowser/userscripts/buku-add.sh -:header-args+: :comments both :mkdirp yes -:header-args+: :shebang "#!/usr/bin/env bash" -:END: -#+begin_src bash +#+begin_src bash :tangle ~/.config/qutebrowser/userscripts/buku-add.sh buku --add $QUTE_URL --title "$QUTE_TITLE" && dunstify "Buku" "📑 Bookmark Added" #+end_src