Skip to content

Commit b925cce

Browse files
committed
fix: prevent crash on missing artist or invalid id
1 parent 2107413 commit b925cce

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ jobs:
5959
git config user.email team@jellyfin.org
6060
git pull
6161
git add ./manifest.json
62-
git commit -m "Update manifest.json"
63-
git push --force origin master
62+
git diff --cached --quiet || git commit -m "Update manifest.json"
63+
git push origin master

Jellyfin.Plugin.Lyrics/LyricsProvider.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
6868
}
6969
catch (HttpRequestException ex)
7070
{
71+
var artist = request.ArtistNames is { Count: > 0 } ? request.ArtistNames[0] : null;
7172
_logger.LogDebug(
7273
ex,
7374
"Unable to get results for {Artist} - {Album} - {Song}",
74-
request.ArtistNames?[0],
75+
artist,
7576
request.AlbumName,
7677
request.SongName);
7778
return Enumerable.Empty<RemoteLyricInfo>();
@@ -82,6 +83,13 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
8283
public async Task<LyricResponse?> GetLyricsAsync(string id, CancellationToken cancellationToken)
8384
{
8485
var splitId = id.Split('_', 2);
86+
if (splitId.Length != 2
87+
|| string.IsNullOrWhiteSpace(splitId[0])
88+
|| !IsSupportedLyricSuffix(splitId[1]))
89+
{
90+
_logger.LogDebug("Invalid lyric id format: {Id}", id);
91+
throw new ResourceNotFoundException($"Unable to get results for id {id}");
92+
}
8593

8694
try
8795
{
@@ -95,7 +103,7 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
95103
.ConfigureAwait(false);
96104
if (response is null)
97105
{
98-
throw new ResourceNotFoundException("Unable to get results for id {Id}");
106+
throw new ResourceNotFoundException($"Unable to get results for id {id}");
99107
}
100108

101109
if (string.Equals(splitId[1], SyncedSuffix, StringComparison.OrdinalIgnoreCase)
@@ -120,18 +128,24 @@ public async Task<IEnumerable<RemoteLyricInfo>> SearchAsync(
120128
};
121129
}
122130

123-
throw new ResourceNotFoundException("Unable to get results for id {Id}");
131+
throw new ResourceNotFoundException($"Unable to get results for id {id}");
124132
}
125133
catch (HttpRequestException ex)
126134
{
127135
_logger.LogDebug(
128136
ex,
129137
"Unable to get results for id {Id}",
130138
id);
131-
throw new ResourceNotFoundException("Unable to get results for id {Id}");
139+
throw new ResourceNotFoundException($"Unable to get results for id {id}");
132140
}
133141
}
134142

143+
private static bool IsSupportedLyricSuffix(string suffix)
144+
{
145+
return string.Equals(suffix, SyncedSuffix, StringComparison.OrdinalIgnoreCase)
146+
|| string.Equals(suffix, PlainSuffix, StringComparison.OrdinalIgnoreCase);
147+
}
148+
135149
private async Task<IEnumerable<RemoteLyricInfo>> GetExactMatch(
136150
LyricSearchRequest request,
137151
CancellationToken cancellationToken)
@@ -319,4 +333,4 @@ private List<RemoteLyricInfo> GetRemoteLyrics(LyricsSearchResponse response)
319333

320334
return results;
321335
}
322-
}
336+
}

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ Looking for **v10.10.7 support**? -> https://github.com/Felitendo/jellyfin-plugi
2323
```
2424
https://raw.githubusercontent.com/Felitendo/jellyfin-plugin-lyrics/master/manifest.json
2525
```
26-
4. Open the **Plugin Catalog** in your Jellyfin dashboard
27-
5. Look for **"Lyrics"** under the **Metadata** category and install it
28-
6. Restart Jellyfin
29-
7. Search for the Plugin "LrcLib" (is sometimes pre-installed) and uninstall it (if it's not installed then skip this step)
30-
8. Restart Jellyfin again
31-
9. Go to **Scheduled Tasks** and run **"Download and upgrade lyrics (new)"**
32-
10. Go to **Libraries** and click on **Scan all Libraries**
26+
3. Open the **Plugin Catalog** in your Jellyfin dashboard
27+
4. Look for **"Lyrics"** under the **Metadata** category and install it
28+
5. Restart Jellyfin
29+
6. Search for the Plugin "LrcLib" (is sometimes pre-installed) and uninstall it (if it's not installed then skip this step)
30+
7. Restart Jellyfin again
31+
8. Go to **Scheduled Tasks** and run **"Download and upgrade lyrics (new)"**
32+
9. Go to **Libraries** and click on **Scan all Libraries**
3333

3434
---
3535

0 commit comments

Comments
 (0)