extension(aniplay): Added preferred video resolution

This commit is contained in:
Swakshan
2025-01-14 22:44:40 +05:30
parent aaa7334f04
commit da79161249

View File

@@ -6,7 +6,7 @@ const mangayomiSources = [{
"iconUrl": "https://www.google.com/s2/favicons?sz=128&domain=https://aniplaynow.live/", "iconUrl": "https://www.google.com/s2/favicons?sz=128&domain=https://aniplaynow.live/",
"typeSource": "single", "typeSource": "single",
"itemType": 1, "itemType": 1,
"version": "0.0.5", "version": "0.0.6",
"dateFormat": "", "dateFormat": "",
"dateFormatLocale": "", "dateFormatLocale": "",
"pkgPath": "anime/src/en/aniplay.js" "pkgPath": "anime/src/en/aniplay.js"
@@ -342,6 +342,7 @@ class DefaultExtension extends MProvider {
delete ep.img delete ep.img
delete ep.title delete ep.title
delete ep.description delete ep.description
delete ep.isFiller
var epUrl = `${anilistId}||${JSON.stringify(ep)}||${choice.providerId}` var epUrl = `${anilistId}||${JSON.stringify(ep)}||${choice.providerId}`
chapters.push({ name, url: epUrl, dateUpload }) chapters.push({ name, url: epUrl, dateUpload })
} }
@@ -350,6 +351,27 @@ class DefaultExtension extends MProvider {
return animeData return animeData
} }
// Sorts streams based on user preference.
async sortStreams(streams) {
var sortedStreams = [];
var copyStreams = streams.slice()
var pref = await this.getPreference("aniplay_pref_video_resolution");
for (var stream of streams) {
if (stream.quality.indexOf(pref) > -1) {
sortedStreams.push(stream);
var index = copyStreams.indexOf(stream);
if (index > -1) {
copyStreams.splice(index, 1);
}
break;
}
}
return [...sortedStreams, ...copyStreams]
}
// Extracts the streams url for different resolutions from a hls stream. // Extracts the streams url for different resolutions from a hls stream.
async extractStreams(url, providerId) { async extractStreams(url, providerId) {
const response = await new Client().get(url); const response = await new Client().get(url);
@@ -430,7 +452,7 @@ class DefaultExtension extends MProvider {
streams = await this.getYukiStreams(result) streams = await this.getYukiStreams(result)
} }
return streams return await this.sortStreams(streams)
} }
// For manga chapter pages // For manga chapter pages
@@ -478,6 +500,15 @@ class DefaultExtension extends MProvider {
"entries": ["Sub", "Dub"], "entries": ["Sub", "Dub"],
"entryValues": ["sub", "dub"], "entryValues": ["sub", "dub"],
} }
}, {
key: 'aniplay_pref_video_resolution',
listPreference: {
title: 'Preferred video resolution',
summary: '',
valueIndex: 0,
entries: ["Auto", "1080p", "720p", "480p", "360p"],
entryValues: ["auto", "1080", "720", "480", "360"]
}
}, },
] ]