-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_podcast.sh
executable file
·58 lines (50 loc) · 1.71 KB
/
get_podcast.sh
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
cd $(dirname $0)
download_log="./download.log"
if [ $# -lt 4 ]; then
echo "USAGE: $(basename $0) target_dir speed fixed_name audio_url podcast_name episode_name artwork_url pubdate episode"
exit 1
fi
target_dir="$1"
speed="$2"
rawdir="$3"
url="$4"
# rawdir="$5" # ignore podcast name from feed, it's inconsistent
rawname="$6"
artwork_url="$7"
rawdate="$8"
episode="$9"
echo "RAWDATE: $rawdate"
album=$(echo "$rawdir" | tr "-" " " | tr -d "[:punct:]")
song=$(echo "$rawname" | tr "-" " " | tr -d "[:punct:]")
dir=$(echo "$album" | tr " " "_")
pubdate=$(echo "$rawdate" | tr "-" " " | tr -d "[:punct:]" | tr " " "_")
name=$(echo "$song" | tr " " "_")
local_path="$dir/$name.mp3"
# local_path="${dir}_${pubdate}.mp3"
# check if file was downloaded already
grep $local_path $download_log >/dev/null
if [[ ${?} -eq 1 || ${?} -eq 2 ]]; then
target_path="$target_dir/$local_path"
# if [ ! -f "$target_path" ]; then
echo "Downloading the following podcast to $target_path"
echo $url
echo $dir
echo $name
echo $pubdate
echo $episode
mkdir -p "$(dirname "$target_path")"
wget "$url" -O "$target_path"
id3v2 --album "$album" --song "$song" "$target_path"
if [[ "$episode" != "" ]]; then
id3v2 --track "$episode" "$target_path"
fi
echo "${local_path}" >> "${download_log}"
# If desired speed is different than 1, change the speed
if [[ $(echo "$speed==1" | bc) -ne 1 ]]; then
mv $target_dir/$local_path "$target_dir/$dir/tmp.mp3"
ffmpeg -y -i "$target_dir/$dir/tmp.mp3" -filter:a "atempo=$speed" -vn $target_dir/$local_path
rm "$target_dir/$dir/tmp.mp3"
fi
# curl -qL $artwork_url > "$target_dir/$dir/artwork.jpg" # assumes jpg
fi