Browse Source

Fix comparison of tracks

Toni Fadjukoff 6 years ago
parent
commit
7b18122784
1 changed files with 14 additions and 2 deletions
  1. 14 2
      bot.go

+ 14 - 2
bot.go View File

10
 	"io"
10
 	"io"
11
 	"log"
11
 	"log"
12
 	"os"
12
 	"os"
13
-	"reflect"
14
 	"regexp"
13
 	"regexp"
15
 	"strconv"
14
 	"strconv"
16
 	"strings"
15
 	"strings"
281
 	return changedText
280
 	return changedText
282
 }
281
 }
283
 
282
 
283
+func tracksEqual(tracks1 []spotify.ID, tracks2 []string) bool {
284
+	if len(tracks1) != len(tracks2) {
285
+		return false
286
+	}
287
+	for i, track1 := range tracks1 {
288
+		track2 := tracks2[i]
289
+		if string(track1) != track2 {
290
+			return false
291
+		}
292
+	}
293
+	return true
294
+}
295
+
284
 func (app *App) AutomateSection(title string) error {
296
 func (app *App) AutomateSection(title string) error {
285
 	wiki := app.wikiClient()
297
 	wiki := app.wikiClient()
286
 
298
 
328
 						log.Println("Failed to find tracks from DB", err)
340
 						log.Println("Failed to find tracks from DB", err)
329
 					}
341
 					}
330
 					log.Println("Checking if playlist needs updating", currentTracks, tracks, err)
342
 					log.Println("Checking if playlist needs updating", currentTracks, tracks, err)
331
-					if len(tracks) > 0 && (err != nil || !reflect.DeepEqual(currentTracks, tracks)) {
343
+					if len(tracks) > 0 && (err != nil || !tracksEqual(tracks, currentTracks)) {
332
 
344
 
333
 						if playlistID == "" {
345
 						if playlistID == "" {
334
 							log.Println("Creating new playlist")
346
 							log.Println("Creating new playlist")