Parcourir la source

Fix comparison of tracks

Toni Fadjukoff il y a 6 ans
Parent
révision
7b18122784
1 fichiers modifiés avec 14 ajouts et 2 suppressions
  1. 14 2
      bot.go

+ 14 - 2
bot.go Voir le fichier

@@ -10,7 +10,6 @@ import (
10 10
 	"io"
11 11
 	"log"
12 12
 	"os"
13
-	"reflect"
14 13
 	"regexp"
15 14
 	"strconv"
16 15
 	"strings"
@@ -281,6 +280,19 @@ func appendPlaylist(wikiText string, playlist *spotify.FullPlaylist) string {
281 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 296
 func (app *App) AutomateSection(title string) error {
285 297
 	wiki := app.wikiClient()
286 298
 
@@ -328,7 +340,7 @@ func (app *App) AutomateSection(title string) error {
328 340
 						log.Println("Failed to find tracks from DB", err)
329 341
 					}
330 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 345
 						if playlistID == "" {
334 346
 							log.Println("Creating new playlist")