tube

package
v0.0.0-...-41ce98d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2024 License: BSD-2-Clause Imports: 26 Imported by: 3

Documentation

Index

Constants

View Source
const (
	UnknownArtist = "Unknown Artist"
	UnknownAlbum  = "Unknown Album"
	UnknownTitle  = "Untitled"
)
View Source
const CurrentPhase = RegPhaseEarlyAccess

Variables

View Source
var ErrNotFound = dynamo.ErrNotFound
View Source
var MusicFolder = SSID{Kind: SSIDFolder, ID: "1"}
View Source
var TrialDuration = 14 * time.Hour * 24

Functions

func CountTracks

func CountTracks(ctx context.Context, userID int) (int64, error)

func CountTracks2

func CountTracks2(ctx context.Context, userID int) (int64, error)

func CreateTables

func CreateTables(ctx context.Context) error

func DeletePlaylist

func DeletePlaylist(ctx context.Context, userID int, id int) error

func DeleteStar

func DeleteStar(ctx context.Context, userID int, ssid string) error

func DeleteTrack

func DeleteTrack(ctx context.Context, userID int, trackID string) error

func GetALLTracks

func GetALLTracks(ctx context.Context) dynamo.Iter

func GetStars

func GetStars(ctx context.Context, userID int) (map[SSID]Star, error)

func HashPassword

func HashPassword(password string) ([]byte, error)

func IncTotalPlays

func IncTotalPlays(ctx context.Context, secs int) error

func Init

func Init(region, prefix, endpoint string, debug bool)

func MassUpdateTracks

func MassUpdateTracks(ctx context.Context, userID int, trackIDs []string, mutator func(*dynamo.Update)) error

func NextID

func NextID(ctx context.Context, class string) (n int, err error)

func RecreateDump

func RecreateDump(ctx context.Context, userID int, at time.Time) error

func RefreshDump

func RefreshDump(ctx context.Context, userID int, at time.Time, updates []Track, deletes []string) error

func SetStar

func SetStar(ctx context.Context, userID int, ssid SSID, date time.Time) error

Types

type DisplayOptions

type DisplayOptions struct {
	Stretch     bool
	MusicLink   MusicLinkOpt
	TrackSelect TrackSelOpt
}

type Dump

type Dump struct {
	UserID int
	Time   time.Time
	Tracks []Track
}

func (Dump) Key

func (d Dump) Key() string

func (*Dump) Remove

func (d *Dump) Remove(trackID string)

func (*Dump) Splice

func (d *Dump) Splice(tracks []Track)

type Event

type Event struct {
	UserID int
	Time   Timegarb
	Kind   EventKind
}

type EventKind

type EventKind string
const (
	EventPaid EventKind = "paid"
)

type File

type File struct {
	ID     string `dynamo:",hash" index:"UserID-ID-index,range"`
	UserID int    `index:"UserID-ID-index,hash"`

	Size     int64
	Type     string
	Name     string
	Ext      string
	Time     time.Time
	LocalMod int64
	Queued   time.Time
	Started  time.Time
	Finished time.Time
	Ready    bool
	Deleted  bool

	TrackID string
}

func GetFile

func GetFile(ctx context.Context, id string) (File, error)

func GetFiles

func GetFiles(ctx context.Context, ids ...string) ([]File, error)

func GetFilesByUser

func GetFilesByUser(ctx context.Context, userID string) ([]File, error)

func NewFile

func NewFile(userID int, filename string, size int64) File

func (File) Create

func (f File) Create(ctx context.Context) error

func (File) Delete

func (f File) Delete(ctx context.Context) error

dont use TODO delete

func (*File) Finish

func (f *File) Finish(ctx context.Context, contentType string, size int64) error

func (File) Glyph

func (f File) Glyph() string

func (File) Path

func (f File) Path() string

func (*File) SetQueued

func (f *File) SetQueued(ctx context.Context, at time.Time) error

func (*File) SetStarted

func (f *File) SetStarted(ctx context.Context, at time.Time) error

func (*File) SetTrackID

func (f *File) SetTrackID(tID string) error

func (File) Status

func (f File) Status() string

type MusicLinkOpt

type MusicLinkOpt string
const (
	MusicLinkDefault MusicLinkOpt = ""
	MusicLinkAlbums  MusicLinkOpt = "albums"
)

func (MusicLinkOpt) String

func (mlo MusicLinkOpt) String() string

type Picture

type Picture struct {
	ID   string
	Type string
	Ext  string
	Desc string
}

func (Picture) StorageKey

func (p Picture) StorageKey() string

type Plan

type Plan struct {
	Kind    PlanKind
	Quota   int64
	PriceID string
}

func GetPlan

func GetPlan(kind PlanKind) Plan

func GetPlans

func GetPlans() []Plan

type PlanKind

type PlanKind string
const (
	PlanKindNone  PlanKind = ""
	PlanKindTiny  PlanKind = "tiny"
	PlanKindSmall PlanKind = "small"
	PlanKindBig   PlanKind = "big"
	PlanKindHuge  PlanKind = "huge"
)

func (PlanKind) Msg

func (pk PlanKind) Msg() string

type PlanStatus

type PlanStatus string
const (
	PlanStatusActive            PlanStatus = "active"
	PlanStatusTrialing          PlanStatus = "trialing"
	PlanStatusIncomplete        PlanStatus = "incomplete"
	PlanStatusIncompleteExpired PlanStatus = "incomplete_expired"
	PlanStatusPastDue           PlanStatus = "past_due"
	PlanStatusCanceled          PlanStatus = "canceled"
	PlanStatusUnpaid            PlanStatus = "unpaid"
)

func (PlanStatus) Active

func (ps PlanStatus) Active() bool

type Playlist

type Playlist struct {
	UserID int `dynamo:",hash"`
	ID     int `dynamo:",range"`

	Date time.Time
	Name string
	Desc string

	Tracks   []string
	Duration int // seconds

	Dynamic bool
	Query   string
	Sort    []string
	UIMeta  []byte

	LastMod time.Time
}

func GetPlaylist

func GetPlaylist(ctx context.Context, userID int, id int) (Playlist, error)

func GetPlaylists

func GetPlaylists(ctx context.Context, userID int) ([]Playlist, error)

func (*Playlist) Create

func (p *Playlist) Create(ctx context.Context) error

func (*Playlist) Save

func (p *Playlist) Save(ctx context.Context) error

func (*Playlist) With

func (p *Playlist) With(tracks []Track)

type RegPhase

type RegPhase string
const (
	RegPhaseAlpha       RegPhase = ""
	RegPhaseEarlyAccess RegPhase = "EA"
)

type SSID

type SSID struct {
	Kind SSIDKind
	ID   string
}

func NewSSID

func NewSSID(kind SSIDKind, id string) SSID

func ParseSSID

func ParseSSID(id string) SSID

func (SSID) IsZero

func (s SSID) IsZero() bool

func (SSID) MarshalText

func (s SSID) MarshalText() ([]byte, error)

func (SSID) String

func (s SSID) String() string

func (*SSID) UnmarshalText

func (s *SSID) UnmarshalText(text []byte) error

type SSIDKind

type SSIDKind rune
const (
	SSIDArtist SSIDKind = 'A'
	SSIDAlbum  SSIDKind = 'a'
	SSIDTrack  SSIDKind = 't'
	// SSIDPlaylist SSIDKind = 'P'
	SSIDFolder  SSIDKind = 'F'
	SSIDInvalid SSIDKind = -1
)

func (SSIDKind) String

func (k SSIDKind) String() string

type Session

type Session struct {
	Token   string `dynamo:",hash"`
	UserID  int
	Expires time.Time `dynamo:",unixtime"`
	IP      string
}

func CreateSession

func CreateSession(ctx context.Context, userID int, ipaddr string) (Session, error)

func GetSession

func GetSession(ctx context.Context, token string) (Session, error)

type Star

type Star struct {
	UserID int  `dynamo:",hash"`
	SSID   SSID `dynamo:",range"`
	Date   time.Time
}

type Timegarb

type Timegarb struct {
	time.Time
	Garb string
}

func NewTimegarb

func NewTimegarb(t time.Time) Timegarb

func (Timegarb) MarshalText

func (t Timegarb) MarshalText() ([]byte, error)

func (*Timegarb) UnmarshalText

func (t *Timegarb) UnmarshalText(text []byte) error

type Track

type Track struct {
	UserID int       `dynamo:",hash" index:"UserID-SortID-index,hash" index:"UserID-Date-index,hash"`
	ID     string    `dynamo:",range"`
	SortID string    `index:"UserID-SortID-index,range" badgerhold:"index"`
	Date   time.Time `index:"UserID-Date-index,range"`

	// proper case:
	Info TrackInfo

	// should be lowercase:
	Title       string
	Artist      string
	Album       string
	AlbumArtist string
	Composer    string
	Genre       string
	Comment     string

	Number  int
	Total   int
	Disc    int
	Discs   int
	Year    int
	Picture Picture  `dynamo:",omitempty"`
	Tags    []string `dynamo:",set"` // user-defined tags

	Filename string
	Filetype string
	UploadID string
	Size     int
	Duration int // seconds

	TagFormat string
	Metadata  map[string]interface{} // IDv3 tags

	LastMod  time.Time
	LocalMod int64 // lastMod from client at upload time
	Dirty    bool

	Plays      int
	LastPlayed time.Time
	Resume     float64   // seconds
	ResumeMod  time.Time `dynamo:",omitempty"`

	Deleted bool

	// view only
	Starred time.Time `dynamo:"-"`
	DL      string    `dynamo:"-" json:",omitempty"`
}

func GetTrack

func GetTrack(ctx context.Context, userID int, trackID string) (Track, error)

func (Track) AlbumCode

func (t Track) AlbumCode() string

func (Track) AlbumEqual

func (t Track) AlbumEqual(other Track) bool

func (Track) AlbumSSID

func (t Track) AlbumSSID() SSID

func (Track) AnyArtist

func (t Track) AnyArtist() string

func (*Track) ApplyInfo

func (t *Track) ApplyInfo(info TrackInfo)

func (Track) ArtistEqual

func (t Track) ArtistEqual(other Track) bool

func (Track) ArtistSSID

func (t Track) ArtistSSID() SSID

func (Track) Bitrate

func (t Track) Bitrate() int

TODO: improve

func (*Track) Create

func (t *Track) Create(ctx context.Context) error

func (Track) CreateTable

func (Track) CreateTable(create *dynamo.CreateTable)

func (*Track) Delete

func (t *Track) Delete(ctx context.Context) error

func (Track) Env

func (t Track) Env() map[string]interface{}

func (Track) Ext

func (t Track) Ext() string

func (Track) FileURL

func (t Track) FileURL() string

func (*Track) IncPlays

func (t *Track) IncPlays(ctx context.Context) error

func (Track) LastModOrDate

func (t Track) LastModOrDate() time.Time

func (Track) MIMEType

func (t Track) MIMEType() string

func (Track) MatchesSSID

func (t Track) MatchesSSID(ssid SSID) bool

func (*Track) RefreshSortID

func (t *Track) RefreshSortID(ctx context.Context) error

func (*Track) Save

func (t *Track) Save(ctx context.Context) error

func (*Track) SetDuration

func (t *Track) SetDuration(ctx context.Context, secs int) error

func (*Track) SetResume

func (t *Track) SetResume(ctx context.Context, secs float64, modTime time.Time) error

func (Track) SortKey

func (t Track) SortKey() string

func (Track) StorageKey

func (t Track) StorageKey() string

func (Track) TrackSSID

func (t Track) TrackSSID() SSID

func (Track) VirtualPath

func (t Track) VirtualPath() string

VirtualPath returns an ideal path as synchronized to a filesystem

type TrackInfo

type TrackInfo struct {
	Title       string
	Artist      string
	Album       string
	AlbumArtist string
	Composer    string
	Genre       string
	Comment     string
}

func (TrackInfo) AnyArtist

func (t TrackInfo) AnyArtist() string

func (*TrackInfo) Sanitize

func (ti *TrackInfo) Sanitize()

type TrackSelOpt

type TrackSelOpt string
const (
	TrackSelDefault TrackSelOpt = ""
	TrackSelCtrlKey TrackSelOpt = "ctrl"
)

func (TrackSelOpt) String

func (tso TrackSelOpt) String() string

type Tracks

type Tracks []Track

func GetTracks

func GetTracks(ctx context.Context, userID int) (Tracks, error)

func GetTracksBatch

func GetTracksBatch(ctx context.Context, userID int, trackIDs []string) (Tracks, error)

func GetTracksInfo

func GetTracksInfo(ctx context.Context, userID int) (Tracks, error)

func GetTracksPartial

func GetTracksPartial(ctx context.Context, userID int, limit int64, startFrom dynamo.PagingKey) (Tracks, dynamo.PagingKey, error)

func GetTracksPartialSorted

func GetTracksPartialSorted(ctx context.Context, userID int, limit int64, startFrom dynamo.PagingKey) (Tracks, dynamo.PagingKey, error)

func (Tracks) IDs

func (tt Tracks) IDs() []string

func (Tracks) Len

func (tt Tracks) Len() int

func (Tracks) Less

func (tt Tracks) Less(i, j int) bool

func (Tracks) Swap

func (tt Tracks) Swap(i, j int)

type User

type User struct {
	ID       int    `dynamo:",hash"`
	Email    string `index:"Email-index,hash"`
	Password []byte `json:"-"`
	Regdate  time.Time
	Phase    RegPhase // phase at time of reg
	Recovery string

	Usage  int64
	Quota  int64
	Tracks int

	CustomerID string `index:"CustomerID-index,hash"` // from stripe
	Plan       PlanKind
	PlanStatus PlanStatus // from stripe
	PlanExpire time.Time  `dynamo:",omitempty"`
	Canceled   bool
	TrialOver  bool

	Theme   string
	Display DisplayOptions

	B2Token  string
	B2Expire time.Time `dynamo:",omitempty"`

	LastMod  time.Time
	LastDump time.Time `dynamo:",omitempty"`
}

func AddUsage

func AddUsage(ctx context.Context, id int, usage int64, trackCt int) (User, error)

func GetAllUsers

func GetAllUsers(ctx context.Context) ([]User, error)

func GetUser

func GetUser(ctx context.Context, id int) (User, error)

func GetUserByCustomerID

func GetUserByCustomerID(ctx context.Context, id string) (User, error)

func GetUserByEmail

func GetUserByEmail(ctx context.Context, email string) (User, error)

func (User) Active

func (u User) Active() bool

func (User) CalcQuota

func (u User) CalcQuota() int64

func (*User) Create

func (u *User) Create(ctx context.Context) error

func (*User) DeletePaymentInfo

func (u *User) DeletePaymentInfo(ctx context.Context) error

func (User) Expired

func (u User) Expired() bool

func (User) GetDump

func (u User) GetDump() (Dump, error)

func (User) GetTracks

func (u User) GetTracks(ctx context.Context) (Tracks, error)

func (User) Grandfathered

func (u User) Grandfathered() bool

func (User) SaveDump

func (u User) SaveDump(ctx context.Context, d Dump) error

func (*User) SetB2Token

func (u *User) SetB2Token(ctx context.Context, token string, expire time.Time) error

func (*User) SetCustomerID

func (u *User) SetCustomerID(ctx context.Context, id string) error

func (*User) SetDisplayOpt

func (u *User) SetDisplayOpt(ctx context.Context, disp DisplayOptions) error

func (*User) SetEmail

func (u *User) SetEmail(ctx context.Context, email string) error

func (*User) SetPassword

func (u *User) SetPassword(ctx context.Context, pw []byte) error

func (*User) SetPlan

func (u *User) SetPlan(ctx context.Context, kind PlanKind, status PlanStatus, expires time.Time, canceled bool) error

func (*User) SetRandomRecovery

func (u *User) SetRandomRecovery(ctx context.Context) error

func (*User) SetTheme

func (u *User) SetTheme(ctx context.Context, theme string) error

func (*User) SetTracks

func (u *User) SetTracks(ctx context.Context, count int) error

func (User) StorageFull

func (u User) StorageFull() bool

func (User) TimeRemaining

func (u User) TimeRemaining() time.Duration

func (User) Trialing

func (u User) Trialing() bool

func (*User) UpdateLastDump

func (u *User) UpdateLastDump(ctx context.Context, at time.Time) error

func (*User) UpdateLastMod

func (u *User) UpdateLastMod(ctx context.Context) error

func (User) UsageDesc

func (u User) UsageDesc() string

func (User) ValidPassword

func (u User) ValidPassword(password string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL