Skip to content

Commit 8e09412

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 6d1ad82 + 7c40feb commit 8e09412

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

.github/workflows/wrapper-manager-image.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727

2828
- name: Mount image
2929
run: |
30+
sudo apt-get update
3031
sudo apt-get install -y qemu-utils
3132
sudo modprobe nbd max_part=8
3233
sudo qemu-nbd --connect=/dev/nbd0 wrapper-manager.qcow2

decrypt.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ func (d *Dispatcher) AddInstance(inst *WrapperInstance) {
4848
func (d *Dispatcher) RemoveInstance(id string) {
4949
d.mu.Lock()
5050
defer d.mu.Unlock()
51+
if len(d.Instances) == 0 {
52+
return
53+
}
5154
for i, inst := range d.Instances {
55+
if inst == nil {
56+
continue
57+
}
5258
if inst.id == id {
5359
d.Instances = append(d.Instances[:i], d.Instances[i+1:]...)
5460
break

lyrics.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ func GetHttpClient() *http.Client {
2121
return &http.Client{Transport: transport}
2222
}
2323

24+
type LyricResponse struct {
25+
Errors []interface{} `json:"errors"`
26+
Data []struct {
27+
Attributes struct {
28+
TtmlLocalizations string `json:"ttmlLocalizations"`
29+
} `json:"attributes"`
30+
} `json:"data"`
31+
}
32+
2433
func GetLyrics(adamID string, region string, language string, token string, musicToken string) (string, error) {
2534
req, err := http.NewRequest("GET", fmt.Sprintf("https://amp-api.music.apple.com/v1/catalog/%s/songs/%s/syllable-lyrics?l[lyrics]=%s&extend=ttmlLocalizations&l[script]=en-Latn", region, adamID, language), nil)
2635
if err != nil {
@@ -41,14 +50,20 @@ func GetLyrics(adamID string, region string, language string, token string, musi
4150
if err != nil {
4251
return "", err
4352
}
44-
var respJson map[string][]interface{}
45-
if err := json.Unmarshal(respBody, &respJson); err != nil {
53+
var result LyricResponse
54+
if err := json.Unmarshal(respBody, &result); err != nil {
4655
return "", err
4756
}
48-
if respJson["errors"] != nil {
49-
return "", errors.New(fmt.Sprintf("failed to get lyrics: %s", respJson["errors"]))
57+
if len(result.Errors) > 0 {
58+
return "", fmt.Errorf("failed to get lyrics: %v", result.Errors)
59+
}
60+
if len(result.Data) == 0 {
61+
return "", errors.New("no data found")
62+
}
63+
ttml := result.Data[0].Attributes.TtmlLocalizations
64+
if ttml == "" {
65+
return "", errors.New("no ttml found")
5066
}
51-
ttml := respJson["data"][0].(map[string]interface{})["attributes"].(map[string]interface{})["ttmlLocalizations"].(string)
5267
return ttml, nil
5368
}
5469

0 commit comments

Comments
 (0)