forked from jprjr/internet-radio-streams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_links
executable file
·47 lines (37 loc) · 1.25 KB
/
make_links
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
#!/usr/bin/env bash
if [[ -z "$1" || -z "$2" ]]; then
echo "usage:"
echo " $0 folder format [iheartradio format]"
echo "Creates symlinks to playlists"
echo "Format can be 'm3u' or 'pls'"
echo "iheartradio format can be 'by-name' or 'by-calletters'"
echo "Defaults to 'by-name'"
exit 1
fi
cwd=$(pwd)
dest=$1
format=$2
iheartradio_format='by-name'
if [[ -n "$3" ]]; then
iheartradio_format=$3
fi
abspath_portable() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
abs_path=$(abspath_portable "$0")
script_dir=$(dirname "${abs_path}")
script_abs_path=$(readlink "${abs_path}" || echo "${abs_path}")
script_abs_dir=$(cd "$(dirname "${script_abs_path}")" && pwd -P)
script_name="${abs_path#$script_abs_dir/}"
script_abs_name="${script_abs_path#$script_abs_dir/}"
cd $dest
find "$script_abs_dir/$format"\
-type f\
-not -path '*/iheartradio/*'\
-exec sh -c \
'src="{}"; dest="${src#'"$script_abs_dir/$format/"'}"; leadfolder=$(dirname "$dest"); mkdir -p "$leadfolder"; ln -sfv "$src" "$dest" ' \;
find "$script_abs_dir/$format" \
-type f \
-path '*/iheartradio/'$iheartradio_format'/*' \
-exec sh -c \
'src="{}"; dest="${src#'"$script_abs_dir/$format/"'}"; leadfolder=$(dirname "$dest"); mkdir -p "$leadfolder"; ln -sfv "$src" "$dest" ' \;