aboutsummaryrefslogtreecommitdiff
path: root/youtube-par-cmd
blob: 1c5e5c580d32058f89c191bb8a33435de11f1640 (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
#!/usr/bin/env bash

# called from youtube-audio-par-dl and youtube-par-dl with corresponding download command
# only works with jq (command line JSON processor)

cmd="$1"
playlistURL="$2"

playlistJSON=`youtube-dl "$playlistURL" --flat-playlist -J`
playlistTitle=`echo "$playlistJSON" | jq -r '.title'`
playlistInfo="$playlistTitle"

output="$(mkdir "$playlistTitle")"
status=$?
if [ $status -ne 0 ]; then
    playlistTitle=`echo "$playlistJSON" | jq -r '.id'`
    mkdir "$playlistTitle"
fi

cd "$playlistTitle"

urls=`echo "$playlistJSON" | jq -r '.entries[].url'`
echo "$urls" | awk '{print "https://www.youtube.com/watch?v=" $0}' | xargs -n 1 -P 10 "$cmd"

m3uFile="Playlist - $playlistTitle"".m3u8"
echo "#EXTM3U" > "$m3uFile"
echo "#PLAYLIST:$playlistInfo" >> "$m3uFile"
echo "$urls" | while read url; do
    find . -name "*$url*" -prune >> "$m3uFile"
done