~yerinalexey/dotfiles

ref: bb286f78d2f5c93f44c6faae8f20b19d96b5cb6d dotfiles/scripts/dl-music -rwxr-xr-x 582 bytes
bb286f78Alexey Yerin dl-music: "defer" the clean-up with trap 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh -e

# Download music from YouTube

MUSIC_DIRECTORY="$HOME"/music

video_url="$1"

if [ -z "$video_url" ]; then
	printf "Warning: defaulting video URL to \$(wl-paste)\n" >&2
	video_url="$(wl-paste)"
fi

video_title="$(youtube-dl --get-title "$video_url" | sed 's/\s*\[NCS Release\]\s*//g')"
dest="$MUSIC_DIRECTORY"/"$video_title"

orig="$(youtube-dl --get-filename -f bestaudio -o "$dest.%(ext)s" "$video_url")"
youtube-dl -f bestaudio -o "$dest.%(ext)s" "$video_url"

# defer rm "$orig"
trap 'rm "$orig"' EXIT

ffmpeg -v 16 -i "$orig" "$dest".opus

opus-edit "$dest".opus