观看直播会记录播放记录

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
+41
View File
@@ -15,6 +15,7 @@ import {
generateStorageKey, generateStorageKey,
isFavorited as checkIsFavorited, isFavorited as checkIsFavorited,
saveFavorite, saveFavorite,
savePlayRecord,
subscribeToDataUpdates, subscribeToDataUpdates,
} from '@/lib/db.client'; } from '@/lib/db.client';
import { parseCustomTimeFormat } from '@/lib/time'; import { parseCustomTimeFormat } from '@/lib/time';
@@ -425,6 +426,25 @@ function LivePageClient() {
// 异步获取初始频道的节目单(不阻塞页面加载) // 异步获取初始频道的节目单(不阻塞页面加载)
if (selectedChannel) { if (selectedChannel) {
fetchEpgData(selectedChannel, source); 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) { if (currentSource) {
await fetchEpgData(channel, 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);
}
}
}; };
// 滚动到指定频道位置的函数 // 滚动到指定频道位置的函数
+1
View File
@@ -144,6 +144,7 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) {
) )
} }
type={record.total_episodes > 1 ? 'tv' : ''} type={record.total_episodes > 1 ? 'tv' : ''}
origin={record.origin}
/> />
</div> </div>
); );
+1
View File
@@ -40,6 +40,7 @@ export interface PlayRecord {
total_time: number; // 总进度(秒) total_time: number; // 总进度(秒)
save_time: number; // 记录保存时间(时间戳) save_time: number; // 记录保存时间(时间戳)
search_title?: string; // 搜索时使用的标题 search_title?: string; // 搜索时使用的标题
origin?: 'vod' | 'live'; // 来源类型
} }
// ---- 收藏类型 ---- // ---- 收藏类型 ----