观看直播会记录播放记录

This commit is contained in:
mtvpls
2025-12-18 00:01:31 +08:00
parent 3156b3449d
commit 96f9b094e4
3 changed files with 43 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ import {
generateStorageKey,
isFavorited as checkIsFavorited,
saveFavorite,
savePlayRecord,
subscribeToDataUpdates,
} from '@/lib/db.client';
import { parseCustomTimeFormat } from '@/lib/time';
@@ -425,6 +426,25 @@ function LivePageClient() {
// 异步获取初始频道的节目单(不阻塞页面加载)
if (selectedChannel) {
fetchEpgData(selectedChannel, source);
// 保存播放记录
try {
await savePlayRecord(`live_${source.key}`, `live_${selectedChannel.id}`, {
title: selectedChannel.name,
source_name: source.name,
year: '',
cover: `/api/proxy/logo?url=${encodeURIComponent(selectedChannel.logo)}&source=${source.key}`,
index: 1,
total_episodes: 1,
play_time: 0,
total_time: 0,
save_time: Date.now(),
search_title: '',
origin: 'live',
});
} catch (err) {
console.error('保存播放记录失败:', err);
}
}
}
@@ -570,6 +590,27 @@ function LivePageClient() {
if (currentSource) {
await fetchEpgData(channel, currentSource);
}
// 保存播放记录
if (currentSource) {
try {
await savePlayRecord(`live_${currentSource.key}`, `live_${channel.id}`, {
title: channel.name,
source_name: currentSource.name,
year: '',
cover: `/api/proxy/logo?url=${encodeURIComponent(channel.logo)}&source=${currentSource.key}`,
index: 1,
total_episodes: 1,
play_time: 0,
total_time: 0,
save_time: Date.now(),
search_title: '',
origin: 'live',
});
} catch (err) {
console.error('保存播放记录失败:', err);
}
}
};
// 滚动到指定频道位置的函数

View File

@@ -144,6 +144,7 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) {
)
}
type={record.total_episodes > 1 ? 'tv' : ''}
origin={record.origin}
/>
</div>
);

View File

@@ -40,6 +40,7 @@ export interface PlayRecord {
total_time: number; // 总进度(秒)
save_time: number; // 记录保存时间(时间戳)
search_title?: string; // 搜索时使用的标题
origin?: 'vod' | 'live'; // 来源类型
}
// ---- 收藏类型 ----