Skip to content

A self-hosted media server and file management system

fix: lrclib service does not use album and artist correctly

aminnausinb56e1ae71413
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index a0c50e60..85111fcc 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -195,8 +195,8 @@ class VerifyFiles implements ShouldQueue {
if ($stored['media_type'] !== $media_type) {
$changes['media_type'] = $media_type;
}
- // if file is of type audio one of the following is true: description and episode is null, codec is null, bitrate is null => generate description from audio tags
- $audioMetadata = ((is_null($metadata->description) && is_null($metadata->episode)) || is_null($metadata->bitrate) || is_null($metadata->codec)) && $is_audio ? $this->getAudioDescription($filePath, $this->fileMetaData ?? null) : [];
+ // if file is of type audio and one of the following is true: artist is null, album is null, codec is null, bitrate is null => generate description from audio tags
+ $audioMetadata = (is_null($metadata->artist) || is_null($metadata->album) || is_null($metadata->bitrate) || is_null($metadata->codec)) && $is_audio ? $this->getAudioDescription($filePath, $this->fileMetaData ?? null) : [];
// TODO: if no poster_url is set or file was modified since last update and the file is of type audio, extract image
// TODO: if poster_url is set and it is not a local url, download and save as local image
@@ -282,6 +282,14 @@ class VerifyFiles implements ShouldQueue {
$changes['lyrics'] = $audioMetadata['lyrics'] ?? null;
}
+ if (is_null($metadata->artist) || $fileUpdated) {
+ $changes['artist'] = $audioMetadata['artist'] ?? null;
+ }
+
+ if (is_null($metadata->album) || $fileUpdated) {
+ $changes['album'] = $audioMetadata['album'] ?? null;
+ }
+
if (is_null($metadata->codec) && ! isset($changes['codec'])) {
$changes['codec'] = $audioMetadata['codec'] ?? null;
}
@@ -334,6 +342,8 @@ class VerifyFiles implements ShouldQueue {
'title',
'description',
'lyrics',
+ 'artist',
+ 'album',
'duration',
'season',
'episode',
diff --git a/app/Services/External/LrcLibService.php b/app/Services/External/LrcLibService.php
index dd213089..b9aa42e2 100644
--- a/app/Services/External/LrcLibService.php
+++ b/app/Services/External/LrcLibService.php
@@ -10,7 +10,7 @@ class LrcLibService {
public function importLyrics(Metadata $metadata): array {
$query = array_filter([
'track_name' => $metadata->title,
- 'artist_name' => explode(' - ', $metadata->description)[0],
+ 'artist_name' => $metadata->artist ?? explode(' - ', $metadata->description)[0],
'album_name' => $metadata->album,
'duration' => $metadata->duration,
], fn ($value) => $value !== null && $value !== '');
@@ -23,8 +23,8 @@ class LrcLibService {
public function searchLyrics(Metadata $metadata, Request $request): array {
$query = array_filter([
'track_name' => $request->query('track') ?? $metadata->title,
- 'artist_name' => $request->query('artist') ?? explode(' - ', $metadata->description)[0],
- 'album_name' => $request->query('album'),
+ 'artist_name' => $request->query('artist') ?? $metadata->artist ?? explode(' - ', $metadata->description)[0],
+ 'album_name' => $request->query('album') ?? $metadata->album,
], fn ($value) => $value !== null && $value !== '');
$response = Http::get('https://lrclib.net/api/search', $query);