feat(lastfm): strip copyright text from albumInfo/artistInfo responses
Release-As: 0.16.3
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/andybalholm/cascadia"
|
"github.com/andybalholm/cascadia"
|
||||||
@@ -57,6 +59,10 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Artist{}, fmt.Errorf("make request: %w", err)
|
return Artist{}, fmt.Errorf("make request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Artist.Bio.Summary = cleanLicenceText(resp.Artist.Bio.Summary)
|
||||||
|
resp.Artist.Bio.Content = cleanLicenceText(resp.Artist.Bio.Content)
|
||||||
|
|
||||||
return resp.Artist, nil
|
return resp.Artist, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +83,9 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) {
|
|||||||
return Album{}, fmt.Errorf("make request: %w", err)
|
return Album{}, fmt.Errorf("make request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resp.Album.Wiki.Summary = cleanLicenceText(resp.Album.Wiki.Summary)
|
||||||
|
resp.Album.Wiki.Content = cleanLicenceText(resp.Album.Wiki.Content)
|
||||||
|
|
||||||
return resp.Album, nil
|
return resp.Album, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,3 +333,15 @@ func GetParamSignature(params url.Values, secret string) string {
|
|||||||
hash := md5.Sum([]byte(toHash))
|
hash := md5.Sum([]byte(toHash))
|
||||||
return hex.EncodeToString(hash[:])
|
return hex.EncodeToString(hash[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var doublePuncExpr = regexp.MustCompile(`\.\s+\.\s+`)
|
||||||
|
var licenceExpr = regexp.MustCompile(`(?i)user-contributed text.*`)
|
||||||
|
|
||||||
|
func cleanLicenceText(text string) string {
|
||||||
|
text = licenceExpr.ReplaceAllString(text, "")
|
||||||
|
text = doublePuncExpr.ReplaceAllString(text, ". ")
|
||||||
|
text = strings.ReplaceAll(text, " .", ".")
|
||||||
|
text = strings.Join(strings.Fields(text), " ")
|
||||||
|
text = strings.TrimSpace(text)
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user