sc

package
v0.0.0-...-1ddfbef Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientIDCache clientIdCache
View Source
var ErrIDNotFound = errors.New("clientid not found")
View Source
var ErrIncompatibleStream = errors.New("incompatible stream")
View Source
var ErrKindNotCorrect = errors.New("entity of incorrect kind")
View Source
var ErrNoURL = errors.New("no url")
View Source
var ErrScriptNotFound = errors.New("script not found")
View Source
var ErrVersionNotFound = errors.New("version not found")
View Source
var PlaylistsCache = map[string]cached[Playlist]{}
View Source
var TracksCache = map[string]cached[Track]{}
View Source
var UsersCache = map[string]cached[User]{}

Functions

func DoWithRetry

func DoWithRetry(httpc *fasthttp.HostClient, req *fasthttp.Request, resp *fasthttp.Response) (err error)

Since the http client is setup to always keep connections idle (great for speed, no need to open a new one everytime), those connections may be closed by soundcloud after some time of inactivity, this ensures that we retry those requests that fail due to the connection closing/timing out

func DoWithRetryAll

func DoWithRetryAll(httpc *fasthttp.Client, req *fasthttp.Request, resp *fasthttp.Response) (err error)

Just retry any kind of errors, why not

func GetClientID

func GetClientID() (string, error)

inspired by github.com/imputnet/cobalt (mostly stolen lol)

func GetMissingTracks

func GetMissingTracks(cid string, missing []MissingTrack) (res []Track, next []MissingTrack, err error)

func JoinMissingTracks

func JoinMissingTracks(missing []MissingTrack) (st string)

func Resolve

func Resolve(cid string, path string, out any) error

func TagListParser

func TagListParser(taglist string) (res []string)

Types

type Format

type Format struct {
	Protocol Protocol `json:"protocol"`
	MimeType string   `json:"mime_type"`
}

type Like

type Like struct {
	Track    *Track
	Playlist *Playlist
}

same thing

func (Like) Fix

func (l Like) Fix(prefs cfg.Preferences)
type Link struct {
	URL   string `json:"url"`
	Title string `json:"title"`
}

type Media

type Media struct {
	Transcodings []Transcoding `json:"transcodings"`
}

func (Media) SelectCompatible

func (m Media) SelectCompatible(mode string, opus bool) (*Transcoding, string)

type MissingTrack

type MissingTrack struct {
	ID    string
	Index int
}

type Paginated

type Paginated[T any] struct {
	Collection []T    `json:"collection"`
	Total      int64  `json:"total_results"`
	Next       string `json:"next_href"`
}

func GetFeaturedTracks

func GetFeaturedTracks(cid string, prefs cfg.Preferences, args string) (*Paginated[*Track], error)

func GetSelections

func GetSelections(cid string, prefs cfg.Preferences) (*Paginated[*Selection], error)

func RecentTracks

func RecentTracks(cid string, prefs cfg.Preferences, args string) (*Paginated[*Track], error)

func SearchPlaylists

func SearchPlaylists(cid string, prefs cfg.Preferences, args string) (*Paginated[*Playlist], error)

func SearchTracks

func SearchTracks(cid string, prefs cfg.Preferences, args string) (*Paginated[*Track], error)

func SearchUsers

func SearchUsers(cid string, prefs cfg.Preferences, args string) (*Paginated[*User], error)

func (*Paginated[T]) Proceed

func (p *Paginated[T]) Proceed(cid string, shouldUnfold bool) error

type Playlist

type Playlist struct {
	Artwork      string `json:"artwork_url"`
	CreatedAt    string `json:"created_at"`
	Description  string `json:"description"`
	Kind         string `json:"kind"` // should always be "playlist"!
	LastModified string `json:"last_modified"`
	Likes        int64  `json:"likes_count"`
	Permalink    string `json:"permalink"`
	//ReleaseDate  string  `json:"release_date"`
	TagList    string  `json:"tag_list"`
	Title      string  `json:"title"`
	Type       string  `json:"set_type"`
	Album      bool    `json:"is_album"`
	Author     User    `json:"user"`
	Tracks     []Track `json:"tracks"`
	TrackCount int64   `json:"track_count"`

	MissingTracks string `json:"-"`
}

func GetPlaylist

func GetPlaylist(cid string, permalink string) (Playlist, error)

func (*Playlist) Fix

func (p *Playlist) Fix(cid string, cached bool, fixAuthor bool) error

func (Playlist) FormatDescription

func (p Playlist) FormatDescription() string

func (*Playlist) GetMissingTracks

func (p *Playlist) GetMissingTracks(cid string) error

func (Playlist) Href

func (p Playlist) Href() string

func (*Playlist) Postfix

func (p *Playlist) Postfix(prefs cfg.Preferences, fixTracks bool, fixAuthor bool) []Track

type Protocol

type Protocol string
const (
	ProtocolHLS         Protocol = "hls"
	ProtocolProgressive Protocol = "progressive"
)

type Repost

type Repost struct {
	Type RepostType

	Track    *Track    // type == track-report
	Playlist *Playlist // type == playlist-repost
}

not worthy of its own file

func (Repost) Fix

func (r Repost) Fix(prefs cfg.Preferences)

type RepostType

type RepostType string
const (
	TrackRepost    RepostType = "track-repost"
	PlaylistRepost RepostType = "playlist-repost"
)

type Selection

type Selection struct {
	Title string               `json:"title"`
	Kind  string               `json:"kind"`  // should always be "selection"!
	Items Paginated[*Playlist] `json:"items"` // ?? why
}

func (*Selection) Fix

func (s *Selection) Fix(prefs cfg.Preferences)

type Stream

type Stream struct {
	URL string `json:"url"`
}

type Track

type Track struct {
	Artwork     string `json:"artwork_url"`
	Comments    int    `json:"comment_count"`
	CreatedAt   string `json:"created_at"`
	Description string `json:"description"`
	//Duration      int    `json:"duration"` // there are duration and full_duration fields wtf does that mean
	Genre         string      `json:"genre"`
	Kind          string      `json:"kind"` // should always be "track"!
	LastModified  string      `json:"last_modified"`
	License       string      `json:"license"`
	Likes         int64       `json:"likes_count"`
	Permalink     string      `json:"permalink"`
	Played        int64       `json:"playback_count"`
	Reposted      int64       `json:"reposts_count"`
	TagList       string      `json:"tag_list"`
	Title         string      `json:"title"`
	ID            json.Number `json:"id"`
	Media         Media       `json:"media"`
	Authorization string      `json:"track_authorization"`
	Author        User        `json:"user"`
	Policy        TrackPolicy `json:"policy"`
}

func GetArbitraryTrack

func GetArbitraryTrack(cid string, data string) (Track, error)

Currently supports: http/https links: - api.soundcloud.com/tracks/<id> (api-v2 subdomain also supported) - soundcloud.com/<user>/<track>

plain permalink/id: - <user>/<track> - <id>

func GetNextMissingTracks

func GetNextMissingTracks(cid string, raw string) (res []Track, next []string, err error)

func GetTrack

func GetTrack(cid string, permalink string) (Track, error)

func GetTrackByID

func GetTrackByID(cid string, id string) (Track, error)

func GetTracks

func GetTracks(cid string, ids string) ([]Track, error)

func (Track) DownloadImage

func (t Track) DownloadImage() ([]byte, string, error)

func (*Track) Fix

func (t *Track) Fix(large bool, fixAuthor bool)

func (Track) FormatDescription

func (t Track) FormatDescription() string

func (*Track) GetAlbums

func (t *Track) GetAlbums(cid string, prefs cfg.Preferences, args string) (*Paginated[*Playlist], error)

func (*Track) GetPlaylists

func (t *Track) GetPlaylists(cid string, prefs cfg.Preferences, args string) (*Paginated[*Playlist], error)

func (*Track) GetRelated

func (t *Track) GetRelated(cid string, prefs cfg.Preferences, args string) (*Paginated[*Track], error)

func (Track) Href

func (t Track) Href() string

func (*Track) Postfix

func (t *Track) Postfix(prefs cfg.Preferences, fixAuthor bool)

type TrackPolicy

type TrackPolicy string
const (
	PolicyBlock TrackPolicy = "BLOCK" // not available (in your country)
	PolicySnip  TrackPolicy = "SNIP"  // 30-second snippet available
	PolicyAllow TrackPolicy = "ALLOW" // all good
)

type Transcoding

type Transcoding struct {
	URL     string `json:"url"`
	Preset  string `json:"preset"`
	Format  Format `json:"format"`
	Quality string `json:"quality"`
}

func (Transcoding) GetStream

func (tr Transcoding) GetStream(cid string, prefs cfg.Preferences, authorization string) (string, error)

type User

type User struct {
	Avatar       string      `json:"avatar_url"`
	CreatedAt    string      `json:"created_at"`
	Description  string      `json:"description"`
	Followers    int64       `json:"followers_count"`
	Following    int64       `json:"followings_count"`
	FullName     string      `json:"full_name"`
	Kind         string      `json:"kind"` // should always be "user"!
	LastModified string      `json:"last_modified"`
	Liked        int64       `json:"likes_count"`
	Permalink    string      `json:"permalink"`
	Playlists    int64       `json:"playlist_count"`
	Tracks       int64       `json:"track_count"`
	ID           json.Number `json:"id"`
	Username     string      `json:"username"`
	Verified     bool        `json:"verified"`

	WebProfiles []Link
}

func GetUser

func GetUser(cid string, permalink string) (User, error)

func (*User) Fix

func (u *User) Fix(large bool)

func (User) FormatDescription

func (u User) FormatDescription() string

func (User) FormatUsername

func (u User) FormatUsername() string

func (User) GetAlbums

func (u User) GetAlbums(cid string, prefs cfg.Preferences, args string) (*Paginated[*Playlist], error)

func (User) GetFollowers

func (u User) GetFollowers(cid string, prefs cfg.Preferences, args string) (*Paginated[*User], error)

func (User) GetFollowing

func (u User) GetFollowing(cid string, prefs cfg.Preferences, args string) (*Paginated[*User], error)

func (User) GetLikes

func (u User) GetLikes(cid string, prefs cfg.Preferences, args string) (*Paginated[*Like], error)

func (User) GetPlaylists

func (u User) GetPlaylists(cid string, prefs cfg.Preferences, args string) (*Paginated[*Playlist], error)

func (*User) GetRelated

func (u *User) GetRelated(cid string, prefs cfg.Preferences) ([]*User, error)

func (User) GetReposts

func (u User) GetReposts(cid string, prefs cfg.Preferences, args string) (*Paginated[*Repost], error)

func (*User) GetTopTracks

func (u *User) GetTopTracks(cid string, prefs cfg.Preferences) ([]*Track, error)

func (User) GetTracks

func (u User) GetTracks(cid string, prefs cfg.Preferences, args string) (*Paginated[*Track], error)

func (*User) GetWebProfiles

func (u *User) GetWebProfiles(cid string) error

func (*User) Postfix

func (u *User) Postfix(prefs cfg.Preferences)

Jump to

Keyboard shortcuts

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