Quellcode durchsuchen

Fix removing query args from tracks

Toni Fadjukoff vor 6 Jahren
Ursprung
Commit
38b4290588
3 geänderte Dateien mit 23 neuen und 6 gelöschten Zeilen
  1. 10 2
      bot.go
  2. 12 3
      web.go
  3. 1 1
      web/index.html

+ 10 - 2
bot.go Datei anzeigen

@@ -247,7 +247,7 @@ func findPlaylist(wikiText string) (spotify.ID, []spotify.ID) {
247 247
 					j += i
248 248
 				}
249 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 252
 		} else if strings.Index(line, SPOTIFY_PLAYLIST_MARK) != -1 && strings.Index(line, PLAYLIST_MARK) != -1 {
253 253
 			i := strings.Index(line, SPOTIFY_PLAYLIST_MARK)
@@ -258,7 +258,7 @@ func findPlaylist(wikiText string) (spotify.ID, []spotify.ID) {
258 258
 			if q != -1 {
259 259
 				playlist = playlist[:q]
260 260
 			}
261
-			playlistId = spotify.ID(playlist)
261
+			playlistId = spotify.ID(chopArgs(playlist))
262 262
 		}
263 263
 	}
264 264
 	log.Printf("Found playlist %s and tracks %s\n", playlistId, tracks)
@@ -266,6 +266,14 @@ func findPlaylist(wikiText string) (spotify.ID, []spotify.ID) {
266 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 277
 func appendPlaylist(wikiText string, playlist *spotify.FullPlaylist) string {
270 278
 	changedText := wikiText + `
271 279
 	[` + playlist.ExternalURLs["spotify"] + ` Spotify-soittolista]

+ 12 - 3
web.go Datei anzeigen

@@ -20,10 +20,12 @@ func (s *WebService) IndexHandler(w http.ResponseWriter, r *http.Request) {
20 20
 	}
21 21
 
22 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 31
 		make([]*Song, 0),
@@ -42,6 +44,13 @@ func (s *WebService) IndexHandler(w http.ResponseWriter, r *http.Request) {
42 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 54
 	var templates = cachedTemplates
46 55
 	if s.noCache {
47 56
 		templates = template.Must(template.ParseFiles("web/index.html"))

+ 1 - 1
web/index.html Datei anzeigen

@@ -34,7 +34,7 @@
34 34
     <div class="container">
35 35
         {{if .Username }}
36 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 38
         {{else}}
39 39
         <a href="/spotify"><button style="margin-bottom: 1em">Login with Spotify</button></a>
40 40
         {{end}}