Skip to content

Commit

Permalink
fix using same filename item will end in the same id even if changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfaceS committed Oct 25, 2023
1 parent 349f8e5 commit f2ae475
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/pms/dlna/DidlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,10 @@ public static final String getDidlString(StoreResource resource) {
if (defaultAudioTrack != null && mediaInfo.getDurationInSeconds() > 0.0 && transcodeFrequency > 0 &&
transcodeNumberOfChannels > 0) {
int finalSize = (int) (mediaInfo.getDurationInSeconds() * transcodeFrequency * 2 * transcodeNumberOfChannels);
LOGGER.trace("Calculated transcoded size for {}: {}", resource.getSystemName(), finalSize);
LOGGER.trace("Calculated transcoded size for {}: {}", resource.getFileName(), finalSize);
addAttribute(sb, "size", finalSize);
} else if (mediaInfo.getSize() > 0) {
LOGGER.trace("Could not calculate transcoded size for {}, using file size: {}", resource.getSystemName(),
LOGGER.trace("Could not calculate transcoded size for {}, using file size: {}", resource.getFileName(),
mediaInfo.getSize());
addAttribute(sb, "size", mediaInfo.getSize());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/pms/encoders/AviSynthFFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public boolean isCompatible(StoreItem resource) {
return false;
}
} catch (NullPointerException e) {
LOGGER.trace("AviSynth/FFmpeg cannot determine compatibility based on audio track for " + resource.getSystemName());
LOGGER.trace("AviSynth/FFmpeg cannot determine compatibility based on audio track for " + resource.getFileName());
} catch (IndexOutOfBoundsException e) {
LOGGER.trace("AviSynth/FFmpeg cannot determine compatibility based on default audio track for " + resource.getSystemName());
LOGGER.trace("AviSynth/FFmpeg cannot determine compatibility based on default audio track for " + resource.getFileName());
}

return PlayerUtil.isVideo(resource, Format.Identifier.MKV) ||
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/pms/encoders/AviSynthMEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public boolean isCompatible(StoreItem resource) {
return false;
}
} catch (NullPointerException e) {
LOGGER.trace("AviSynth/MEncoder cannot determine compatibility based on audio track for " + resource.getSystemName());
LOGGER.trace("AviSynth/MEncoder cannot determine compatibility based on audio track for " + resource.getFileName());
} catch (IndexOutOfBoundsException e) {
LOGGER.trace("AviSynth/MEncoder cannot determine compatibility based on default audio track for " + resource.getSystemName());
LOGGER.trace("AviSynth/MEncoder cannot determine compatibility based on default audio track for " + resource.getFileName());
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/pms/encoders/TsMuxeRVideo.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,9 @@ public boolean isCompatible(StoreItem resource) {
return false;
}
} catch (NullPointerException e) {
LOGGER.trace("tsMuxeR cannot determine compatibility based on audio track for " + resource.getSystemName());
LOGGER.trace("tsMuxeR cannot determine compatibility based on audio track for " + resource.getFileName());
} catch (IndexOutOfBoundsException e) {
LOGGER.trace("tsMuxeR cannot determine compatibility based on default audio track for " + resource.getSystemName());
LOGGER.trace("tsMuxeR cannot determine compatibility based on default audio track for " + resource.getFileName());
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ protected static List<SubtitleItem> findSubtitlesByName(
}
}
if (fileName == null) {
fileName = resource.getSystemName();
fileName = resource.getFileName();
}

Array queryArray = new Array();
Expand Down Expand Up @@ -1280,7 +1280,7 @@ protected static String guessImdbIdByFileName(StoreResource resource, String fil
}
fileName = file.getName();
} else {
fileName = resource.getSystemName();
fileName = resource.getFileName();
}
if (isBlank(fileName)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ public static final Item getItem(StoreItem item) {
if (defaultAudioTrack != null && mediaInfo.getDurationInSeconds() > 0.0 && transcodeFrequency > 0 &&
transcodeNumberOfChannels > 0) {
int finalSize = (int) (mediaInfo.getDurationInSeconds() * transcodeFrequency * 2 * transcodeNumberOfChannels);
LOGGER.trace("Calculated transcoded size for {}: {}", item.getSystemName(), finalSize);
LOGGER.trace("Calculated transcoded size for {}: {}", item.getFileName(), finalSize);
res.setSize(finalSize);
} else if (mediaInfo.getSize() > 0) {
LOGGER.trace("Could not calculate transcoded size for {}, using file size: {}", item.getSystemName(),
LOGGER.trace("Could not calculate transcoded size for {}, using file size: {}", item.getFileName(),
mediaInfo.getSize());
res.setSize(mediaInfo.getSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,8 @@ private static boolean sendMedia(HttpServletRequest req, HttpServletResponse res
}
if (item.getFormat().isVideo()) {
mimeType = renderer.getVideoMimeType();
if (FileUtil.isUrl(item.getSystemName())) {
if (FFmpegWebVideo.isYouTubeURL(item.getSystemName())) {
if (FileUtil.isUrl(item.getFileName())) {
if (FFmpegWebVideo.isYouTubeURL(item.getFileName())) {
item.setEngine(EngineFactory.getEngine(StandardEngineId.YOUTUBE_DL, false, false));
} else {
item.setEngine(EngineFactory.getEngine(StandardEngineId.FFMPEG_WEB_VIDEO, false, false));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/pms/store/StoreItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void setFormat(Format format) {
*/
protected void resolveFormat() {
if (format == null) {
format = FormatFactory.getAssociatedFormat(getSystemName());
format = FormatFactory.getAssociatedFormat(getFileName());
}

if (format != null && format.isUnknown()) {
Expand Down Expand Up @@ -631,7 +631,7 @@ public void startPlaying(final String rendererId) {
if (isLogPlayEvents()) {
LOGGER.info("Started playing {} ({}) on your {}", getName(), getEngineName(), rendererName);
LOGGER.debug(
"The full filename of which is: " + getSystemName() + " and the address of the renderer is: " + rendererId);
"The full filename of which is: " + getFileName() + " and the address of the renderer is: " + rendererId);
}
startTime = System.currentTimeMillis();
};
Expand Down Expand Up @@ -683,7 +683,7 @@ public void stopPlaying(final String rendererId) {

if (isLogPlayEvents()) {
LOGGER.info("Stopped playing {} on {}", getName(), rendererName);
LOGGER.debug("The full filename of which is \"{}\" and the address of the renderer is {}", getSystemName(),
LOGGER.debug("The full filename of which is \"{}\" and the address of the renderer is {}", getFileName(),
rendererId);
}
internalStop();
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/pms/store/item/RealFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,26 @@ public void resolveFormat() {
super.resolveFormat();
}

/**
* @return The path to the mediaInfo source.
*/
@Override
public String getSystemName() {
public String getFileName() {
return ProcessUtil.getShortFileNameIfWideChars(getFile().getAbsolutePath());
}

@Override
public String getSystemName() {
String filename = getFileName();
if (getMediaAudio() != null && getMediaAudio().getId() != 0) {
filename = filename.concat("_a").concat(String.valueOf(getMediaAudio().getId()));
}
if (getMediaSubtitle() != null && getMediaSubtitle().getId() != 0) {
filename = filename.concat("_s").concat(String.valueOf(getMediaSubtitle().getId()));
}
return filename;
}

@Override
public synchronized void resolve() {
if (file == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/pms/util/FileNamePrettifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public FileNamePrettifier(StoreResource resource) {
tmpName = realFile.getFile().getName();
}
if (isBlank(tmpName)) {
tmpName = resource.getSystemName();
tmpName = resource.getFileName();
}
if (isBlank(tmpName)) {
tmpName = resource.getName();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/pms/util/SubtitleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static File getSubtitles(
return convertedFile;
}

String filename = isEmbeddedSource ? resource.getSystemName() : params.getSid().getExternalFile().getAbsolutePath();
String filename = isEmbeddedSource ? resource.getFileName() : params.getSid().getExternalFile().getAbsolutePath();

String basename;

Expand Down

0 comments on commit f2ae475

Please sign in to comment.