-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
105 lines (81 loc) · 1.71 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (C) 2023 l4rzy
* MIT License
*/
package csn
import (
"encoding/json"
"errors"
"fmt"
"io"
)
func getInfo(id interface{}) (MusicInfo, error) {
var ret MusicInfoResp
surl := fmt.Sprintf(MusicInfoFmt, id)
// get data
resp, err := csnClient.Get(surl)
if err != nil {
return ret.MusicInfo, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = errors.New("responsed status code is not ok")
return ret.MusicInfo, err
}
// read to body
body, err := io.ReadAll(resp.Body)
if err != nil {
return ret.MusicInfo, err
}
// parse json
err = json.Unmarshal(body, &ret)
if err != nil {
return ret.MusicInfo, err
}
return ret.MusicInfo, nil
}
func (m MusicSearch) GetInfo() (MusicInfo, error) {
return getInfo(m.MusicID)
}
func (m MusicSearchNew) GetInfo() (MusicInfo, error) {
return getInfo(m.MusicID)
}
func (v VideoSearch) GetInfo() (MusicInfo, error) {
return MusicInfo{}, nil
}
func (a ArtistSearch) GetInfo() (MusicInfo, error) {
return MusicInfo{}, nil
}
func (a AlbumSearch) GetInfo() (MusicInfo, error) {
return MusicInfo{}, nil
}
func (m MusicSearch) GetLink() string {
return ""
}
func (m MusicSearchNew) GetLink() string {
return m.MusicLink
}
func (m VideoSearch) GetLink() string {
return m.VideoLink
}
func (m ArtistSearch) GetLink() string {
return Home + m.ArtistLink
}
func (m AlbumSearch) GetLink() string {
return Home + m.AlbumLink
}
func (m MusicSearch) GetID() interface{} {
return m.MusicID
}
func (m MusicSearchNew) GetID() interface{} {
return m.MusicID
}
func (m VideoSearch) GetID() interface{} {
return m.VideoID
}
func (m ArtistSearch) GetID() interface{} {
return m.ArtistID
}
func (m AlbumSearch) GetID() interface{} {
return m.AlbumID
}