diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 6d123cc..345e471 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -144,8 +144,6 @@ alias vc="$HOME/.scripts/volctl.sh" alias vp="$HOME/.scripts/vimplugin.sh" alias mpvshuffle="$HOME/.scripts/mpv.sh shuffle" - - # Other alias len="xclip -o | wc -m" alias length="rofi -dmenu -i -p 'String length' -lines 0 | tr -d '\n' | wc -m" @@ -156,7 +154,8 @@ alias weather="curl -s 'https://wttr.in/dordrecht?q&n&p' | head -n -3" alias webmconvert="$HOME/.scripts/alias.sh webmconvert" alias workbench="GDK_SCALE=1 GDK_DPI_SCALE=1 mysql-workbench > /dev/null 2>&1 & disown" alias ytdl="youtube-dl -f bestvideo+bestaudio" -alias ytaudio="youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0" +alias yta="youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0" # --embed-thumbnail" +alias ytat="$HOME/.scripts/alias.sh ytaudio_thumbnail" zsh="/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" [ -f "$zsh" ] && source "$zsh"; unset zsh diff --git a/.scripts/alias.sh b/.scripts/alias.sh index f913fb1..ff8bc78 100755 --- a/.scripts/alias.sh +++ b/.scripts/alias.sh @@ -105,4 +105,32 @@ webmconvert() { ffmpeg -threads 4 -i "$1" -c:v libvpx -qmin 0 -qmax 40 -crf 16 -b:v 4M "$AUDIO" "${1%.*}_convert.webm" } +ytaudio_thumbnail() { + # Get file name + echo "Retrieving video name.." + FILE_NAME="$(youtube-dl --get-filename "$1")" + FILE_NAME="${FILE_NAME%.*}" + + # Get mp3 + thumbnail + echo "Downloading and converting \"$FILE_NAME\".." + youtube-dl -f bestaudio/best -x --audio-format mp3 --audio-quality 0 \ + --write-thumbnail "$1" > /dev/null + + echo "Embedding thumbnail into mp3.." + + # Convert thumbnail to actually be a jpg + yes y | ffmpeg -i "${FILE_NAME}.jpg" "${FILE_NAME}_converted.jpg" > /dev/null 2>&1 + + # Embed thumbnail into mp3 + yes y | ffmpeg -i "${FILE_NAME}.mp3" -i "${FILE_NAME}_converted.jpg" \ + -map 0:0 -map 1:0 -c copy -id3v2_version 3 \ + -metadata:s:v title="Album cover" \ + -metadata:s:v comment="Cover (front)" \ + "${FILE_NAME}_embed.mp3" > /dev/null 2>&1 + + # Remove left over files + rm -f "./${FILE_NAME}_converted.jpg" "./${FILE_NAME}.jpg" "./${FILE_NAME}.mp3" + mv "${FILE_NAME}_embed.mp3" "${FILE_NAME}.mp3" +} + "$@"