Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
update stuff to lavalink v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jan 29, 2022
1 parent 56abb79 commit cda37e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/DisgoOrg/spotify-plugin

go 1.17

require github.com/DisgoOrg/disgolink/lavalink v1.1.2
require github.com/DisgoOrg/disgolink/lavalink v1.2.0

require (
github.com/DisgoOrg/log v1.1.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/DisgoOrg/disgolink/lavalink v1.1.2 h1:/0L1UV5QXQyobDhTXPLQJPK4G6VNv5lnVoKAllC0ggY=
github.com/DisgoOrg/disgolink/lavalink v1.1.2/go.mod h1:oLXNVyw7Ab0sOItQSrW/Bk3/IrBwGHdlz5dE2PKxvEA=
github.com/DisgoOrg/disgolink/lavalink v1.2.0 h1:2bdEQlSApvnt39GoUXIpvsegjKEchAv/4GIxlE6q6eA=
github.com/DisgoOrg/disgolink/lavalink v1.2.0/go.mod h1:oLXNVyw7Ab0sOItQSrW/Bk3/IrBwGHdlz5dE2PKxvEA=
github.com/DisgoOrg/log v1.1.2 h1:tGJS4jaH1PyjPRHybHp8WpYJ/4fR3fYWT4Mv1PoDGBM=
github.com/DisgoOrg/log v1.1.2/go.mod h1:tSMofXaNhQNvzLRoL4tAiCG9yGY1ES5DLvduh7e9GRU=
github.com/DisgoOrg/snowflake v1.0.3 h1:KfzswrZOr8ISu/J5P3C5+QC9yKxW7nNJWeCJpkldxbI=
Expand Down
55 changes: 34 additions & 21 deletions spotify_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package spotify
import (
"errors"
"io"
"time"

"github.com/DisgoOrg/disgolink/lavalink"
)
Expand All @@ -29,13 +30,13 @@ func (p *Plugin) Encode(track lavalink.AudioTrack, w io.Writer) (err error) {
return errors.New("track is not a SpotifyAudioTrack")
}

if err = lavalink.WriteNullableString(w, spotifyTrack.AudioTrackInfo.ISRC); err != nil {
if err = lavalink.WriteNullableString(w, spotifyTrack.ISRC); err != nil {
return
}
return lavalink.WriteNullableString(w, spotifyTrack.AudioTrackInfo.ArtworkURL)
return lavalink.WriteNullableString(w, spotifyTrack.ArtworkURL)
}

func (p *Plugin) Decode(track string, info lavalink.AudioTrackInfo, r io.Reader) (spotifyTrack lavalink.AudioTrack, err error) {
func (p *Plugin) Decode(info lavalink.AudioTrackInfo, r io.Reader) (spotifyTrack lavalink.AudioTrack, err error) {
var isrc, artworkURL *string

if isrc, err = lavalink.ReadNullableString(r); err != nil {
Expand All @@ -46,35 +47,47 @@ func (p *Plugin) Decode(track string, info lavalink.AudioTrackInfo, r io.Reader)
}

return &AudioTrack{
AudioTrack: track,
AudioTrackInfo: &AudioTrackInfo{
AudioTrackInfo: info,
ISRC: isrc,
ArtworkURL: artworkURL,
},
AudioTrackInfo: info,
ISRC: isrc,
ArtworkURL: artworkURL,
}, nil
}

var (
_ lavalink.AudioTrack = (*AudioTrack)(nil)
_ lavalink.AudioTrackInfo = (*AudioTrackInfo)(nil)
_ lavalink.AudioTrack = (*AudioTrack)(nil)
)

type AudioTrack struct {
AudioTrack string `json:"track"`
AudioTrackInfo *AudioTrackInfo `json:"info"`
}

func (t *AudioTrack) Track() string {
return t.AudioTrack
AudioTrackInfo lavalink.AudioTrackInfo `json:"info"`
ISRC *string `json:"isrc"`
ArtworkURL *string `json:"artwork_url"`
}

func (t *AudioTrack) Info() lavalink.AudioTrackInfo {
return t.AudioTrackInfo
}

type AudioTrackInfo struct {
lavalink.AudioTrackInfo
ISRC *string `json:"isrc"`
ArtworkURL *string `json:"artwork_url"`
func (t *AudioTrack) SetPosition(position time.Duration) {
t.AudioTrackInfo.Position = position
}

func (t *AudioTrack) Clone() lavalink.AudioTrack {
info := t.AudioTrackInfo
info.Position = 0
var (
isrc, artworkURL *string
)
if t.ISRC != nil {
isrc = new(string)
*isrc = *t.ISRC
}
if t.ArtworkURL != nil {
artworkURL = new(string)
*artworkURL = *t.ArtworkURL
}
return &AudioTrack{
AudioTrackInfo: info,
ISRC: isrc,
ArtworkURL: artworkURL,
}
}

0 comments on commit cda37e4

Please sign in to comment.