From ae1458873e7dd2a7975d0bbc033825b21ae2eedf Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 9 Aug 2021 12:50:10 +0200 Subject: [PATCH] Packages: Add aria2 download utility To speed up YouTube downloads, use the external downloader aria2c. Also implemented it in the aliases and scripts where youtube-dl is used. --- .config/aria2/aria2.conf | 6 ++++++ .config/zsh/.zshrc | 6 +++--- .local/bin/aliases | 4 ++-- .local/bin/play | 22 +++++++++++++--------- packages | 1 + 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 .config/aria2/aria2.conf diff --git a/.config/aria2/aria2.conf b/.config/aria2/aria2.conf new file mode 100644 index 0000000..34c0cc5 --- /dev/null +++ b/.config/aria2/aria2.conf @@ -0,0 +1,6 @@ +continue +file-allocation=none +max-concurrent-downloads=3 +max-connection-per-server=3 +min-split-size=1M +split=3 diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index c95d2da..7ca2c6e 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -173,9 +173,9 @@ alias u="setsid -f urxvt -cd $PWD" alias weather="curl -s 'https://wttr.in/dordrecht?q&n&p' | head -n -3" alias webmconvert="aliases webmconvert" alias workbench="GDK_SCALE=1 GDK_DPI_SCALE=1 setsid -f -- mysql-workbench > /dev/null 2>&1" -alias ytv="youtube-dl -f bestvideo\[height\<=\?1080\]+bestaudio/best" -alias ytvb="youtube-dl -f bestvideo+bestaudio/best" -alias yta="youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0" # --embed-thumbnail" +alias ytv="youtube-dl -f bestvideo\[height\<=\?1080\]+bestaudio/best --external-downloader aria2c" +alias ytvb="youtube-dl -f bestvideo+bestaudio/best --external-downloader aria2c" +alias yta="youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0 --external-downloader aria2c" # --embed-thumbnail" alias ytat="aliases ytaudio_thumbnail" mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || exit; } diff --git a/.local/bin/aliases b/.local/bin/aliases index 88ef663..5816994 100755 --- a/.local/bin/aliases +++ b/.local/bin/aliases @@ -150,8 +150,8 @@ ytaudio_thumbnail() { # Get mp3 + thumbnail echo "Downloading and converting \"$FILE_NAME\".." youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0 \ - --write-thumbnail --cookies "~/documents/youtube.com_cookies.txt" "$1" > /dev/null - # --write-thumbnail "$1" > /dev/null + --write-thumbnail --external-downloader aria2c \ + --cookies "$HOME/documents/youtube.com-cookies.txt" "$1" > /dev/null echo "Embedding thumbnail into mp3.." diff --git a/.local/bin/play b/.local/bin/play index 4812f4a..632b14b 100755 --- a/.local/bin/play +++ b/.local/bin/play @@ -38,16 +38,17 @@ EOF CLIP="$(xclip -se c -o)" play() { + MPV="mpv --ytdl-raw-options=external-downloader=aria2c" if [ -z "$1" ]; then - MPV="mpv $CLIP" + MPV="$MPV $CLIP" # Cut off everything after space - LINK=" $(echo $CLIP | sed -nE 's/^(\S+).*/\1/p')" + LINK=" $(echo "$CLIP" | sed -nE 's/^(\S+).*/\1/p')" else - MPV="mpv $*" + MPV="$MPV $*" # Determain which argument holds the urls [ "$1" = "${1#-}" ] && DISPLAY="$1" || DISPLAY="$2" # Cut off everything after space - LINK=" $(echo $DISPLAY | sed -nE 's/^(\S+).*/\1/p')" + LINK=" $(echo "$DISPLAY" | sed -nE 's/^(\S+).*/\1/p')" fi notify-send -t 2500 "Loading video: $LINK" @@ -58,27 +59,30 @@ play() { shuffle() { # Skip first argument shift 1 - mpv --no-video --shuffle --ytdl-format='bestaudio[ext=m4a]' "${@:-$CLIP}" + mpv --no-video --shuffle \ + --ytdl-format='bestaudio[ext=m4a]' \ + --ytdl-raw-options='external-downloader=aria2c' \ + "${@:-$CLIP}" } queue() { - OPTIONS="--no-terminal --force-window --input-file=$PIPE" + OPTIONS="--no-terminal --force-window --input-file=$PIPE --ytdl-raw-options=external-downloader=aria2c" # Create mpv cache directory DIR="$(dirname "$PIPE")" [ ! -d "$DIR" ] && mkdir -p "$DIR" # Delete named pipe if no umpv is running - if ! pgrep -f 'mpv $OPTIONS' > /dev/null; then + if ! pgrep -f "mpv $OPTIONS" > /dev/null; then rm -f "$PIPE" fi # Skip first argument shift 1 # Set url to argument if provided, clipboard otherwise - URLS="${@:-$CLIP}" + URLS="${*:-$CLIP}" - if [ -p $PIPE ]; then + if [ -p "$PIPE" ]; then notify-send -t 2500 "Added video to queue.." # Add video to named pipe echo "$URLS" \ diff --git a/packages b/packages index 876d274..4a5364d 100644 --- a/packages +++ b/packages @@ -4,6 +4,7 @@ alsa-utils arandr arc-gtk-theme arc-icon-theme +aria2 aspell-en aspell-nl base