summaryrefslogtreecommitdiff
path: root/scripts/fetchdnow.sh
blob: 990a2dc670dd85b7774b8ea032679a1e1d1e142c (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
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Copyright 2008 Nick White
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# See <http://www.gnu.org/licenses/> for a copy of the GNU General
# Public License.

function usage
{
	echo "Usage: dnow [-c codec] [-f outfile]"
	echo " codec may be ogg, flac or mp3"
}

# Get Dates #
year=$(date +%Y)
month=$(date +%m)
monthname=$(date +%B)
day=$(date +%d)
dayunpadded=$(date +%-e)

# Set Defaults #
title="Democracy Now!"
titleshort="Democracy_Now"
codec="ogg"
podcastdir=~/feeds

while [ "$1" != "" ]; do
	case $1 in
		-c | --codec ) 	shift
				codec=$1
				;;
		-f | --file ) 	shift
				outfile=$1
				;;
		-h | --help )	usage
				exit
				;;
		* )		usage
				exit
				;;
	esac
	shift
done

downfile=dn$year-$month$day-1.$codec

url=http://www.archive.org/download/dn$year-$month$day/$downfile

downdir=$podcastdir/$year-$month-$dayunpadded

# if the file already exists, exit
if [ -f "$downdir/$downfile" ]; then
	echo "download file already exists"
	exit 1
fi

echo "url is $url"

mkdir -p "$downdir"
wget --quiet --directory-prefix="$downdir" $url

# check that it's audio data, not a 404, & if necessary delete
if [ -f "$downdir/404.php" ]; then
	find "$downdir" -iname "404.php*" -type f -exec rm -f {} \;
	echo "404, sorry"
	exit 1
elif [ -z "$(file $downdir/$downfile|grep audio)" ]; then
	rm "$downdir/$downfile"
	echo "download wasn't audio"
	exit 1
fi

# tag the newly downloaded file
vorbiscomment -w "$downdir/$downfile" -t "ARTIST=$title" -t "TITLE=$day $monthname $year" -t "GENRE=News" -t "DATE=$year"

# create directories and links to integrate with GoldenPod's directory structure
catdir=$podcastdir/catalogue/$titleshort

mkdir -p "$catdir"

ln -s "$downdir/$downfile" "$podcastdir/catalogue/All/"
ln -s $downdir/$downfile "$catdir/"
ln -sf $downdir/$downfile "$catdir/latest.$codec"
ln -sfn $downdir "$podcastdir/latest"