mirror of
https://github.com/koel/koel
synced 2024-11-24 21:23:06 +00:00
68 lines
1.4 KiB
PHP
68 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property string path
|
|
*/
|
|
class Song extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* Attributes to be hidden from JSON outputs.
|
|
* Here we specify to hide lyrics as well to save some bandwidth (actually, lots of it).
|
|
* Lyrics can then be queried on demand.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = ['lyrics', 'created_at', 'updated_at', 'path', 'mtime'];
|
|
|
|
public function album()
|
|
{
|
|
return $this->belongsTo(Album::class);
|
|
}
|
|
|
|
public function playlists()
|
|
{
|
|
return $this->belongsToMany(Playlist::class);
|
|
}
|
|
|
|
/**
|
|
* Sometimes the tags extracted from getID3 are HTML entity encoded.
|
|
* This makes sure they are always sane.
|
|
*
|
|
* @param $value
|
|
*/
|
|
public function setTitleAttribute($value)
|
|
{
|
|
$this->attributes['title'] = html_entity_decode($value);
|
|
}
|
|
|
|
/**
|
|
* Some songs don't have a title.
|
|
* Fall back to the file name (without extension) for such.
|
|
*
|
|
* @param $value
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getTitleAttribute($value)
|
|
{
|
|
return $value ?: pathinfo($this->path, PATHINFO_FILENAME);
|
|
}
|
|
|
|
/**
|
|
* Prepare the lyrics for displaying.
|
|
*
|
|
* @param $value
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getLyricsAttribute($value)
|
|
{
|
|
return nl2br($value);
|
|
}
|
|
}
|