Skip to content

feat(plugin): MPRIS 媒体控制插件 — 支持分P、合集、单视频及封面同步精简版#6

Open
Copilot wants to merge 3 commits into
copilot/fix-mpris-video-infofrom
copilot/sub-pr-5
Open

feat(plugin): MPRIS 媒体控制插件 — 支持分P、合集、单视频及封面同步精简版#6
Copilot wants to merge 3 commits into
copilot/fix-mpris-video-infofrom
copilot/sub-pr-5

Conversation

Copy link
Copy Markdown

Copilot AI commented May 11, 2026

新增两个插件:完整 MPRIS 集成(video.mpris)及仅同步封面的精简版(video.mpris-cover)。同时扩展 VideoInfo API 以暴露 ugc_season 数据。

src/components/video/video-info.ts

  • 新增 UgcSeasonEpisodeInfo / UgcSeasonSectionInfo / UgcSeasonInfo 接口
  • VideoInfo 新增 ugcSeason?: UgcSeasonInfo 字段,从 data.ugc_season 提取,无额外网络请求

registry/lib/plugins/video/mpris (video.mpris)

完整 MPRIS 集成:

  • 元数据:标题(多P附分P名)、UP主(artist)、封面(artwork)
  • 进度setPositionState 含 duration / position / playbackRate,每 5s 刷新,play / pause / ratechange 即时触发
  • 控制:play / pause / seekforward / seekbackward(±10s)/ seekto via playerAgent
  • 上/下一曲(分P 与合集不互斥):
    previoustrack: 上一P → 合集上一集
    nexttrack:     下一P → 合集下一集 → 播放器内置 next 按钮(不存在或 disabled 则不注册)
    
  • videoChange 时自动刷新所有 metadata 与 handler,切换前清理事件监听与定时器

registry/lib/plugins/video/mpris-cover (video.mpris-cover)

精简版,仅在每次视频切换时将 navigator.mediaSession.metadata.artwork 替换为当前视频封面;不含播放控制、进度同步或导航逻辑。

// 若已有 metadata,仅更新 artwork;否则创建最小 MediaMetadata
if (ms.metadata) {
  ms.metadata.artwork = artwork
} else {
  ms.metadata = new MediaMetadata({ artwork })
}

修复:快速切换视频时的竞争条件

引入递增的 requestId 计数器,防止快速切换视频时早期 fetchInfo() 响应在较新请求之后返回并覆盖当前封面。每次 videoChange 回调在 await 后校验 currentId === requestId,若不一致则丢弃过期结果。

…ly syncs video cover artwork

Agent-Logs-Url: https://github.com/BlockG-ws/b23-evolved/sessions/e1791125-b6e5-42e1-869c-7d92440d8e43

Co-authored-by: GrassBlock1 <46253950+GrassBlock1@users.noreply.github.com>
Copilot AI changed the title [WIP] Add MPRIS media control plugin for Bilibili videos feat(plugin): MPRIS 媒体控制插件 — 支持分P、合集、单视频及封面同步精简版 May 11, 2026
Copilot AI requested a review from GrassBlock1 May 11, 2026 13:32
@GrassBlock1 GrassBlock1 marked this pull request as ready for review May 11, 2026 13:41
Copilot AI review requested due to automatic review settings May 11, 2026 13:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new video plugin that syncs the system Media Session (MPRIS) artwork to the current Bilibili video cover on each video switch.

Changes:

  • Add video.mpris-cover plugin to update navigator.mediaSession.metadata.artwork when videoChange fires.
  • Fetch VideoInfo on each video change to obtain the current video’s cover URL and apply it to Media Session metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +37
videoChange(async ({ aid }) => {
let info: VideoInfo
try {
info = await new VideoInfo(String(aid)).fetchInfo()
} catch {
return
}

if (!info.coverUrl) {
return
}

const artwork: MediaImage[] = [{ src: info.coverUrl, sizes: COVER_SIZES, type: COVER_TYPE }]

if (ms.metadata) {
ms.metadata.artwork = artwork
} else {
ms.metadata = new MediaMetadata({ artwork })
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fa3b64a. Added a requestId counter in the setup() closure. Each videoChange callback invocation increments it and captures its own currentId. After await, if currentId !== requestId the response is from a superseded request and is discarded.

Comment on lines +8 to +12
export const plugin: PluginMetadata = {
name: 'video.mpris-cover',
displayName: 'MPRIS 封面同步',
description: `将系统媒体控制(MPRIS)的专辑封面替换为当前正在播放的 Bilibili 视频封面。`,
setup: () => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants