Song
extends BaseModel
in package
implements
DirectStreamableFile, Recommendable
uses
HasFactory, HasLibraryAccess, HasNanoPublicId, HasRecommendation, HasContentSimilarity, HasMusicMetadata
Table of Contents
Interfaces
Properties
- $filterRelations : array<string|int, mixed>
- $librarySlug : string
- $dateFormat : mixed
- $fillable : mixed
- $perPage : mixed
- $with : mixed
Methods
- album() : mixed
- artists() : mixed
- bootHasNanoPublicId() : mixed
- clearRecommendationCache() : void
- Clear recommendation cache for all models of this class
- createRadioStation() : mixed
- Create a radio station based on this song
- findContentSimilar() : Collection
- Advanced content similarity using PostgreSQL functions
- findSimilarByArtists() : Collection
- Find songs by similar artists or collaborating artists
- findSimilarByContent() : Collection
- Find songs with similar musical content (genre, artists, tempo, etc.)
- findSimilarByDuration() : Collection
- Find songs with similar duration (±20%)
- findSimilarByGenres() : Collection
- Find songs with similar genres using PostgreSQL function
- formatForException() : string
- generateRecommendations() : int
- Generate recommendations for all models of this class
- generateRecommendationsForSelf() : int
- Generate recommendations for this specific model instance
- genres() : mixed
- getMimeType() : string
- Get the mime type of the file
- getMusicallySimilar() : mixed
- Get songs that are musically similar to this one
- getPath() : string
- Get the path of the file
- getRecommendationConfig() : array<string|int, mixed>
- Returns the array of configuration for the model.
- getRecommendations() : mixed
- Get recommended songs based on this song's musical characteristics
- getRecommendationsByListeningHistory() : Collection
- Get content-based recommendations using user listening patterns
- getRecommendationsWithRelations() : Collection
- Get recommendations with specified relationships loaded
- getRouteKeyName() : string
- getSimilarByMetadata() : Collection
- Get songs with similar musical characteristics
- getSize() : int
- Get the size of the file in bytes
- newEloquentBuilder() : mixed
- scheduleRecommendationGeneration() : void
- Schedule recommendation generation as a background job
- update() : mixed
- userHasAccessToLibrary() : bool
- Determine if a user has access to the library.
- userMediaActivies() : mixed
- scopeWhereGenreNames() : mixed
- scopeWhereGenreSlugs() : mixed
Properties
$filterRelations
public
static array<string|int, mixed>
$filterRelations
= ['album', 'album.cover', 'artists', 'genres']
$librarySlug
public
string
$librarySlug
Available in SongController
$dateFormat
protected
mixed
$dateFormat
= 'Y-m-d H:i:sO'
$fillable
protected
mixed
$fillable
= ['album_id', 'title', 'path', 'size', 'mime_type', 'length', 'lyrics', 'track', 'disc', 'modified_time', 'year', 'comment', 'hash', 'librarySlug', 'mbid', 'discogs_id', 'position']
$perPage
protected
mixed
$perPage
= 30
$with
protected
mixed
$with
= ['album']
Methods
album()
public
album() : mixed
artists()
public
artists() : mixed
bootHasNanoPublicId()
public
static bootHasNanoPublicId() : mixed
clearRecommendationCache()
Clear recommendation cache for all models of this class
public
static clearRecommendationCache(string $recommendationName) : void
Parameters
- $recommendationName : string
createRadioStation()
Create a radio station based on this song
public
createRadioStation([int $songCount = 50 ]) : mixed
Parameters
- $songCount : int = 50
findContentSimilar()
Advanced content similarity using PostgreSQL functions
public
static findContentSimilar([array<string|int, mixed> $genreIds = [] ][, array<string|int, mixed> $artistIds = [] ][, int|null $duration = null ][, int|null $year = null ][, int $limit = 50 ]) : Collection
Parameters
- $genreIds : array<string|int, mixed> = []
- $artistIds : array<string|int, mixed> = []
- $duration : int|null = null
- $year : int|null = null
- $limit : int = 50
Return values
CollectionfindSimilarByArtists()
Find songs by similar artists or collaborating artists
public
findSimilarByArtists([int $limit = 20 ]) : Collection
Parameters
- $limit : int = 20
Return values
CollectionfindSimilarByContent()
Find songs with similar musical content (genre, artists, tempo, etc.)
public
findSimilarByContent([int $limit = 10 ]) : Collection
Parameters
- $limit : int = 10
Return values
CollectionfindSimilarByDuration()
Find songs with similar duration (±20%)
public
findSimilarByDuration([int $limit = 20 ]) : Collection
Parameters
- $limit : int = 20
Return values
CollectionfindSimilarByGenres()
Find songs with similar genres using PostgreSQL function
public
findSimilarByGenres([int $limit = 20 ]) : Collection
Parameters
- $limit : int = 20
Return values
CollectionformatForException()
public
formatForException() : string
Return values
stringgenerateRecommendations()
Generate recommendations for all models of this class
public
static generateRecommendations(string $recommendationName[, array<string|int, mixed> $options = [] ]) : int
Parameters
- $recommendationName : string
- $options : array<string|int, mixed> = []
Return values
int —Number of recommendations generated
generateRecommendationsForSelf()
Generate recommendations for this specific model instance
public
generateRecommendationsForSelf(string $recommendationName) : int
Parameters
- $recommendationName : string
Return values
int —Number of recommendations generated
genres()
public
genres() : mixed
getMimeType()
Get the mime type of the file
public
getMimeType() : string
Return values
stringgetMusicallySimilar()
Get songs that are musically similar to this one
public
getMusicallySimilar([int $limit = 10 ]) : mixed
Parameters
- $limit : int = 10
getPath()
Get the path of the file
public
getPath() : string
Return values
stringgetRecommendationConfig()
Returns the array of configuration for the model.
public
static getRecommendationConfig() : array<string|int, mixed>
[ 'recommendation_name_1' => [ 'recommendation_algorithm' => 'db_relation', // db_relation, similarity 'recommendation_data_table' => 'recommendation_data_table', 'recommendation_data_table_filter' => [ 'field' => 'value' ], 'recommendation_data_field' => 'recommendation_data_field', 'recommendation_data_field_type' => 'recommendation_data_field_type', 'recommendation_group_field' => 'recommendation_group_field', 'recommendation_count' => 5, 'recommendation_order' => 'desc' ], 'recommendation_name_2' => [ 'recommendation_algorithm' => 'similarity', // db_relation, similarity 'similarity_feature_weight' => 1, 'similarity_numeric_value_weight' => 1, 'similarity_numeric_value_high_range' => 1, 'similarity_taxonomy_weight' => 1, 'similarity_feature_attributes' => [ 'attribute1', 'attribute2' ], 'similarity_numeric_value_attributes' => [ 'attribute1', 'attribute2' ], 'similarity_taxonomy_attributes' => [ [ 'relation' => 'attribute' ] ], 'recommendation_count' => 5, 'recommendation_order' => 'desc' ] ]
Return values
array<string|int, mixed>getRecommendations()
Get recommended songs based on this song's musical characteristics
public
getRecommendations([int $limit = 20 ]) : mixed
Parameters
- $limit : int = 20
getRecommendationsByListeningHistory()
Get content-based recommendations using user listening patterns
public
getRecommendationsByListeningHistory(int $userId[, int $limit = 20 ]) : Collection
Parameters
- $userId : int
- $limit : int = 20
Return values
CollectiongetRecommendationsWithRelations()
Get recommendations with specified relationships loaded
public
getRecommendationsWithRelations(string $recommendationName, array<string|int, mixed> $relationships) : Collection
Parameters
- $recommendationName : string
- $relationships : array<string|int, mixed>
Return values
CollectiongetRouteKeyName()
public
getRouteKeyName() : string
Return values
stringgetSimilarByMetadata()
Get songs with similar musical characteristics
public
getSimilarByMetadata([array<string|int, mixed> $criteria = [] ][, int $limit = 20 ]) : Collection
Parameters
- $criteria : array<string|int, mixed> = []
- $limit : int = 20
Return values
CollectiongetSize()
Get the size of the file in bytes
public
getSize() : int
Return values
intnewEloquentBuilder()
public
newEloquentBuilder(mixed $query) : mixed
Parameters
- $query : mixed
scheduleRecommendationGeneration()
Schedule recommendation generation as a background job
public
static scheduleRecommendationGeneration(string $recommendationName) : void
Parameters
- $recommendationName : string
update()
public
update([array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $attributes : array<string|int, mixed> = []
- $options : array<string|int, mixed> = []
userHasAccessToLibrary()
Determine if a user has access to the library.
public
userHasAccessToLibrary(int $userId, int $libraryId) : bool
Parameters
- $userId : int
- $libraryId : int
Return values
booluserMediaActivies()
public
userMediaActivies() : mixed
scopeWhereGenreNames()
protected
scopeWhereGenreNames(BaseBuilder $q, array<string|int, mixed> $names) : mixed
Parameters
- $q : BaseBuilder
- $names : array<string|int, mixed>
scopeWhereGenreSlugs()
protected
scopeWhereGenreSlugs(BaseBuilder $q, array<string|int, mixed> $slugs) : mixed
Parameters
- $q : BaseBuilder
- $slugs : array<string|int, mixed>