#!/bin/bash # # Script extracts patern from name of downloaded file # Use this script or just add pattern -o "%(title)s.%(ext)s" # to your 'youtube-dl' command url="$1" [ -z "$url" ] && echo "URL needed, exiting" && exit downloader="$(type -P youtube-dl)" 2>/dev/null [ "$?" != 0 ] && echo "Youtube-dl not found, exiting" && exit string="${url#*=}" echo "Downloading file, please wait" "$downloader" -v --audio-quality 0 --audio-format mp3 -x "$url" &>/dev/null [ "$?" != 0 ] && echo "Downloading not succesfull, exiting" && exit 1 file="$(ls | grep $string)" newfile="${file%-*}".mp3 if [ -f "$file" ]; then mv "$file" "$newfile" else echo "Warning! File was downladed but I can't locate it" echo "Please rename file manually" && exit 10 fi [ -f "$newfile" ] && echo "File '$newfile' was succesfully created" && exit 0