-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuji.sh
executable file
·89 lines (69 loc) · 1.93 KB
/
fuji.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
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
#!/bin/sh
# fuji
#
# Script to download a playlist segments from youtube and convert them into a
# single audio file. Implemented with the idea to be run via CRON once a day.
#
# youtube-dl and ffmpeg are required to be installed.
#
# The location of youtube-dl
YTDL=/opt/bin/youtube-dl
# Standard options for youtube-dl
OPTS="-q -i -A"
# Playlist options for youtube-dl
PLOPTS="--playlist-end 100"
# Audio options for youtube-dl
AOPTS="--extract-audio --audio-format mp3 --audio-quality 320k"
# The url of the playlist to download
URL="http://www.youtube.com/playlist?list=UUoQBJMzcwmXrRSHBFAlTsIw"
# The name to give the resulting file
FNAME=`date "+%y-%m-%d"`
# Regex for titles to download
REGEX='.*'`date "+\(%y\/%m\/%d\)"`'$'
# The audio file to place between each audio file from youtube.
# Should be placed in the work directory.
GAP=../gap.mp3
# Audio file to play when done.
# Should be placed in the work directory.
CHIME=../ATOS-3.mp3
# The working directory.
WORKDIR="$HOME/Documents/fuji"
# Check for the work directory and create it if necessary.
if [ ! -d $WORKDIR ]; then
mkdir $WORKDIR
fi
# The full path to the directory for today.
FULLPATH=$WORKDIR/$FNAME
# Check for today's directory and create it if necessary.
if [ ! -d $FULLPATH ]; then
mkdir $FULLPATH
fi
# Change to today's directory.
cd $FULLPATH
# Download and process youtube files.
$YTDL $OPTS $PLOPTS --match-title "$REGEX" $AOPTS $URL
# Build concat list.
CONCAT=""
for i in `ls -1ct`; do
if [ "$CONCAT" == "" ]; then
CONCAT=$CONCAT$i
elif [ -f $GAP ]; then
CONCAT=$CONCAT\|$GAP\|$i
else
CONCAT=$CONCAT\|$i
fi
done
# Build single audio file.
ffmpeg -loglevel panic -i concat:$CONCAT -acodec copy $FNAME.mp3
# Check for successful creation of audio file.
if [ -f $FNAME.mp3 ]; then
mv $FNAME.mp3 ../$FNAME.mp3
# Clean up.
cd ../
rm -rf ./$FNAME
# Play chime if file exists.
if [ -f $CHIME ]; then
# afplay is specific to OS X
afplay $CHIME
fi
fi