Fixed some small bugs that were still present

This commit is contained in:
2024-08-15 20:12:29 +02:00
parent 3438ae9e45
commit da2829dbe2
4 changed files with 24 additions and 16 deletions

View File

@@ -103,7 +103,7 @@ func GetRandomSongClassic() string {
//Check if file exists and open
openFile, err := os.Open(song.Path)
if err != nil || gameData.Path+"/"+song.FileName != song.Path {
if err != nil || gameData.Path+song.FileName != song.Path {
//File not found
db.RemoveBrokenSong(song)
log.Println("Song not found, song '" + song.SongName + "' deleted from game '" + gameData.GameName + "' FileName: " + song.FileName)
@@ -232,12 +232,21 @@ func getSongFromList(games []models.GameData) models.SongData {
var song models.SongData
for !songFound {
game := getRandomGame(games)
log.Println("game = ", game)
songs := db.FindSongsFromGame(game.Id)
log.Println("songs = ", songs)
if len(songs) == 0 {
continue
}
song = songs[rand.Intn(len(songs))]
log.Println("song = ", song)
//Check if file exists and open
openFile, err := os.Open(song.Path)
if err != nil || game.Path+"/"+song.FileName != song.Path {
log.Println("game.Path+song.FileName: ", game.Path+song.FileName)
log.Println("song.Path: ", song.Path)
log.Println("game.Path+song.FileName != song.Path: ", game.Path+song.FileName != song.Path)
if err != nil || game.Path+song.FileName != song.Path {
//File not found
db.RemoveBrokenSong(song)
log.Println("Song not found, song '" + song.SongName + "' deleted from game '" + game.GameName + "' FileName: " + song.FileName)

View File

@@ -22,7 +22,7 @@ func SyncGames() {
dir = "/Users/sebastian/Resilio Sync/Sorterat_test/"
}
fmt.Printf("dir: %s\n", dir)
foldersToSkip := []string{".sync"}
foldersToSkip := []string{".sync", "dist", "old"}
fmt.Println(foldersToSkip)
db.SetGameDeletionDate()
checkBrokenSongs()
@@ -127,9 +127,12 @@ func checkSongs(gameDir string, gameId int) {
path := gameDir + entry.Name()
fileName := entry.Name()
songName, _ := strings.CutSuffix(fileName, ".mp3")
println("path", path)
if db.CheckSong(path) {
println("db.CheckSong(path)", true)
db.UpdateSong(songName, fileName, path)
} else {
println("db.CheckSong(path)", false)
db.AddSong(models.SongData{GameId: gameId, SongName: songName, Path: path, FileName: fileName})
}
} else if isCoverImage(entry) {