fix: 黄豆按站点方式保持登录并自动切换播放线路
This commit is contained in:
+3
-62
@@ -100,7 +100,6 @@ const ACCOUNTS_KEY = "rapt-accounts";
|
||||
const PLATFORM_KEY = "rapt-platform";
|
||||
const DRAMABOX_LANG_KEY = "dramabox-language";
|
||||
const HUANGDOU_HOST_KEY = "huangdou-host";
|
||||
const HUANGDOU_LINE_KEY = "huangdou-line";
|
||||
const HUANGDOU_ACCOUNTS_KEY = "huangdou-accounts";
|
||||
const HUANGDOU_REMEMBER_KEY = "huangdou-remember";
|
||||
const DRAMABOX_DEVICE_KEY = "dramabox-device";
|
||||
@@ -130,9 +129,6 @@ const platformLabel = computed(() => {
|
||||
});
|
||||
const dramaboxLang = ref("th");
|
||||
const huangdouHost = ref(readHuangdouHost());
|
||||
const huangdouLine = ref(readHuangdouLine());
|
||||
const huangdouLines = ref<{ name: string; label: string }[]>([]);
|
||||
const huangdouLinesBusy = ref(false);
|
||||
const huangdouUser = ref("");
|
||||
const huangdouPassword = ref("");
|
||||
const huangdouRemember = ref(readHuangdouRemember());
|
||||
@@ -267,14 +263,6 @@ function readHuangdouRemember() {
|
||||
}
|
||||
}
|
||||
|
||||
function readHuangdouLine() {
|
||||
try {
|
||||
return localStorage.getItem(HUANGDOU_LINE_KEY) || "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function readHuangdouHost() {
|
||||
try {
|
||||
const value = localStorage.getItem(HUANGDOU_HOST_KEY) || "";
|
||||
@@ -304,41 +292,7 @@ function selectPlatform(key: string) {
|
||||
void loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
if (key === "huangdou") {
|
||||
void sendHuangdouFingerprint();
|
||||
void loadHuangdouLines();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadHuangdouLines() {
|
||||
huangdouLinesBusy.value = true;
|
||||
try {
|
||||
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
|
||||
const response = await fetch("/api/huangdou/lines", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ host }),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "没有读到线路");
|
||||
}
|
||||
const rows = Array.isArray(payload.lines) ? payload.lines : [];
|
||||
huangdouLines.value = rows
|
||||
.map((item: { name?: string; label?: string }) => ({
|
||||
name: String(item?.name || "").trim(),
|
||||
label: String(item?.label || item?.name || "").trim(),
|
||||
}))
|
||||
.filter((item: { name: string }) => item.name);
|
||||
if (!huangdouLines.value.some((item) => item.name === huangdouLine.value)) {
|
||||
huangdouLine.value = huangdouLines.value[0]?.name || "";
|
||||
}
|
||||
} catch (exc) {
|
||||
huangdouLines.value = [];
|
||||
error.value = exc instanceof Error ? exc.message : "没有读到线路";
|
||||
} finally {
|
||||
huangdouLinesBusy.value = false;
|
||||
}
|
||||
if (key === "huangdou") void sendHuangdouFingerprint();
|
||||
}
|
||||
|
||||
function tokenKey() {
|
||||
@@ -1062,13 +1016,11 @@ async function loginHuangdou(asGuest = false) {
|
||||
const host = huangdouHost.value.trim() || "https://pmihlvee.cc";
|
||||
huangdouHost.value = host;
|
||||
localStorage.setItem(HUANGDOU_HOST_KEY, host);
|
||||
localStorage.setItem(HUANGDOU_LINE_KEY, huangdouLine.value);
|
||||
const response = await fetch("/api/huangdou/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
host,
|
||||
line: huangdouLine.value,
|
||||
username: asGuest ? "" : huangdouUser.value.trim(),
|
||||
password: asGuest ? "" : huangdouPassword.value,
|
||||
}),
|
||||
@@ -1363,10 +1315,7 @@ onMounted(async () => {
|
||||
await loadDramaboxLanguages();
|
||||
void loadDevices();
|
||||
}
|
||||
if (platform.value === "huangdou") {
|
||||
void sendHuangdouFingerprint();
|
||||
void loadHuangdouLines();
|
||||
}
|
||||
if (platform.value === "huangdou") void sendHuangdouFingerprint();
|
||||
let saved = readSavedToken();
|
||||
if (!saved && isolated.value) {
|
||||
try {
|
||||
@@ -1584,15 +1533,7 @@ onUnmounted(stopLive);
|
||||
<n-form label-placement="left" label-width="96" size="small" :show-feedback="false" @submit.prevent="login">
|
||||
<template v-if="platform === 'huangdou'">
|
||||
<n-form-item label="域名">
|
||||
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" @blur="loadHuangdouLines" />
|
||||
</n-form-item>
|
||||
<n-form-item label="线路">
|
||||
<n-select
|
||||
v-model:value="huangdouLine"
|
||||
:options="huangdouLines.map((item) => ({ label: item.label, value: item.name }))"
|
||||
:loading="huangdouLinesBusy"
|
||||
placeholder="选择线路"
|
||||
/>
|
||||
<n-input v-model:value="huangdouHost" placeholder="https://pmihlvee.cc" />
|
||||
</n-form-item>
|
||||
<n-form-item v-if="huangdouAccounts.length" label="已保存">
|
||||
<div class="device-line">
|
||||
|
||||
@@ -7,9 +7,11 @@ interface Episode {
|
||||
title: string;
|
||||
playable: boolean;
|
||||
points?: number;
|
||||
type?: string;
|
||||
media?: string;
|
||||
locked_reason?: string;
|
||||
is_preview?: boolean;
|
||||
lines?: number;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -68,10 +70,10 @@ function select(episode: Episode) {
|
||||
if (!episode.playable || episode.cid === current.value) return;
|
||||
current.value = episode.cid;
|
||||
error.value = "";
|
||||
void nextTick(() => attach(episode.cid));
|
||||
void nextTick(() => attach(episode.cid, 0));
|
||||
}
|
||||
|
||||
function attach(cid: number) {
|
||||
function attach(cid: number, line = 0) {
|
||||
const video = videoRef.value;
|
||||
if (!video) return;
|
||||
stop();
|
||||
@@ -81,17 +83,28 @@ function attach(cid: number) {
|
||||
video.play().catch(() => undefined);
|
||||
return;
|
||||
}
|
||||
const url = `${apiBase.value}/play/${props.dramaId}/${cid}/index.m3u8`;
|
||||
const url = `${apiBase.value}/play/${props.dramaId}/${cid}/index.m3u8?line=${line}`;
|
||||
if (Hls.isSupported()) {
|
||||
const player = new Hls();
|
||||
hls = player;
|
||||
let advancing = false;
|
||||
player.loadSource(url);
|
||||
player.attachMedia(video);
|
||||
player.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
if (error.value === "正在切换线路") error.value = "";
|
||||
video.play().catch(() => undefined);
|
||||
});
|
||||
player.on(Hls.Events.ERROR, (_event, data) => {
|
||||
if (data.fatal) error.value = "这一集播放失败";
|
||||
if (!data.fatal || advancing) return;
|
||||
const status = data.response?.code;
|
||||
const known = episode?.lines || 0;
|
||||
if (status === 404 || line >= 5 || (known > 0 && line + 1 >= known)) {
|
||||
error.value = "这一集播放失败";
|
||||
return;
|
||||
}
|
||||
advancing = true;
|
||||
error.value = "正在切换线路";
|
||||
window.setTimeout(() => attach(cid, line + 1), 0);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -134,8 +147,10 @@ onUnmounted(stop);
|
||||
@click="select(episode)"
|
||||
>
|
||||
<span class="play-episode-title">{{ episode.title }}</span>
|
||||
<span v-if="!episode.playable" class="play-episode-lock">{{ episodeNote(episode) }}</span>
|
||||
<span v-if="episode.type?.toLowerCase() === 'vip'" class="play-episode-lock">会员</span>
|
||||
<span v-else-if="!episode.playable" class="play-episode-lock">{{ episodeNote(episode) }}</span>
|
||||
<span v-else-if="episode.is_preview" class="play-episode-lock">试看</span>
|
||||
<span v-if="episode.type?.toLowerCase() === 'vip' && !episode.playable && episode.locked_reason" class="play-episode-lock">{{ episodeNote(episode) }}</span>
|
||||
</button>
|
||||
<div v-if="!loading && episodes.length === 0" class="play-empty">没有分集</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user