Skip to content

Commit

Permalink
Server: Add a lastaccess hint to the cached file.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Sep 23, 2023
1 parent eb43948 commit 58af857
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.ProcessBuilder.Redirect;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -149,6 +151,7 @@ public static TranscodeSession start(File targetFile, Media media, VideoQuality
return session;
}

@SneakyThrows
public static File getFile(Media media, VideoQuality desiredQuality, VideoCodec desiredVCodec, AudioCodec desiredACodec, ContainerFormat desiredContainer, int... streamIds) {
List<String> str_streamIds = new ArrayList<>(streamIds.length);
for (int streamId : streamIds) {
Expand All @@ -159,7 +162,7 @@ public static File getFile(Media media, VideoQuality desiredQuality, VideoCodec
codecs.add(desiredVCodec.name().toLowerCase());
codecs.add(desiredACodec.name().toLowerCase());

return new File(
File mediaFile = new File(
Athena.cacheDirectory,
String.format(
"%s.%s.%s.%s.%s",
Expand All @@ -170,6 +173,26 @@ public static File getFile(Media media, VideoQuality desiredQuality, VideoCodec
desiredContainer.name().toLowerCase()
)
);
File lastAccessedFile = new File(
Athena.cacheDirectory,
String.format(
"%s.%s.%s.%s.%s.lastaccess",
media.getId(),
desiredQuality.name().toLowerCase(),
String.join(",", codecs),
String.join(",", str_streamIds),
desiredContainer.name().toLowerCase()
)
);

// Write the last access time to disk, replacing any existing timestamp.
Files.write(
lastAccessedFile.toPath(),
String.valueOf(System.currentTimeMillis()).getBytes(),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
);

return mediaFile;
}

}

0 comments on commit 58af857

Please sign in to comment.