Initial commit
This commit is contained in:
commit
02a6dabcfb
62 files changed
+15751
No files matched your search
@@ -0,0 +1,264 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Clip represents a clip (short video)
|
||||
type Clip struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Duration int `json:"duration"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
PreviewURI string `json:"preview_uri"`
|
||||
Available bool `json:"available"`
|
||||
Views int `json:"views"`
|
||||
Likes int `json:"likes"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Artist *Artist `json:"artist"`
|
||||
Track *Track `json:"track"`
|
||||
Playlist *Playlist `json:"playlist"`
|
||||
ClipType string `json:"clip_type"`
|
||||
IsVertical bool `json:"is_vertical"`
|
||||
AspectRatio string `json:"aspect_ratio"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a Clip from JSON
|
||||
func (c *Clip) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clip := &Clip{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &clip.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &clip.Title)
|
||||
}
|
||||
if v, ok := raw["duration"]; ok {
|
||||
json.Unmarshal(v, &clip.Duration)
|
||||
}
|
||||
if v, ok := raw["cover_uri"]; ok {
|
||||
json.Unmarshal(v, &clip.CoverURI)
|
||||
}
|
||||
if v, ok := raw["preview_uri"]; ok {
|
||||
json.Unmarshal(v, &clip.PreviewURI)
|
||||
}
|
||||
if v, ok := raw["available"]; ok {
|
||||
json.Unmarshal(v, &clip.Available)
|
||||
}
|
||||
if v, ok := raw["views"]; ok {
|
||||
json.Unmarshal(v, &clip.Views)
|
||||
}
|
||||
if v, ok := raw["likes"]; ok {
|
||||
json.Unmarshal(v, &clip.Likes)
|
||||
}
|
||||
if v, ok := raw["created_at"]; ok {
|
||||
json.Unmarshal(v, &clip.CreatedAt)
|
||||
}
|
||||
if v, ok := raw["clip_type"]; ok {
|
||||
json.Unmarshal(v, &clip.ClipType)
|
||||
}
|
||||
if v, ok := raw["is_vertical"]; ok {
|
||||
json.Unmarshal(v, &clip.IsVertical)
|
||||
}
|
||||
if v, ok := raw["aspect_ratio"]; ok {
|
||||
json.Unmarshal(v, &clip.AspectRatio)
|
||||
}
|
||||
|
||||
if v, ok := raw["artist"]; ok {
|
||||
var artist Artist
|
||||
json.Unmarshal(v, &artist)
|
||||
clip.Artist = &artist
|
||||
}
|
||||
if v, ok := raw["track"]; ok {
|
||||
var track Track
|
||||
json.Unmarshal(v, &track)
|
||||
clip.Track = &track
|
||||
}
|
||||
if v, ok := raw["playlist"]; ok {
|
||||
var playlist Playlist
|
||||
json.Unmarshal(v, &playlist)
|
||||
clip.Playlist = &playlist
|
||||
}
|
||||
|
||||
return clip, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of Clips
|
||||
func (c *Clip) DeList(data []byte, client ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
clip := &Clip{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, clip); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, clip)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ClipsWillLike represents clips the user might like
|
||||
type ClipsWillLike struct {
|
||||
BaseModel
|
||||
Clips []Clip `json:"clips"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// ArtistClipData represents artist clip data
|
||||
type ArtistClipData struct {
|
||||
BaseModel
|
||||
Clips []Clip `json:"clips"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// ArtistClipItem represents an artist clip item
|
||||
type ArtistClipItem struct {
|
||||
BaseModel
|
||||
Clip *Clip `json:"clip"`
|
||||
Index int `json:"index"`
|
||||
}
|
||||
|
||||
// Shot represents a shot (short video)
|
||||
type Shot struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Duration int `json:"duration"`
|
||||
CoverURI string `json:"cover_uri"`
|
||||
PreviewURI string `json:"preview_uri"`
|
||||
Available bool `json:"available"`
|
||||
Views int `json:"views"`
|
||||
Likes int `json:"likes"`
|
||||
Comments int `json:"comments"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Author *User `json:"author"`
|
||||
Track *Track `json:"track"`
|
||||
ShotType string `json:"shot_type"`
|
||||
Tags []string `json:"tags"`
|
||||
IsVertical bool `json:"is_vertical"`
|
||||
AspectRatio string `json:"aspect_ratio"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes a Shot from JSON
|
||||
func (s *Shot) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shot := &Shot{BaseModel: *NewBaseModel(client)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &shot.ID)
|
||||
}
|
||||
if v, ok := raw["title"]; ok {
|
||||
json.Unmarshal(v, &shot.Title)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &shot.Description)
|
||||
}
|
||||
if v, ok := raw["duration"]; ok {
|
||||
json.Unmarshal(v, &shot.Duration)
|
||||
}
|
||||
if v, ok := raw["cover_uri"]; ok {
|
||||
json.Unmarshal(v, &shot.CoverURI)
|
||||
}
|
||||
if v, ok := raw["preview_uri"]; ok {
|
||||
json.Unmarshal(v, &shot.PreviewURI)
|
||||
}
|
||||
if v, ok := raw["available"]; ok {
|
||||
json.Unmarshal(v, &shot.Available)
|
||||
}
|
||||
if v, ok := raw["views"]; ok {
|
||||
json.Unmarshal(v, &shot.Views)
|
||||
}
|
||||
if v, ok := raw["likes"]; ok {
|
||||
json.Unmarshal(v, &shot.Likes)
|
||||
}
|
||||
if v, ok := raw["comments"]; ok {
|
||||
json.Unmarshal(v, &shot.Comments)
|
||||
}
|
||||
if v, ok := raw["created_at"]; ok {
|
||||
json.Unmarshal(v, &shot.CreatedAt)
|
||||
}
|
||||
if v, ok := raw["shot_type"]; ok {
|
||||
json.Unmarshal(v, &shot.ShotType)
|
||||
}
|
||||
if v, ok := raw["tags"]; ok {
|
||||
json.Unmarshal(v, &shot.Tags)
|
||||
}
|
||||
if v, ok := raw["is_vertical"]; ok {
|
||||
json.Unmarshal(v, &shot.IsVertical)
|
||||
}
|
||||
if v, ok := raw["aspect_ratio"]; ok {
|
||||
json.Unmarshal(v, &shot.AspectRatio)
|
||||
}
|
||||
|
||||
if v, ok := raw["author"]; ok {
|
||||
var user User
|
||||
json.Unmarshal(v, &user)
|
||||
shot.Author = &user
|
||||
}
|
||||
if v, ok := raw["track"]; ok {
|
||||
var track Track
|
||||
json.Unmarshal(v, &track)
|
||||
shot.Track = &track
|
||||
}
|
||||
|
||||
return shot, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of Shots
|
||||
func (s *Shot) DeList(data []byte, client ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
shot := &Shot{BaseModel: *NewBaseModel(client)}
|
||||
if err := json.Unmarshal(item, shot); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, shot)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ShotData represents shot data
|
||||
type ShotData struct {
|
||||
BaseModel
|
||||
Shots []Shot `json:"shots"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// ShotEvent represents a shot event
|
||||
type ShotEvent struct {
|
||||
BaseModel
|
||||
EventID string `json:"event_id"`
|
||||
EventType string `json:"event_type"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
ShotID string `json:"shot_id"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
// ShotType represents a shot type
|
||||
type ShotType struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
Reference in new issue
Block a user