-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi4_lpl.sh
executable file
·151 lines (129 loc) · 3.29 KB
/
pi4_lpl.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
. ./settings
echo -n "Cleaning up local directory... "
rm -f *.lpl
echo "done."
echo -n "Cleaning up remote directory on Pi4... "
ssh $PI4_USER@$PI4_IP "rm -rf playlists/*.lpl roms/downloads" > /dev/null
echo "done."
CONSOLELIST=$(ssh $PI4_USER@$PI4_IP "ls -1 $PI4_ROMPATH/" | tr -d $'\r' | sed -e 's/\/$//')
_mame ()
{
MAMEGAME=$(basename $1 .zip)
FULLNAME=$($MAMEBIN -listfull "$MAMEGAME" | grep -v Description | cut -d '"' -f 2 | tr '/' '_' | sed 's/\ \~\ /\)\(/')
if [[ ! -z "$FULLNAME" ]]; then
echo -n .
else
echo "Game $1 was skipped!"
SKIP=1
fi
}
_fbneo ()
{
FULLNAME=$(grep -B4 name\ $1 $FBNEODB | grep name\ \" | cut -d '"' -f 2)
if [[ ! -z "$FULLNAME" ]]; then
echo -n .
else
_mame "$1"
fi
}
_getname ()
{
case $3 in
fbneo|neogeo|cps[123])
_fbneo "$1"
;;
mame*)
_mame "$1"
;;
*)
if $(echo "$1" | grep -q "$2"); then
GAME=$(echo "$1" | tr '_' ' ' | tr -d '[!]')
if $(echo "$GAME" | grep -q \.zip); then
FULLNAME=$(basename "$GAME" "$2.zip")
else
FULLNAME=$(basename "$GAME" "$2")
fi
else
echo "$1" has an unrecognized extension, skipping
SKIP=1
fi
;;
esac
}
_init_lpl ()
{
echo -e "{\n \"version\": \"1.2\",\n \"default_core_path\": \"$2\",\n \"default_core_name\": \"$3\",\n \"items\": [" > "$1"
}
_add_game_to_json ()
{
echo -e " {\n \"path\": \"$1\",\n \"label\": \"$2\",\n \"core_path\": \"$3\",\n \"core_name\": \"$4\",\n \"crc32\": \"$5|crc\",\n \"db_name\": \"$6\"\n }," >> "$6"
}
_close_lpl ()
{
echo -e " ]\n}" >> "$1"
}
for CONSOLE in $CONSOLELIST
do
echo Generating playlist for : $CONSOLE
GAMELIST=$(ssh $PI4_USER@$PI4_IP "ls -1 $PI4_ROMPATH/$CONSOLE/ | tr ' ' '_' | tr -d $'\r'")
FULLNAME=""
case $CONSOLE in
fbneo|neogeo|cps[123])
EXTENSION=".zip"
PLAYLIST="FBNeo - Arcade Games.lpl"
LIBRETRO="/usr/lib/libretro/fbneo_libretro.so"
LIBNAME="FBNeo"
;;
mame2010)
EXTENSION=".zip"
PLAYLIST="MAME.lpl"
LIBRETRO="/usr/lib/libretro/mame2010_libretro.so"
LIBNAME="MAME"
;;
naomi)
EXTENSION=".lst"
PLAYLIST="Sega - NAOMI.lpl"
LIBRETRO="/usr/lib/libretro/flycast_libretro.so"
LIBNAME="Flycast"
;;
neocd)
EXTENSION=".cue"
PLAYLIST="SNK - Neo Geo CD.lpl"
LIBRETRO="/usr/lib/libretro/fbneo_libretro.so"
LIBNAME="FBNeo"
;;
dc)
EXTENSION=".cdi"
PLAYLIST="Sega - Dreamcast.lpl"
LIBRETRO="/usr/lib/libretro/flycast_libretro.so"
LIBNAME="Flycast"
;;
*)
PLAYLIST=""
echo "Hardware $CONSOLE is not supported."
;;
esac
_init_lpl "$PLAYLIST" "$LIBRETRO" "$LIBNAME"
for GAMENAME in $GAMELIST
do
SKIP=0
_getname "$GAMENAME" "$EXTENSION" "$CONSOLE"
if [[ ! -z "$PLAYLIST" ]]
then
if [[ $SKIP -eq 0 ]]
then
FULLPATH=$(echo $PI4_ROMPATH/$CONSOLE/$GAMENAME | tr '_' ' ')
CRC32="00000000"
_add_game_to_json "$FULLPATH" "$FULLNAME" "$LIBRETRO" "$LIBNAME" "$CRC32" "$PLAYLIST"
echo -n .
fi
fi
done
_close_lpl "$PLAYLIST"
echo
done
echo -n "Uploading playlists to Pi4... "
scp *.lpl $PI4_USER@$PI4_IP:playlists/ > /dev/null
echo "done"
exit 0