-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiyou.sh
50 lines (40 loc) · 990 Bytes
/
audiyou.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
#!/bin/bash
# author: Akshay Suresh
# date : 12/08/2017
# title : extract and crop audio from youtube audio
help() {
echo "Usage $1 <url> <start-time> <end-time>"
echo "Example: "
echo "$1 https://www.youtube.com/watch?v=arMu4f8rnBk 00:00:05 00:04:30"
exit 1
}
if [ $# -ne 3 ]
then
help $0
fi
url=$1
st=$2
et=$3
# calculate duration
sthr=`echo $st | cut -d ":" -f1`
ethr=`echo $et | cut -d ":" -f1`
stmin=`echo $st | cut -d ":" -f2`
etmin=`echo $et | cut -d ":" -f2`
stsec=`echo $st | cut -d ":" -f3`
etsec=`echo $et | cut -d ":" -f3`
durhr=$((ethr-sthr))
durmin=$((etmin-stmin))
dursec=$((etsec-stsec))
dur=$durhr":"$durmin":"$dursec
# create directory
dirname=`date +"%s"`
echo "creating temporary directory $dirname"
mkdir $dirname
cd $dirname
# extract the audio
youtube-dl -x --audio-format "mp3" $url
# get the filename
filename=`ls | grep "mp3"`
# crop the audio
avconv -i "$filename" -ss $st -t $dur -codec copy "$filename""_cropped.mp3"
mv "$filename""_cropped.mp3"