Browse Source

Fix removing query args from tracks

Toni Fadjukoff 6 years ago
parent
commit
38b4290588
3 changed files with 23 additions and 6 deletions
  1. 10 2
      bot.go
  2. 12 3
      web.go
  3. 1 1
      web/index.html

+ 10 - 2
bot.go View File

247
 					j += i
247
 					j += i
248
 				}
248
 				}
249
 				trackId := line[i+len(SPOTIFY_MARK) : j]
249
 				trackId := line[i+len(SPOTIFY_MARK) : j]
250
-				tracks = append(tracks, spotify.ID(trackId))
250
+				tracks = append(tracks, spotify.ID(chopArgs(trackId)))
251
 			}
251
 			}
252
 		} else if strings.Index(line, SPOTIFY_PLAYLIST_MARK) != -1 && strings.Index(line, PLAYLIST_MARK) != -1 {
252
 		} else if strings.Index(line, SPOTIFY_PLAYLIST_MARK) != -1 && strings.Index(line, PLAYLIST_MARK) != -1 {
253
 			i := strings.Index(line, SPOTIFY_PLAYLIST_MARK)
253
 			i := strings.Index(line, SPOTIFY_PLAYLIST_MARK)
258
 			if q != -1 {
258
 			if q != -1 {
259
 				playlist = playlist[:q]
259
 				playlist = playlist[:q]
260
 			}
260
 			}
261
-			playlistId = spotify.ID(playlist)
261
+			playlistId = spotify.ID(chopArgs(playlist))
262
 		}
262
 		}
263
 	}
263
 	}
264
 	log.Printf("Found playlist %s and tracks %s\n", playlistId, tracks)
264
 	log.Printf("Found playlist %s and tracks %s\n", playlistId, tracks)
266
 	return spotify.ID(playlistId), tracks
266
 	return spotify.ID(playlistId), tracks
267
 }
267
 }
268
 
268
 
269
+func chopArgs(value string) string {
270
+	q := strings.Index(value, "?")
271
+	if q != -1 {
272
+		value = value[:q]
273
+	}
274
+	return value
275
+}
276
+
269
 func appendPlaylist(wikiText string, playlist *spotify.FullPlaylist) string {
277
 func appendPlaylist(wikiText string, playlist *spotify.FullPlaylist) string {
270
 	changedText := wikiText + `
278
 	changedText := wikiText + `
271
 	[` + playlist.ExternalURLs["spotify"] + ` Spotify-soittolista]
279
 	[` + playlist.ExternalURLs["spotify"] + ` Spotify-soittolista]

+ 12 - 3
web.go View File

20
 	}
20
 	}
21
 
21
 
22
 	data := struct {
22
 	data := struct {
23
-		Username string
24
-		Spotify  string
25
-		Songs    []*Song
23
+		Username      string
24
+		Spotify       string
25
+		SpotifyExpiry string
26
+		Songs         []*Song
26
 	}{
27
 	}{
28
+		"",
27
 		"",
29
 		"",
28
 		"",
30
 		"",
29
 		make([]*Song, 0),
31
 		make([]*Song, 0),
42
 		data.Spotify = session.spotify
44
 		data.Spotify = session.spotify
43
 	}
45
 	}
44
 
46
 
47
+	if s.spotify.client != nil {
48
+		token, err := s.spotify.client.Token()
49
+		if err == nil {
50
+			data.SpotifyExpiry = token.Expiry.Format(time.RFC822Z)
51
+		}
52
+	}
53
+
45
 	var templates = cachedTemplates
54
 	var templates = cachedTemplates
46
 	if s.noCache {
55
 	if s.noCache {
47
 		templates = template.Must(template.ParseFiles("web/index.html"))
56
 		templates = template.Must(template.ParseFiles("web/index.html"))

+ 1 - 1
web/index.html View File

34
     <div class="container">
34
     <div class="container">
35
         {{if .Username }}
35
         {{if .Username }}
36
         {{if .Spotify}}
36
         {{if .Spotify}}
37
-        <p>You are logged to Spotify as <strong>{{ .Spotify }}</strong></p>
37
+        <p>You are logged to Spotify as <strong>{{ .Spotify }}</strong> (Login expires {{ .SpotifyExpiry }})</p>
38
         {{else}}
38
         {{else}}
39
         <a href="/spotify"><button style="margin-bottom: 1em">Login with Spotify</button></a>
39
         <a href="/spotify"><button style="margin-bottom: 1em">Login with Spotify</button></a>
40
         {{end}}
40
         {{end}}