summaryrefslogtreecommitdiffstats
path: root/bin/yout2ogg
blob: b6ab9c984329d90cbc824c98b58408dd4e74c190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /bin/sh
set -euf
target_folder="./music"

uri=$1
id=$(echo "$uri" | sed -n 's@^https\?://www\.youtube\.com/watch?v=@@p' | sed 's/#.*$//')
script=$(readlink -f "$0")
basedir=$(dirname $script)

mkdir -p $target_folder

if ! echo "$id" | grep -q .; then
  echo "bad uri: $uri" >&2
  exit 23
fi

cd $target_folder

if file=$(ls | grep "[-]$id\\.ogg\$"); then
  echo "already done: $file in $target_folder" >&2
  exit
fi

youtube-dl -i -o "%(title)s-%(id)s.%(ext)s" --restrict-filenames -x "$uri" --add-metadata --exec "$basedir/ogg-maker {}"