Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

feat(web): 进度条按时间点显示画面,设置里选采集密度

longmeidao3cc90859fa39
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index fda56feef..5e3b4a91e 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -3691,7 +3691,7 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("const nextCell=Math.min(8,Math.floor(ratio*9))")
self.assertPageContains("image.src=`/poster?id=${encodeURIComponent(it.id)}&c=${nextCell}`")
self.assertPageContains("mountPlayerSeekPreview(detailPlayer,it,{thumbnail:!options.source})")
- self.assertPageContains(".vjs-peach-seek-preview img{width:240px;aspect-ratio:16/9")
+ self.assertPageContains(".vjs-peach-seek-frame{position:relative;width:240px;aspect-ratio:16/9")
def test_the_player_has_exactly_one_center_feedback_circle(self):
"""画面中心只有 `.vjs-peach-bezel` 这一块 78px 提示圆。
@@ -7764,6 +7764,38 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("document.dispatchEvent(new CustomEvent('peachambientchange'")
self.assertPageContains(".settingrow .gselect{min-width:148px}")
+ def test_the_thumbnail_density_is_this_machines_state_not_this_browsers(self):
+ """档位跟着服务端走。跑的是这台机器上的一条长任务,从另一台设备打开设置要看到
+ 的是它正在按什么密度采集,所以这一行既不进 `appSettings` 也不进 localStorage。
+ """
+ self.assertPageContains('id="videoThumbnailSetting"')
+ self.assertPageContains('id="videoThumbnailState" aria-live="polite"')
+ self.assertPageLacks("appSettings.videoThumbnailMode")
+ self.assertPageContains("['videoThumbnailSetting','视频缩略图采集',"
+ "[['off','关闭'],['precise','精准'],['coarse','粗略']],")
+ self.assertPageContains("()=>'off',value=>saveVideoThumbnailMode(value)]")
+ self.assertPageContains("const status=await api('/api/thumbnail-jobs');")
+ self.assertPageContains("api('/api/thumbnail-jobs',{method:'POST',body:JSON.stringify({mode})})")
+ self.assertPageContains("if(status.status==='running')void watchVideoThumbnailJob(request)")
+ # 采集只覆盖本机磁盘上的片子,网盘上的每张都要回源拉一次。这一条是功能范围,
+ # 说明里必须写出来,否则页面上「视频缩略图采集」读起来是全库。
+ self.assertPageContains("只采集本机磁盘上的片子")
+
+ def test_the_seek_preview_prefers_frames_that_match_where_the_pointer_is(self):
+ """指到哪一秒就看到哪一秒。九宫格那九格是全片九等分,两小时的片子格与格之间
+ 隔着十几分钟,指的位置和看到的画面对不上;采集任务铺好了时间轴图就改用它,
+ 没铺到的退回九宫格。
+ """
+ self.assertPageContains("api(`/api/timeline?id=${encodeURIComponent(it.id)}`)")
+ self.assertPageContains("if(meta&&meta.frames>0&&meta.interval>0)sheets=meta")
+ self.assertPageContains("if(sheets){showSheetFrame(duration*ratio);return}")
+ self.assertPageContains("const index=Math.min(sheets.frames-1,"
+ "Math.max(0,Math.floor(seconds/sheets.interval)))")
+ self.assertPageContains("const sheet=Math.floor(index/per),slot=index%per")
+ # 末张通常不满 10 行,行数按它自己剩下那几帧反算;按满行铺会把格子挪到图外面。
+ self.assertPageContains("const rows=Math.ceil(Math.min(per,sheets.frames-sheet*per)/columns)")
+ self.assertPageContains("image.src=`/poster?id=${encodeURIComponent(it.id)}&c=${nextCell}`")
+
def test_theme_is_a_three_way_choice_that_defaults_to_the_system(self):
"""主题三档:跟随系统、浅色、深色。
diff --git a/web/app.js b/web/app.js
index 2987c13d8..e78ad4ee5 100644
--- a/web/app.js
+++ b/web/app.js
@@ -577,6 +577,11 @@ const SETTING_SELECTS=[
['seekSecondsSetting','快进 / 快退',[['5','5 秒'],['10','10 秒'],['30','30 秒']],
()=>appSettings.seekSeconds,
value=>{appSettings.seekSeconds=+value||10;saveSettings()}],
+ /* 档位跟着这台机器走(/api/thumbnail-jobs),不存在本地:跑的是这台机器上的一条
+ 长任务,从另一台设备打开设置要看到的是它正在按什么密度采,不是那台设备上次选的。
+ 初值写 off,真值由 `loadVideoThumbnailSetting` 读回来填。 */
+ ['videoThumbnailSetting','视频缩略图采集',[['off','关闭'],['precise','精准'],['coarse','粗略']],
+ ()=>'off',value=>saveVideoThumbnailMode(value)],
['relatedLimitSetting','相关推荐',[['12','12 个'],['20','20 个'],['30','30 个']],
()=>appSettings.relatedLimit,
value=>{appSettings.relatedLimit=+value;saveSettings()}],
@@ -623,6 +628,7 @@ function syncSettingsPanel(){
renderJavImageSetting();
renderSidebarOrderSetting();
loadFollowScheduleSetting();
+ void loadVideoThumbnailSetting();
}
let settingsReturnFocus=null,settingsTransition=0;
function openSettings(open=true){
@@ -698,6 +704,64 @@ async function saveFollowSchedule(minutes){
}catch(error){state.textContent=error.message||'保存失败'}
finally{const status=followScheduleStatus;syncNumberSetting($('#followScheduleSetting'),status?(status.enabled?status.interval_minutes:0):null,status?!status.available:false)}
}
+/* 视频缩略图采集。档位和进度都在服务端,这一整段只负责把它读回来画在设置行上;
+ 同一个 `videoThumbnailRequest` 兼作过期判据,面板关掉或又点了一次就丢弃在途的那一轮。 */
+let videoThumbnailRequest=0;
+function videoThumbnailField(){return $('#videoThumbnailSetting .gselect')}
+function videoThumbnailCopy(status){
+ const counts=`${status.done||0} / ${status.total||0} 部 · 新生成 ${status.made||0} · 已有 ${status.skipped||0} · 未取得 ${status.failed||0}`;
+ if(status.status==='running')return `正在采集:${counts}`;
+ if(status.status==='failed')return `采集停在 ${counts}:${status.stopped||'原因未取得'}`;
+ if(status.status==='complete')return status.stopped?`已按停:${counts}`:`采集完成:${counts}`;
+ return status.mode==='off'
+ ?'关闭时不采集;已经生成的图留在盘上,清理走数据管理页。'
+ :'选定档位后从最近看过的片子开始采集。';
+}
+function applyVideoThumbnailStatus(status){
+ const field=videoThumbnailField(),state=$('#videoThumbnailState');
+ if(field){field.disabled=false;field.value=status.mode||'off'}
+ if(state)state.textContent=videoThumbnailCopy(status);
+}
+async function watchVideoThumbnailJob(request){
+ const ui=await import('/dist/peach-ui.js');
+ await ui.watchJob({
+ active:()=>request===videoThumbnailRequest&&!$('#settingsPanel').hidden,
+ read:signal=>api('/api/thumbnail-jobs',{signal}),
+ render:status=>applyVideoThumbnailStatus(status),
+ disconnected:()=>{const state=$('#videoThumbnailState');if(state)state.textContent='状态未取得,正在重试…'}});
+}
+async function loadVideoThumbnailSetting(){
+ const state=$('#videoThumbnailState');if(!state)return;
+ const request=++videoThumbnailRequest,field=videoThumbnailField();
+ if(field)field.disabled=true;
+ state.innerHTML=loadingDotsHtml('正在读取状态');
+ try{
+ const status=await api('/api/thumbnail-jobs');
+ if(request!==videoThumbnailRequest)return;
+ applyVideoThumbnailStatus(status);
+ if(status.status==='running')void watchVideoThumbnailJob(request);
+ }catch(error){
+ if(request!==videoThumbnailRequest)return;
+ if(field)field.disabled=false;
+ state.textContent=`状态未取得:${error.message||error}`;
+ }
+}
+async function saveVideoThumbnailMode(mode){
+ const state=$('#videoThumbnailState'),field=videoThumbnailField();
+ const request=++videoThumbnailRequest;
+ if(field)field.disabled=true;
+ if(state)state.innerHTML=`${spinnerHtml('保存中')}<span>正在保存…</span>`;
+ try{
+ const status=await api('/api/thumbnail-jobs',{method:'POST',body:JSON.stringify({mode})});
+ if(request!==videoThumbnailRequest)return;
+ applyVideoThumbnailStatus(status);
+ if(status.status==='running')void watchVideoThumbnailJob(request);
+ }catch(error){
+ if(request!==videoThumbnailRequest)return;
+ if(field)field.disabled=false;
+ if(state)state.textContent=error.message||'保存失败';
+ }
+}
/* 来源图标:品牌使用已缓存的官方资产;通用操作图标统一使用本地 Lucide 子集。
115 与 PikPak 都取 `MEDIA_SOURCE_ICONS` 里那份官方站标(取证
follow-source-icons-measured.md):来源角标、媒体库切换器和配置页问的是同一件事
@@ -1930,9 +1994,31 @@ function mountPlayerSeekPreview(player,it,options={}){
const hasThumbnail=options.thumbnail!==false;
const preview=document.createElement('div');
preview.className='vjs-peach-seek-preview';preview.dataset.playerSeekPreview='';preview.hidden=true;
- preview.innerHTML=`${hasThumbnail?'<img alt="" hidden>':''}<span class="mono">0:00</span>`;
+ preview.innerHTML=`${hasThumbnail?'<i class="vjs-peach-seek-frame" hidden><img alt=""></i>':''}<span class="mono">0:00</span>`;
progress.append(preview);
+ const frame=preview.querySelector('.vjs-peach-seek-frame');
const image=preview.querySelector('img'),label=preview.querySelector('span');
+ /* 采集任务铺好了时间轴接触印相就按它走:每 10 或 30 秒一帧,指到哪一秒看到的就是
+ 那一秒。取不到退回九宫格那九格——那是全片九等分,两小时的片子格与格之间隔着
+ 十几分钟,指的位置和看到的画面对不上,但比没有画面强。 */
+ let sheets=null,shown='';
+ if(frame&&it.id)api(`/api/timeline?id=${encodeURIComponent(it.id)}`)
+ .then(meta=>{if(meta&&meta.frames>0&&meta.interval>0)sheets=meta}).catch(()=>{});
+ const showSheetFrame=seconds=>{
+ const columns=sheets.columns||10,per=columns*(sheets.rows||10);
+ const index=Math.min(sheets.frames-1,Math.max(0,Math.floor(seconds/sheets.interval)));
+ const sheet=Math.floor(index/per),slot=index%per;
+ // 末张通常不满 10 行,行数按它自己那几帧反算:按满行去铺,格子会落到图外面的空白上。
+ const rows=Math.ceil(Math.min(per,sheets.frames-sheet*per)/columns);
+ const source=`/timeline?id=${encodeURIComponent(it.id)}&s=${sheet}`;
+ if(source!==shown){shown=source;image.src=source}
+ frame.hidden=false;
+ // 取景框按片源比例,图按格子铺满:两边比例一致,`fill` 才既不裁也不拉。
+ if(it.width&&it.height)frame.style.aspectRatio=`${it.width} / ${it.height}`;
+ image.style.objectFit='fill';
+ image.style.width=`${columns*100}%`;image.style.height=`${rows*100}%`;
+ image.style.left=`${-(slot%columns)*100}%`;image.style.top=`${-Math.floor(slot/columns)*100}%`;
+ };
let cell=-1;
const move=event=>{
if(event.pointerType==='touch')return;
@@ -1940,16 +2026,18 @@ function mountPlayerSeekPreview(player,it,options={}){
if(!duration)return;
const rect=progress.getBoundingClientRect();
const ratio=Math.min(1,Math.max(0,(event.clientX-rect.left)/rect.width));
- const width=image?Math.min(240,Math.max(160,rect.width*.28)):76;
+ const width=frame?Math.min(240,Math.max(160,rect.width*.28)):76;
const x=Math.min(rect.width-width/2,Math.max(width/2,event.clientX-rect.left));
preview.style.left=`${x}px`;preview.hidden=false;label.textContent=fmtClock(duration*ratio);
- if(image){
- const nextCell=Math.min(8,Math.floor(ratio*9));
- if(nextCell!==cell){cell=nextCell;image.hidden=false;image.src=`/poster?id=${encodeURIComponent(it.id)}&c=${nextCell}`}
- }
+ if(!frame)return;
+ if(sheets){showSheetFrame(duration*ratio);return}
+ const nextCell=Math.min(8,Math.floor(ratio*9));
+ if(nextCell===cell)return;
+ cell=nextCell;frame.hidden=false;image.removeAttribute('style');
+ image.src=`/poster?id=${encodeURIComponent(it.id)}&c=${nextCell}`;
};
const hide=()=>{preview.hidden=true};
- if(image)image.onerror=()=>{image.hidden=true};
+ if(image)image.onerror=()=>{frame.hidden=true};
progress.addEventListener('pointermove',move);progress.addEventListener('pointerleave',hide);
player.on('dispose',()=>{progress.removeEventListener('pointermove',move);progress.removeEventListener('pointerleave',hide)});
}
diff --git a/web/css/14-player.css b/web/css/14-player.css
index 1bbf4103a..220102298 100644
--- a/web/css/14-player.css
+++ b/web/css/14-player.css
@@ -163,9 +163,12 @@
.vjs-peach-seek-preview{position:absolute;z-index:4;bottom:calc(100% - 2px);transform:translateX(-50%);
display:flex;flex-direction:column;align-items:center;pointer-events:none;color:#fff}
.vjs-peach-seek-preview[hidden]{display:none}
-.vjs-peach-seek-preview img{width:240px;aspect-ratio:16/9;display:block;object-fit:cover;border:2px solid #fff;
- border-radius:var(--floating-radius);background:#000;box-shadow:0 8px 24px #0009}
-.vjs-peach-seek-preview img[hidden]{display:none}
+/* 取景框自己裁,图在里面挪。时间轴预览取回来的是一张 10×10 的接触印相,要看的那一格
+ 靠把图放大十倍再往左上推整格数得到;边框和圆角画在框上,图挪动时不跟着走。 */
+.vjs-peach-seek-frame{position:relative;width:240px;aspect-ratio:16/9;display:block;overflow:hidden;
+ border:2px solid #fff;border-radius:var(--floating-radius);background:#000;box-shadow:0 8px 24px #0009}
+.vjs-peach-seek-frame[hidden]{display:none}
+.vjs-peach-seek-preview img{position:absolute;left:0;top:0;width:100%;height:100%;display:block;object-fit:cover}
.vjs-peach-seek-preview span{min-width:58px;margin-top:8px;padding:6px 10px;border-radius:var(--pill-radius);
background:rgba(0,0,0,.68);font-size:var(--fs-sm);font-weight:600;line-height:1;text-align:center;box-shadow:0 2px 8px #0006}
.vwrap .video-js .vjs-custom-control-spacer{display:block;flex:1 1 auto}
@@ -307,7 +310,7 @@
.vwrap .video-js.vjs-layout-small .vjs-current-time,.vwrap .video-js.vjs-layout-small .vjs-duration,
.vwrap .video-js.vjs-layout-small .vjs-time-divider{display:flex}
.vwrap .video-js .vjs-time-control{font-size:var(--fs-xs)}
- .vjs-peach-seek-preview img{width:160px}
+ .vjs-peach-seek-frame{width:160px}
.vjs-peach-settings-menu{right:-100px;width:min(274px,calc(100vw - 16px));border-radius:var(--floating-radius)}
}
/* 窄屏梯度照搬 YouTube delhi-modern:base.js 9470c977 里 `v.width<528` 打开 ytp-xsmall-width-mode,
diff --git a/web/index.html b/web/index.html
index 31ad8bd1d..ed58de27d 100644
--- a/web/index.html
+++ b/web/index.html
@@ -287,6 +287,7 @@
<label class="settingrow"><span><b>打开详情自动播放</b><small id="detailAutoplayDescription">打开本地作品或关注视频详情时开始播放;关闭后点击播放按钮开始。</small></span><input class="ptoggle" type="checkbox" id="detailAutoplaySetting" role="switch" aria-describedby="detailAutoplayDescription"></label>
<label class="settingrow"><span><b>小窗播放</b><small id="miniplayerDescription">离开详情时正在播放的视频缩到角落继续播放;小窗开着时点击其他视频直接在小窗里换片。</small></span><input type="checkbox" id="miniplayerSetting" class="ptoggle" role="switch" aria-describedby="miniplayerDescription"></label>
<div class="settingrow"><span><b>快进 / 快退</b><small>卡片预览和详情播放器共用。</small></span><div id="seekSecondsSetting"></div></div>
+ <div class="settingrow"><span><b>视频缩略图采集</b><small>拖动进度条时按时间点看画面。精准每 10 秒一张,粗略每 30 秒一张;两小时的片子约 720 / 240 张,占 20–100 / 7–35 MB。只采集本机磁盘上的片子,网盘上的每张都要回源拉一次。</small><small id="videoThumbnailState" aria-live="polite">读取运行状态…</small></span><div id="videoThumbnailSetting"></div></div>
<div class="settingrow"><span><b>相关推荐</b><small>详情下方一次显示的相似作品数量。</small></span><div id="relatedLimitSetting"></div></div>
</section>
<section class="settinggroup"><h3>搜索</h3>