-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_osx.go
73 lines (56 loc) · 1.63 KB
/
main_osx.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
// +build darwin
package NeteaseMusicPlaying
import (
"encoding/json"
"fmt"
"howett.net/plist"
"io/ioutil"
"log"
"os"
"strings"
"time"
)
type historyStruct struct {
Objects []string `plist:"$objects"`
}
var HistoryFilePath string
func init() {
HistoryFilePath = os.Getenv("HOME") +
"/Library/Containers/com.netease.163music/Data/Documents/storage/file_storage/webdata/file/history"
}
var Playing = &Song{}
func Update() {
f, err := os.Open(HistoryFilePath)
historyData, _ := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
defer f.Close()
var history historyStruct
_, err = plist.Unmarshal(historyData, &history)
if err != nil {
log.Fatalln(err)
}
var tracks []Song
_ = json.Unmarshal([]byte(history.Objects[1]), &tracks)
var artists []string
for _, a := range tracks[0].Track.Artists {
artists = append(artists, a.Name)
}
PlayingMutex.Lock()
Playing = &tracks[0]
PlayingMutex.Unlock()
duration, _ := time.ParseDuration(fmt.Sprint(Playing.Track.Duration/1000) + "s")
fmt.Println("song id:", Playing.Track.Id)
fmt.Println("song name:", Playing.Track.Name)
fmt.Println("song alias:", Playing.Track.Alias)
fmt.Println("song popularity:", Playing.Track.Popularity)
fmt.Println("song isPayed:", Playing.Track.Privilege.Payed)
fmt.Println("song duration:", duration)
fmt.Println("artists name:", strings.Join(artists, " / "))
fmt.Println("album name:", Playing.Track.Album.Name)
fmt.Println("album alias", Playing.Track.Album.Alias)
fmt.Println("album pic:", Playing.Track.Album.PicUrl)
fmt.Println("from:", Playing.Text)
fmt.Println("////////////////////////////////////////////////////////////////////////////")
}