-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnido_oplmanager
87 lines (77 loc) · 2.65 KB
/
nido_oplmanager
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
#!/usr/bin/env bash
#------------------------------------------------------------------
# Author: nido
# More: < https://github.com/NIDObr >
# Version: 0.1.8-beta 07/03/2021
# Tested on:
# GNU bash, versão 5.0.17(1)-release (x86_64-pc-linux-gnu)
# Info: OPL MANAGER for linux
# License: BSD-3-Clause License
#------------------------------------------------------------------
#----------------------------Vars----------------------------------
[ -e "$1" ] && {
opl_path="$1" # OPL Path
} || {
opl_path='/ps2opl' # OPL Path
}
tmp_list="/tmp/${RANDOM}.opl" # TMP file
#----------------------------Functions-----------------------------
game_manager(){
# Check if the name is already formatted
if $(echo "$1" | egrep -q "([A-Z]{4}\_[0-9]{3}\.[0-9]{2}\.([A-Z|a-z|0-9| |\-]|[\(\)\.\!\'\,]){1,}\.[a-z|A-Z]{3})");then
printf '%s\n' "$1"
return
else
local id=$(cat "$1" | egrep -a -o -m 1 "([A-Z]{4}\_[0-9]{3}\.[0-9]{2})") # Extract the game ID
# Check if you have a valid ID.
[ -z "$id" ] && {
printf '%s\n' "$1 - Does not have a valid id."
return 1
}
fi
# Vars
local ps1_db="database/ps1_database"
local ps2_db="database/ps2_database"
local disc="$3"
local cont='1'
local pre='0'
# Search by id
if [ ${disc} == "/POPS/" ];then
name=$(grep $id $ps1_db)
else
name=$(grep $id $ps2_db)
fi
# If the game is not in the database, just add the ID.
if [ -z "${name}" ];then
printf '%s\n' "Jogo não encontrado no banco de dados: "
new_name="${id}.$(echo "${1}" | awk -F "${disc}" '{print $2}' | awk -F "." '{print $1}')"
else
new_name="${name}"
fi
if [ "${disc}" = "/POPS/" ];then # Change the extension.
local format="VCD"
mkdir "${2}${disc}${new_name}/"
else
local format="iso"
fi
printf '%s\n' "After: `basename "${1}"`"
printf '%s\n' "Before: ${new_name}.${format}"
printf '%s\n\n' "ID: ${id}"
mv "${1}" "${2}${disc}${new_name}.${format}" # Rename the game.
}
#----------------------------Header--------------------------------
> "${tmp_list}"
for disc_type in "/DVD/" "/CD/" "/POPS/";do # Check the directories for games
if [ ${disc_type} == "/POPS/" ];then # If it is PS1 run:
for pops in $(ls "${opl_path}${disc_type}"*.VCD 2>/dev/null | sed -r 's/ /+_/g');do
old_name=$(printf '%s\n' "${pops}" | sed -r 's/\+\_/ /g') # Old name
game_manager "$old_name" "${opl_path}" "${disc_type}" "${arts_path}" # Call main function
done
else
for dvd in $(ls "${opl_path}${disc_type}"*.iso 2>/dev/null | sed -r 's/ /+_/g');do # If it is PS2 run:
old_name=$(printf '%s\n' "${dvd}" | sed -r 's/\+\_/ /g') # Old name
game_manager "$old_name" "${opl_path}" "${disc_type}" "${arts_path}" # Call main function
done
fi
done
rm "${tmp_list}"