Skip to content

Commit

Permalink
Fix external subtitles not added to external player
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Dec 19, 2024
1 parent 2c5f17a commit 25db7d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.jellyfin.apiclient.model.dlna.SubtitleProfile;
import org.jellyfin.apiclient.model.dlna.TranscodeSeekInfo;
import org.jellyfin.apiclient.model.session.PlayMethod;
import org.jellyfin.sdk.api.client.ApiClient;
import org.jellyfin.sdk.model.api.MediaSourceInfo;
import org.jellyfin.sdk.model.api.MediaStream;
import org.jellyfin.sdk.model.api.MediaStreamType;
import org.jellyfin.sdk.model.api.SubtitleDeliveryMethod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;

public class StreamInfo {
Expand Down Expand Up @@ -120,28 +122,22 @@ public final String getMediaSourceId() {
return getMediaSource() == null ? null : getMediaSource().getId();
}

public final ArrayList<SubtitleStreamInfo> getSubtitleProfiles(boolean includeSelectedTrackOnly, String baseUrl, String accessToken) {
return getSubtitleProfiles(includeSelectedTrackOnly, false, baseUrl, accessToken);
}

public final ArrayList<SubtitleStreamInfo> getSubtitleProfiles(boolean includeSelectedTrackOnly, boolean enableAllProfiles, String baseUrl, String accessToken) {
public final ArrayList<SubtitleStreamInfo> getSubtitleProfiles(ApiClient api) {
ArrayList<SubtitleStreamInfo> list = new ArrayList<SubtitleStreamInfo>();

if (!includeSelectedTrackOnly) {
if (getMediaSource() == null) return list;
if (getMediaSource() == null) return list;

for (org.jellyfin.sdk.model.api.MediaStream stream : getMediaSource().getMediaStreams()) {
if (stream.getType() == org.jellyfin.sdk.model.api.MediaStreamType.SUBTITLE) {
SubtitleStreamInfo info = getSubtitleStreamInfo(stream, getDeviceProfile().getSubtitleProfiles());
list.add(info);
}
for (org.jellyfin.sdk.model.api.MediaStream stream : getMediaSource().getMediaStreams()) {
if (stream.getType() == org.jellyfin.sdk.model.api.MediaStreamType.SUBTITLE) {
SubtitleStreamInfo info = getSubtitleStreamInfo(api, stream, getDeviceProfile().getSubtitleProfiles());
list.add(info);
}
}

return list;
}

private SubtitleStreamInfo getSubtitleStreamInfo(org.jellyfin.sdk.model.api.MediaStream stream, SubtitleProfile[] subtitleProfiles) {
private SubtitleStreamInfo getSubtitleStreamInfo(ApiClient api, org.jellyfin.sdk.model.api.MediaStream stream, SubtitleProfile[] subtitleProfiles) {
SubtitleProfile subtitleProfile = StreamBuilder.getSubtitleProfile(stream, subtitleProfiles, getPlayMethod());
SubtitleStreamInfo info = new SubtitleStreamInfo();
String tempVar2 = stream.getLanguage();
Expand All @@ -150,6 +146,9 @@ private SubtitleStreamInfo getSubtitleStreamInfo(org.jellyfin.sdk.model.api.Medi
info.setIndex(stream.getIndex());
info.setDeliveryMethod(subtitleProfile.getMethod());
info.setDisplayTitle(stream.getDisplayTitle());
if (stream.getDeliveryUrl() != null) {
info.setUrl(api.createUrl(stream.getDeliveryUrl(), new HashMap<>(), new HashMap<>(), true));
}
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ protected void startExternalActivity(String path, String container) {
* @param playerIntent Put player API params of sub urls.
*/
private void adaptExternalSubtitles(StreamInfo mediaStreamInfo, Intent playerIntent) {

List<SubtitleStreamInfo> externalSubs = mediaStreamInfo.getSubtitleProfiles(false,
apiClient.getValue().getBaseUrl(), apiClient.getValue().getAccessToken()).stream()
List<SubtitleStreamInfo> externalSubs = mediaStreamInfo.getSubtitleProfiles(apiClient.getValue()).stream()
.filter(stream -> stream.getDeliveryMethod() == SubtitleDeliveryMethod.External && stream.getUrl() != null)
.collect(Collectors.toList());

Expand Down

0 comments on commit 25db7d5

Please sign in to comment.