Skip to content

armgit / peach

Public Imported from GitHub
0

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

feat(web): 小窗里补上快退和快进

longmeidaob4e0f9c6ff7b
diff --git a/README.en.md b/README.en.md
index 4e1e7022e..c4f5ed94e 100644
--- a/README.en.md
+++ b/README.en.md
@@ -57,7 +57,7 @@ Follow sources include FANBOX, Patreon, SubscribeStar, Kemono, Pawchive, Coomer,
## Quick start
-Settings control whether local and followed videos play automatically when their details open, and whether a video that is still playing keeps going in a corner miniplayer when you leave its details. While the miniplayer is open, clicking another video plays it there; it can be dragged to any of the four corners and expanded back to the details from its title. The player context menu offers loop, miniplayer, picture-in-picture, copy video URL (optionally at the current time) and playback stats.
+Settings control whether local and followed videos play automatically when their details open, and whether a video that is still playing keeps going in a corner miniplayer when you leave its details. While the miniplayer is open, clicking another video plays it there; it can be dragged to any of the four corners and expanded back to the details from its title, and the play button is flanked by seek keys that jump by the configured number of seconds. The player context menu offers loop, miniplayer, picture-in-picture, copy video URL (optionally at the current time) and playback stats.
Portraits and brand marks allow moderate enlargement in large and compact views. Very small images use their native size with a blurred background. Display areas below 64 px retain the regular icon treatment.
diff --git a/README.md b/README.md
index 3c1b4ec1d..142dccbbe 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ CloudDrive · 115 与 CloudDrive · PikPak 按本机文件夹接入;先在 Clo
关注来源包括 FANBOX、Patreon、SubscribeStar,以及 Kemono、Pawchive、Coomer、Rule34 系列与 F95zone。来源可用性受站点和使用者权限限制;采集边界与支持情况见 [来源采集](docs/SOURCING.md)。
-右上角设置可控制打开本地作品和关注视频详情时是否自动播放,以及离开详情时正在播放的视频是否缩到角落的小窗继续播放。小窗开着时点击其他视频直接在小窗里换片,可拖到四个角、点击标题展开回详情;播放器右键菜单提供循环播放、迷你播放器、画中画、复制视频网址(含当前时间)和播放统计。
+右上角设置可控制打开本地作品和关注视频详情时是否自动播放,以及离开详情时正在播放的视频是否缩到角落的小窗继续播放。小窗开着时点击其他视频直接在小窗里换片,可拖到四个角、点击标题展开回详情,画面上的播放键两侧还有按设置秒数跳的快退和快进;播放器右键菜单提供循环播放、迷你播放器、画中画、复制视频网址(含当前时间)和播放统计。
首页包含尚无缩略图的视频;搜索推荐仅来自当前馆藏。空馆藏保留头像、厂牌与标签布局,并提供添加内容与来源的入口。
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index 16869550f..4fa1d0005 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -1226,13 +1226,14 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains(".vjs-layout-x-small .vjs-progress-control"
"{left:0;right:0;top:-12px;height:18px;display:flex}")
- def test_the_small_window_gets_its_own_seek_keys(self):
- """小窗(画中画)里只剩浏览器给的那几颗键,站内控制条一颗都递不进去。
+ def test_picture_in_picture_gets_its_own_seek_keys(self):
+ """画中画那个窗口由浏览器画,站内控制条一颗键都递不进去。
Media Session 的动作处理器是唯一的入口:登记 `seekbackward` 和 `seekforward`
- 之后小窗才画得出快退快进,步长取设置里那个秒数;`setPositionState` 让小窗自己
+ 之后那个窗口才画得出快退快进,步长取设置里那个秒数;`setPositionState` 让它自己
那条进度条知道放到哪,`seekto` 让拖它生效。逐个动作单独 try——整块 try 会让一个
- 浏览器不认识的动作带走后面全部处理器。
+ 浏览器不认识的动作带走后面全部处理器。站内的小窗是另一件事,见
+ `test_the_small_window_gets_its_own_seek_keys`。
"""
self.assertPageContains("function mountPlayerMediaSession(player,it){")
self.assertPageContains("mountPlayerMediaSession(detailPlayer,it);")
@@ -1246,7 +1247,7 @@ class WebUiSourceTests(unittest.TestCase):
"try{session.setActionHandler(action,handler);registered.push(action)}catch(_e){}",
"if(!duration||position>duration)return;"):
self.assertPageContains(needle)
- # 换一条视频就换一份处理器:不摘掉的话小窗还按着上一条的进度条走。
+ # 换一条视频就换一份处理器:不摘掉的话那个窗口还按着上一条的进度条走。
self.assertPageContains("registered.forEach(action=>{try{session.setActionHandler(action,null)}catch(_e){}});")
def test_settings_overlay_owns_the_top_fixed_layer(self):
@@ -3236,6 +3237,33 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("if((!stage||stage.hidden)&&miniplayerActive())return miniplayerVideo();")
self.assertPageContains("function toggleMiniplayerShortcut()")
+ def test_the_small_window_gets_its_own_seek_keys(self):
+ """小窗里播放键两侧各一颗快退快进,步长跟设置里那个秒数走。
+
+ 上游 YouTube 的小窗没有这两颗。Peach 自己要:小窗一开就离开了详情,站内那条控制条
+ 一颗键都递不进来,只剩底下那条 5px 的进度条能拖,想跳十秒得先回详情。标签里带着
+ 秒数,读屏用户按之前听得到自己会跳多远;接手播放器时重写一遍,设置改完开的下一个
+ 小窗就是新的秒数。时长取不到时不封顶——直播和还没读到元数据的片子 `duration()` 是
+ NaN,拿它去 `Math.min` 会把进度扔成 NaN,视频停在原地不动。
+ """
+ self.assertPageContains('<button type="button" class="miniplayerseek" id="miniplayerBack">'
+ '<svg viewBox="0 0 24 24" aria-hidden="true">'
+ '<use href="#i-rotate-ccw"/></svg></button>')
+ self.assertPageContains('<button type="button" class="miniplayerseek" id="miniplayerAhead">'
+ '<svg viewBox="0 0 24 24" aria-hidden="true">'
+ '<use href="#i-rotate-cw"/></svg></button>')
+ self.assertPageContains("function syncMiniplayerSeekLabels()")
+ self.assertPageContains("[['#miniplayerBack',`后退 ${step} 秒`],"
+ "['#miniplayerAhead',`前进 ${step} 秒`]]")
+ self.assertPageContains("const at=Math.max(0,(Number(player.currentTime())||0)+step*side);")
+ self.assertPageContains("player.currentTime(total?Math.min(total,at):at);")
+ self.assertPageContains("$('#miniplayerBack').onclick=seekBy(-1);")
+ self.assertPageContains("$('#miniplayerAhead').onclick=seekBy(1);")
+ # 按在这两颗上不能起手拖窗,否则一次点击变成一次挪位。
+ self.assertPageContains("event.target.closest('.miniplayerbtn,.miniplayerplay,"
+ ".miniplayerseek,.vjs-control-bar')")
+ self.assertPageContains(".miniplayerseek{width:36px;height:36px}")
+
def test_player_context_menu_lists_only_the_actions_peach_can_do(self):
"""播放器右键菜单照 YouTube f572e43c 的 .ytp-contextmenu 取舍,只留 Peach 有能力的项。
diff --git a/web/app.js b/web/app.js
index d54a89498..6720d2bff 100644
--- a/web/app.js
+++ b/web/app.js
@@ -961,12 +961,21 @@ function syncMiniplayerTime(){
const total=realDuration(miniplayerState.item?.duration)||realDuration(player.duration());
out.textContent=`${fmtClock(player.currentTime())} / ${total?fmtClock(total):'0:00'}`;
}
+/* 步长跟设置走,标签里带着这个数:读屏用户按之前听得到自己会跳多远。每次接手播放器
+ 时重写一遍,设置改完开的下一个小窗就是新的秒数。 */
+function syncMiniplayerSeekLabels(){
+ const step=Math.max(1,Number(appSettings.seekSeconds)||10);
+ for(const [id,text] of [['#miniplayerBack',`后退 ${step} 秒`],['#miniplayerAhead',`前进 ${step} 秒`]]){
+ const button=$(id);if(!button)continue;
+ button.setAttribute('aria-label',text);button.title=text;
+ }
+}
function bindMiniplayerPlayer(player){
const on=(events,handler)=>{player.on(events,handler);miniplayerState.off.push(()=>{try{player.off(events,handler)}catch(_e){}})};
on(['play','pause','ended'],syncMiniplayerPlayState);
on(['timeupdate','durationchange','loadedmetadata'],syncMiniplayerTime);
on('loadedmetadata',syncMiniplayerAspect);
- syncMiniplayerPlayState();syncMiniplayerTime();syncMiniplayerAspect();
+ syncMiniplayerPlayState();syncMiniplayerTime();syncMiniplayerAspect();syncMiniplayerSeekLabels();
}
function unbindMiniplayerPlayer(){miniplayerState.off.forEach(off=>off());miniplayerState.off=[]}
function enterMiniplayer(player,meta){
@@ -1092,9 +1101,22 @@ function wireMiniplayer(){
if(!player||player.isDisposed())return;
if(player.paused())player.play().catch(()=>{});else player.pause();
};
+ /* 时长取不到时不封顶:直播和还没读到元数据的片子 `duration()` 是 NaN,拿它去
+ `Math.min` 会把进度直接扔成 NaN,视频停在原地不动。 */
+ const seekBy=side=>event=>{
+ event.stopPropagation();const player=miniplayerState.player;
+ if(!player||player.isDisposed())return;
+ const step=Math.max(1,Number(appSettings.seekSeconds)||10);
+ const total=realDuration(player.duration())||realDuration(miniplayerState.item?.duration)||0;
+ const at=Math.max(0,(Number(player.currentTime())||0)+step*side);
+ player.currentTime(total?Math.min(total,at):at);
+ };
+ $('#miniplayerBack').onclick=seekBy(-1);
+ $('#miniplayerAhead').onclick=seekBy(1);
+ syncMiniplayerSeekLabels();
let drag=null;
card.addEventListener('pointerdown',event=>{
- if(event.button!==0||event.target.closest('.miniplayerbtn,.miniplayerplay,.vjs-control-bar'))return;
+ if(event.button!==0||event.target.closest('.miniplayerbtn,.miniplayerplay,.miniplayerseek,.vjs-control-bar'))return;
drag={id:event.pointerId,x:event.clientX,y:event.clientY,dx:0,dy:0,moved:false};
try{card.setPointerCapture(event.pointerId)}catch(_e){}
});
@@ -1779,11 +1801,11 @@ function mountPlayerSeekPreview(player,it,options={}){
}
/* Video.js 自带的转圈是 `:before`/`:after` 画的两条弧,换不掉曲线;YouTube e937390a
的 `FsY` 是四段嵌套元素配四段动画。转圈的 DOM 只能整块替换,样式表接不上手。 */
-/* 小窗(画中画)里只剩浏览器给的那几颗键,站内控制条一颗都递不进去。Media Session
- 的动作处理器是唯一的入口:登记 `seekbackward` 和 `seekforward` 之后,Chrome 会在小窗
- 里画出快退和快进两颗,步长用设置里那个秒数;`setPositionState` 让小窗自己那条进度条
- 知道现在放到哪,`seekto` 让拖它真的生效。不登记时小窗只有播放、暂停和关闭三颗。
- YouTube 的小窗没有这两颗,这里是本站自己要的。 */
+/* 画中画那个窗口由浏览器画,站内控制条一颗键都递不进去。Media Session 的动作处理器
+ 是唯一的入口:登记 `seekbackward` 和 `seekforward` 之后,Chrome 才在那个窗口里画出
+ 快退和快进两颗,步长用设置里那个秒数;`setPositionState` 让它自己那条进度条知道现在
+ 放到哪,`seekto` 让拖它真的生效。不登记时那里只有播放、暂停和关闭三颗。
+ 站内的小窗是另一件事,那三颗键在 `wireMiniplayer()` 里。 */
function mountPlayerMediaSession(player,it){
const session=navigator.mediaSession;
if(!session||typeof session.setActionHandler!=='function')return;
diff --git a/web/css/24-miniplayer.css b/web/css/24-miniplayer.css
index 1e2b6272e..dff0ac7ad 100644
--- a/web/css/24-miniplayer.css
+++ b/web/css/24-miniplayer.css
@@ -41,21 +41,26 @@
.miniplayerframe .video-js .vjs-time-tooltip{font-size:var(--fs-xs);font-family:inherit}
/* 悬停幕:上游 .ytp-miniplayer-scrim rgba(0,0,0,.5),.2s cubic-bezier(.4,0,.2,1) 延迟 .1s,
hover / focus-within 才显;关闭右上、展开左上各 40px,中央播放键 42px,时间左下。 */
-.miniplayerscrim{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.5);
+.miniplayerscrim{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;gap:6px;background:rgba(0,0,0,.5);
opacity:0;transition:opacity .2s cubic-bezier(.4,0,.2,1) .1s;color:#fff}
.miniplayerframe:hover .miniplayerscrim,.miniplayerframe:focus-within .miniplayerscrim,.miniplayer.miniplayer-dragging .miniplayerscrim{opacity:1}
-.miniplayerbtn,.miniplayerplay{position:relative;isolation:isolate;display:grid;place-items:center;margin:0;padding:0;border:0;background:transparent;color:#fff;cursor:pointer}
+.miniplayerbtn,.miniplayerplay,.miniplayerseek{position:relative;isolation:isolate;display:grid;place-items:center;margin:0;padding:0;border:0;background:transparent;color:#fff;cursor:pointer}
.miniplayerbtn{position:absolute;top:0;width:40px;height:40px}
.miniplayerbtn svg{position:relative;z-index:1;width:24px;height:24px;stroke:currentColor;fill:none;stroke-width:2;filter:drop-shadow(0 0 1px rgba(0,0,0,.8))}
.miniplayerexpand{left:0}
.miniplayerclose{right:0}
.miniplayerplay{width:42px;height:42px}
.miniplayerplay svg{position:relative;z-index:1;width:36px;height:36px;fill:currentColor;stroke:none;filter:drop-shadow(0 0 1px rgba(0,0,0,.8))}
+/* 快退和快进分列播放键两侧。上游 YouTube 的小窗没有这两颗,Peach 自己要:小窗一开就
+ 离开了详情,站内那条控制条一颗键都递不进来,只剩进度条能拖,想跳十秒得先回详情。
+ 36px 比中间那颗小一档,三颗并排读得出主次。 */
+.miniplayerseek{width:36px;height:36px}
+.miniplayerseek svg{position:relative;z-index:1;width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:2;filter:drop-shadow(0 0 1px rgba(0,0,0,.8))}
/* 悬停圈与详情页的关闭键、统计键同一套。 */
-.miniplayerbtn:after,.miniplayerplay:after{content:"";position:absolute;z-index:0;inset:4px;border-radius:50%;background:transparent;pointer-events:none;transition:background .2s cubic-bezier(.05,0,0,1)}
-.miniplayerbtn:hover:after,.miniplayerbtn:focus-visible:after,.miniplayerplay:hover:after,.miniplayerplay:focus-visible:after{background:rgba(255,255,255,.1)}
-.miniplayerbtn:active:after,.miniplayerplay:active:after{background:rgba(255,255,255,.2)}
-.miniplayerbtn:focus-visible,.miniplayerplay:focus-visible{outline:0}
+.miniplayerbtn:after,.miniplayerplay:after,.miniplayerseek:after{content:"";position:absolute;z-index:0;inset:4px;border-radius:50%;background:transparent;pointer-events:none;transition:background .2s cubic-bezier(.05,0,0,1)}
+.miniplayerbtn:hover:after,.miniplayerbtn:focus-visible:after,.miniplayerplay:hover:after,.miniplayerplay:focus-visible:after,.miniplayerseek:hover:after,.miniplayerseek:focus-visible:after{background:rgba(255,255,255,.1)}
+.miniplayerbtn:active:after,.miniplayerplay:active:after,.miniplayerseek:active:after{background:rgba(255,255,255,.2)}
+.miniplayerbtn:focus-visible,.miniplayerplay:focus-visible,.miniplayerseek:focus-visible{outline:0}
.miniplayertime{position:absolute;left:12px;bottom:16px;font-size:var(--fs-xs);line-height:15px;text-shadow:0 0 2px #000;pointer-events:none}
/* 信息栏:上游 76px,12px 16px 内边距;标题 14/20 500 单行省略,副标题 12/18 400、上距 4px。
整条是「展开到详情」的按钮,拖动从这里起手最顺,所以光标是 grab。 */
diff --git a/web/index.html b/web/index.html
index 79dcadfe5..e4bd150de 100644
--- a/web/index.html
+++ b/web/index.html
@@ -211,7 +211,9 @@
<div class="miniplayerscrim">
<button type="button" class="miniplayerbtn miniplayerexpand" id="miniplayerExpand" aria-label="展开到详情" aria-keyshortcuts="i"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-maximize-2"/></svg></button>
<button type="button" class="miniplayerbtn miniplayerclose" id="miniplayerClose" aria-label="关闭小窗"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-x"/></svg></button>
+ <button type="button" class="miniplayerseek" id="miniplayerBack"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-rotate-ccw"/></svg></button>
<button type="button" class="miniplayerplay" id="miniplayerPlay" aria-label="暂停" aria-keyshortcuts="k"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-player-pause"/></svg></button>
+ <button type="button" class="miniplayerseek" id="miniplayerAhead"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="#i-rotate-cw"/></svg></button>
<span class="miniplayertime mono" id="miniplayerTime">0:00 / 0:00</span>
</div>
</div>