PHP Class app\models\Song

Inheritance: extends Illuminate\Database\Eloquent\Model
Mostra file Open project: phanan/koel Class Usage Examples

Public Properties

Property Type Description
$incrementing boolean Indicates if the IDs are auto-incrementing.

Protected Properties

Property Type Description
$casts array
$guarded
$hidden array Here we specify to hide lyrics as well to save some bandwidth (actually, lots of it). Lyrics can then be queried on demand.

Public Methods

Method Description
album ( )
byPath ( string $path ) : Song | null Get a Song record using its path.
contributingArtist ( )
getArtistAttribute ( ) : Artist Get the correct artist of the song.
getFavorites ( User $user, boolean $toArray = false ) : Illuminate\Database\Eloquent\Collection | array Get all songs favored by a user.
getLyricsAttribute ( $value ) : string Prepare the lyrics for displaying.
getObjectStoragePublicUrl ( Aws\AwsClient $s3 = null ) : string Get the song's Object Storage url for streaming or downloading.
getRelatedYouTubeVideos ( string $youTubePageToken = '' ) : object | false Get the YouTube videos related to this song.
getS3ParamsAttribute ( ) : boolean | array Get the bucket and key name of an S3 object.
getTitleAttribute ( $value ) : string Some songs don't have a title.
isS3ObjectAttribute ( ) : boolean Determine if the song is an AWS S3 Object.
playlists ( )
scopeInDirectory ( Builder $query, string $path ) : Builder Scope a query to only include songs in a given directory.
scrobble ( string $timestamp ) : mixed Scrobble the song using Last.fm service.
setTitleAttribute ( $value ) Sometimes the tags extracted from getID3 are HTML entity encoded.
updateInfo ( array $ids, array $data ) : array Update song info.
updateSingle ( string $title, string $albumName, string $artistName, string $lyrics, integer $track, integer $compilationState ) : self Update a single song's info.

Method Details

album() public method

public album ( )

byPath() public static method

Get a Song record using its path.
public static byPath ( string $path ) : Song | null
$path string
return Song | null

contributingArtist() public method

public contributingArtist ( )

getArtistAttribute() public method

If it's part of a compilation, that would be the contributing artist. Otherwise, it's the album artist.
public getArtistAttribute ( ) : Artist
return Artist

getFavorites() public static method

Get all songs favored by a user.
public static getFavorites ( User $user, boolean $toArray = false ) : Illuminate\Database\Eloquent\Collection | array
$user User
$toArray boolean
return Illuminate\Database\Eloquent\Collection | array

getLyricsAttribute() public method

Prepare the lyrics for displaying.
public getLyricsAttribute ( $value ) : string
$value
return string

getObjectStoragePublicUrl() public method

Get the song's Object Storage url for streaming or downloading.
public getObjectStoragePublicUrl ( Aws\AwsClient $s3 = null ) : string
$s3 Aws\AwsClient
return string

getRelatedYouTubeVideos() public method

Get the YouTube videos related to this song.
public getRelatedYouTubeVideos ( string $youTubePageToken = '' ) : object | false
$youTubePageToken string The YouTube page token, for pagination purpose.
return object | false

getS3ParamsAttribute() public method

Get the bucket and key name of an S3 object.
public getS3ParamsAttribute ( ) : boolean | array
return boolean | array

getTitleAttribute() public method

Fall back to the file name (without extension) for such.
public getTitleAttribute ( $value ) : string
$value
return string

isS3ObjectAttribute() public method

Determine if the song is an AWS S3 Object.
public isS3ObjectAttribute ( ) : boolean
return boolean

playlists() public method

public playlists ( )

scopeInDirectory() public method

Scope a query to only include songs in a given directory.
public scopeInDirectory ( Builder $query, string $path ) : Builder
$query Illuminate\Database\Eloquent\Builder
$path string Full path of the directory
return Illuminate\Database\Eloquent\Builder

scrobble() public method

Scrobble the song using Last.fm service.
public scrobble ( string $timestamp ) : mixed
$timestamp string The UNIX timestamp in which the song started playing.
return mixed

setTitleAttribute() public method

This makes sure they are always sane.
public setTitleAttribute ( $value )
$value

updateInfo() public static method

Update song info.
public static updateInfo ( array $ids, array $data ) : array
$ids array
$data array The data array, with these supported fields: - title - artistName - albumName - lyrics All of these are optional, in which case the info will not be changed (except for lyrics, which will be emptied).
return array

updateSingle() public method

Update a single song's info.
public updateSingle ( string $title, string $albumName, string $artistName, string $lyrics, integer $track, integer $compilationState ) : self
$title string
$albumName string
$artistName string
$lyrics string
$track integer
$compilationState integer
return self

Property Details

$casts protected_oe property

protected array $casts
return array

$guarded protected_oe property

protected $guarded

$hidden protected_oe property

Here we specify to hide lyrics as well to save some bandwidth (actually, lots of it). Lyrics can then be queried on demand.
protected array $hidden
return array

$incrementing public_oe property

Indicates if the IDs are auto-incrementing.
public bool $incrementing
return boolean