Skip to content

Commit

Permalink
feat(AttrList): standard
Browse files Browse the repository at this point in the history
Update AttrList.mjs
  • Loading branch information
VirgilClyne committed Dec 19, 2024
1 parent 14031df commit f44ce31
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/class/AttrList.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import aPath from "../function/aPath.mjs";
export default class AttrList {
constructor(format = "application/x-mpegURL", platform = "Universal") {
this.Name = "AttrList";
this.Version = "1.0.6";
this.Version = "1.0.7";
this.format = format;
this.platform = platform;
//Object.assign(this, options)
Expand All @@ -30,13 +30,13 @@ export default class AttrList {
case "application/x-mpegurl":
case "application/vnd.apple.mpegurl":
case "audio/mpegurl": {
let attrList = file
const attrList = file
.filter(item => item?.TAG === "#EXT-X-MEDIA") // 过滤标签
.filter(item => item?.OPTION?.TYPE === type) // 过滤类型
.filter(item => item?.OPTION?.FORCED !== "YES"); // 过滤强制内容
//Console.debug(`attrList: ${JSON.stringify(attrList)}`);
//查询是否有符合语言的内容
for (let langcode of langCodes) {
for (const langcode of langCodes) {
Console.debug(`for (let ${langcode} of langcodes)`);
matchList = attrList.filter(item => item?.OPTION?.LANGUAGE?.toLowerCase() === langcode?.toLowerCase());
if (matchList.length !== 0) break;
Expand All @@ -51,9 +51,9 @@ export default class AttrList {
case "application/json": {
switch (this.platform) {
case "PrimeVideo": {
let attrList = file?.[type] ?? [];
const attrList = file?.[type] ?? [];
//查询是否有符合语言的内容
for (let langcode of langCodes) {
for (const langcode of langCodes) {
Console.debug(`for (let ${langcode} of langcodes)`);
matchList = attrList.filter(item => item?.languageCode?.toLowerCase() === langcode?.toLowerCase());
if (matchList.length !== 0) break;
Expand Down Expand Up @@ -84,8 +84,9 @@ export default class AttrList {
* @return {Object} m3u8
*/
set(file = [], playlists = {}, types = [], languages = [], standard = true, device = "iPhone") {
//types = (standard == true) ? types : ["Translate"];
types = standard == true ? types : [types.at(-1)];
//types = standard === true ? types : ["Translate"];
//types = standard === true ? types : [types.at(-1)];
types = standard === true ? types : types.reverse(); // 反转数组,先找翻译字幕,后找官方字幕
const playlists1 = playlists?.[languages?.[0]];
const playlists2 = playlists?.[languages?.[1]];
//if (playlists1?.length !== 0) Console.debug(`有主字幕语言(源语言)字幕`);
Expand All @@ -109,11 +110,10 @@ export default class AttrList {
playlists2?.forEach(playlist2 => {
//const index2 = file.findIndex(item => item?.OPTION?.URI === playlist2.OPTION.URI); // 副语言(源语言)字幕位置
if (playlist1?.OPTION?.["GROUP-ID"] === playlist2?.OPTION?.["GROUP-ID"]) {
switch (
this.platform // 兼容性修正
) {
// 兼容性修正
switch (this.platform) {
case "Apple":
if (playlist1?.OPTION.CHARACTERISTICS == playlist2?.OPTION.CHARACTERISTICS) {
if (playlist1?.OPTION.CHARACTERISTICS === playlist2?.OPTION.CHARACTERISTICS) {
// 只生成属性相同
option = setOption(playlist1, playlist2, type, this.platform, standard, device);
// option.OPTION.URI += `&lang=${languages[0]}`;
Expand All @@ -128,7 +128,7 @@ export default class AttrList {
});
break;
case "Translate":
case "External":
case "External": {
const playlist2 = {
OPTION: {
TYPE: "SUBTITLES",
Expand All @@ -141,6 +141,7 @@ export default class AttrList {
option = setOption(playlist1, playlist2, type, this.platform, standard, device);
option.OPTION.URI += `&lang=${playlist1?.OPTION?.LANGUAGE?.toUpperCase()}`;
break;
}
}
if (option) file.splice(index1 + (standard ? 1 : 0), 0, option);
});
Expand Down Expand Up @@ -172,7 +173,7 @@ export default class AttrList {
});
break;
case "Translate":
case "External":
case "External": {
option = JSON.parse(JSON.stringify(playlist1));
option.displayName = `${type} (${playlist1.displayName}/${languages[1]})`;
option.languageCode = `${playlist1.languageCode}/${languages[1].toLowerCase()}_${type}`;
Expand All @@ -182,6 +183,7 @@ export default class AttrList {
option.url += `&lang=${playlist1.languageCode.toUpperCase()}`;
//Console.debug(`option: ${JSON.stringify(option)}`);
break;
}
}
if (option) file.splice(index1 + (standard ? 1 : 0), 0, option);
});
Expand Down

0 comments on commit f44ce31

Please sign in to comment.