Skip to content

Commit

Permalink
Server: Quality/Codec/Format dropdowns.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Feb 26, 2024
1 parent da04cd8 commit 0df5d99
Showing 1 changed file with 71 additions and 31 deletions.
102 changes: 71 additions & 31 deletions server/src/main/java/xyz/e3ndr/athena/service/simple_ui/UIRoutes.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,65 @@ public HttpResponse onViewSpecificMedia(SoraHttpSession session) {
String directors = String.join(", ", media.getInfo().getDirectors().stream().map((p) -> p.getName()).collect(Collectors.toList()));
String actors = String.join(", ", media.getInfo().getActors().stream().limit(4).map((p) -> p.getName()).collect(Collectors.toList()));

ContainerFormat container = null;
VideoCodec vCodec = null;
AudioCodec aCodec = null;
VideoQuality quality = null;

String userAgent = session.getHeader("User-Agent");
if (userAgent.contains("Nintendo WiiU")) {
container = ContainerFormat.TS;
vCodec = VideoCodec.H264_BASELINE;
aCodec = AudioCodec.AAC;
quality = VideoQuality.FHD;
} else if (userAgent.contains("Windows Phone") || userAgent.contains("Trident/")) {
container = ContainerFormat.MP4;
vCodec = VideoCodec.H264_HIGH;
aCodec = AudioCodec.AAC;
quality = VideoQuality.FHD;
} else {
container = ContainerFormat.MKV;
vCodec = VideoCodec.SOURCE;
aCodec = AudioCodec.SOURCE;
quality = VideoQuality.UHD;
}

String containerOptions = "";
for (ContainerFormat e : ContainerFormat.values()) {
if (e == container) {
containerOptions += "<option selected>" + e + "</option>";
} else {
containerOptions += "<option>" + e + "</option>";
}
}

String vCodecOptions = "";
for (VideoCodec e : VideoCodec.values()) {
if (e == vCodec) {
vCodecOptions += "<option selected>" + e + "</option>";
} else {
vCodecOptions += "<option>" + e + "</option>";
}
}

String aCodecOptions = "";
for (AudioCodec e : AudioCodec.values()) {
if (e == aCodec) {
aCodecOptions += "<option selected>" + e + "</option>";
} else {
aCodecOptions += "<option>" + e + "</option>";
}
}

String qualityOptions = "";
for (VideoQuality e : VideoQuality.values()) {
if (e == quality) {
qualityOptions += "<option selected>" + e + "</option>";
} else {
qualityOptions += "<option>" + e + "</option>";
}
}

return new HTMLBuilder()
.f("<a href=\"/media\">Go back</a>")
.f("<br />")
Expand Down Expand Up @@ -444,7 +503,13 @@ public HttpResponse onViewSpecificMedia(SoraHttpSession session) {
.f(" </table>")
.f("")
.f(" <br />")
.f(" <a href=\"/media/%s/watch\">Watch</a>", media.getId())
.f(" <form action=\"./%s/watch\" method=\"GET\">", media.getId())
.f(" <select name=\"container\">" + containerOptions + "</select>")
.f(" <select name=\"vCodec\">" + vCodecOptions + "</select>")
.f(" <select name=\"aCodec\">" + aCodecOptions + "</select>")
.f(" <select name=\"quality\">" + qualityOptions + "</select>")
.f(" <button type=\"submit\">Watch</button>")
.f(" </form>")
.f(" </td>")
.f(" </tr>")
.f("</table>")
Expand All @@ -459,37 +524,12 @@ public HttpResponse onWatchSpecificMedia(SoraHttpSession session) {
return HttpResponse.newFixedLengthResponse(StandardHttpStatus.NOT_FOUND);
}

String videoUrl;

String userAgent = session.getHeader("User-Agent");
// if (userAgent.contains("Nintendo WiiU")) {
// VideoCodec vCodec = VideoCodec.H264_BASELINE;
// AudioCodec aCodec = AudioCodec.AAC;
// VideoQuality quality = VideoQuality.FHD;
//
// videoUrl = String.format(
// "/_internal/media/%s/stream/hls/media.m3u8?videoCodec=%s&audioCodec=%s&quality=%s",
// media.getId(), vCodec, aCodec, quality
// );
// } else {
ContainerFormat container = ContainerFormat.MKV;
VideoCodec vCodec = VideoCodec.H264_HIGH;
AudioCodec aCodec = AudioCodec.OPUS;
VideoQuality quality = VideoQuality.UHD;

if (userAgent.contains("Nintendo WiiU")) {
container = ContainerFormat.TS;
vCodec = VideoCodec.H264_BASELINE;
aCodec = AudioCodec.AAC;
quality = VideoQuality.FHD;
} else if (userAgent.contains("Windows Phone") || userAgent.contains("Trident/")) {
container = ContainerFormat.MP4;
vCodec = VideoCodec.H264_HIGH;
aCodec = AudioCodec.AAC;
quality = VideoQuality.FHD;
}
ContainerFormat container = ContainerFormat.valueOf(session.getQueryParameters().get("container"));
VideoCodec vCodec = VideoCodec.valueOf(session.getQueryParameters().get("vCodec"));
AudioCodec aCodec = AudioCodec.valueOf(session.getQueryParameters().get("aCodec"));
VideoQuality quality = VideoQuality.valueOf(session.getQueryParameters().get("quality"));

videoUrl = String.format(
String videoUrl = String.format(
"/_internal/media/%s/stream?format=%s&videoCodec=%s&audioCodec=%s&quality=%s",
media.getId(), container, vCodec, aCodec, quality
);
Expand Down

0 comments on commit 0df5d99

Please sign in to comment.