[WIP] music platform user data scraper
teal-fm atproto
at main 2.2 kB view raw
1package models 2 3import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 "time" 8 9 "github.com/lestrrat-go/jwx/v2/jwk" 10 cbg "github.com/whyrusleeping/cbor-gen" 11) 12 13type ATprotoAuthData struct { 14 State string `json:"state"` 15 DID string `json:"did"` 16 PDSUrl string `json:"pds_url"` 17 AuthServerIssuer string `json:"authserver_issuer"` 18 PARState string `json:"par_state"` 19 PKCEVerifier string `json:"pkce_verifier"` 20 DPoPAuthServerNonce string `json:"dpop_authserver_nonce"` 21 DPoPPrivateJWK jwk.Key `json:"dpop_private_jwk"` 22} 23 24type ATprotoAuthSession struct { 25 ID string `json:"id"` 26 DID string `json:"did"` 27 PDSUrl string `json:"pds_url"` 28 AuthServerIssuer string `json:"authserver_issuer"` 29 AccessToken string `json:"access_token"` 30 RefreshToken string `json:"refresh_token"` 31 DpopPdsNonce string `json:"dpop_pds_nonce"` 32 DpopAuthServerNonce string `json:"dpop_authserver_nonce"` 33 DpopPrivateJWK jwk.Key `json:"dpop_private_jwk"` 34 TokenExpiry time.Time `json:"expires_at"` 35} 36 37type TealFmFeedPlay struct { 38 Type string `json:"$type"` 39 Duration int `json:"duration"` 40 TrackName string `json:"trackName"` 41 PlayedTime string `json:"playedTime"` 42 ArtistMbIDs []string `json:"artistMbIds"` 43 ArtistNames []string `json:"artistNames"` 44 ReleaseMBID string `json:"releaseMbId"` 45 ReleaseName string `json:"releaseName"` 46 RecordingMBID string `json:"recordingMbId"` 47 SubmissionClientAgent string `json:"submissionClientAgent"` 48} 49 50func (tfmTrack TealFmFeedPlay) MarshalCBOR(w io.Writer) error { 51 // in case the pointer is nil 52 // if tfmTrack == nil { 53 // return fmt.Errorf("cannot marshal nil TealFmFeedPlay") 54 // } 55 fmt.Println("Marshalling", tfmTrack) 56 trackBytes, err := json.Marshal(tfmTrack) 57 if err != nil { 58 return fmt.Errorf("failed to marshal trackMap to bytes: %w", err) 59 } 60 61 cw := cbg.NewCborWriter(w) 62 if err := cbg.WriteByteArray(cw, trackBytes); err != nil { 63 return fmt.Errorf("failed to write bytes as CBOR: %w", err) 64 } 65 return nil 66}