Skip to content

Commit

Permalink
Fix jellyfin session user avatar; Fix displaying music info
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Oct 24, 2024
1 parent 48dbc96 commit 77d2436
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/src/modules/jellyfin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ class AuthenticatedJellyfinClient {
Future<void> startTask(String taskId) => jellyfinClient.getScheduledTasksApi().startTask(taskId: taskId);
Uri getItemPrimaryImage(String itemId) => Uri.parse("${configUser.config?.basePath}/Items/$itemId/Images/Primary");
Uri getJellyfinItemUrl(String itemId) => Uri.parse("${configUser.config?.basePath}/#/details?id=$itemId");
Uri getUserImage(String userId, String imageTag) =>
Uri.parse("${configUser.config?.basePath}/Users/$userId/Images/Primary?tag=$imageTag");
Uri getUserImage(String userId, [String? imageTag]) => Uri.parse(
"${configUser.config?.basePath}/Users/$userId/Images/Primary${imageTag != null ? '?tag=$imageTag' : ''}");
Uri getUserProfile(String userId) =>
Uri.parse('${configUser.config?.basePath}/web/#/userprofile.html?userId=$userId');
}
Expand Down
13 changes: 8 additions & 5 deletions lib/src/util/jellyfin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ Iterable<EmbedFieldBuilder> getMediaPlaybackInfoFields(SessionInfo sessionInfo)
if (sessionInfo.transcodingInfo == null) {
final mediaStreams = (sessionInfo.nowPlayingItem!.mediaStreams as Iterable<MediaStream>? ?? []);

if (sessionInfo.nowPlayingItem!.type == BaseItemKind.audio) {
return getMediaInfoEmbedFields(mediaStreams.where((mediaStream) => mediaStream.type == MediaStreamType.audio));
}

return getMediaInfoEmbedFields([
...mediaStreams.where((mediaStream) => mediaStream.type == MediaStreamType.video),
...mediaStreams.where((mediaStream) =>
mediaStream.type == MediaStreamType.audio && mediaStream.index == sessionInfo.playState!.audioStreamIndex),
]).toList();
]);
}

final transcodingInfo = sessionInfo.transcodingInfo!;
Expand Down Expand Up @@ -101,7 +105,7 @@ EmbedBuilder? buildSessionEmbed(SessionInfo sessionInfo, AuthenticatedJellyfinCl
final footer = EmbedFooterBuilder(text: "Jellyfin instance: ${client.configUser.config!.name}");
final author = EmbedAuthorBuilder(
name: '${sessionInfo.userName} on ${sessionInfo.deviceName}',
iconUrl: sessionInfo.userPrimaryImageTag != null ? client.getItemPrimaryImage(sessionInfo.userId!) : null,
iconUrl: client.getUserImage(sessionInfo.userId!),
);

if (nowPlayingItem.type == BaseItemKind.episode) {
Expand Down Expand Up @@ -219,9 +223,8 @@ EmbedBuilder? buildMediaEmbedBuilder(BaseItemDto item, AuthenticatedJellyfinClie
}

EmbedBuilder getUserInfoEmbed(UserDto currentUser, AuthenticatedJellyfinClient client) {
final thumbnail = currentUser.primaryImageTag != null
? EmbedThumbnailBuilder(url: client.getUserImage(currentUser.id!, currentUser.primaryImageTag!))
: null;
final thumbnail =
currentUser.primaryImageTag != null ? EmbedThumbnailBuilder(url: client.getUserImage(currentUser.id!)) : null;

return EmbedBuilder(
thumbnail: thumbnail,
Expand Down

0 comments on commit 77d2436

Please sign in to comment.