Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide xesam:asText in MPRIS #202

Closed
1 task done
Cryolitia opened this issue Oct 13, 2023 · 17 comments · Fixed by #207
Closed
1 task done

Provide xesam:asText in MPRIS #202

Cryolitia opened this issue Oct 13, 2023 · 17 comments · Fixed by #207
Labels
enhancement New feature or request

Comments

@Cryolitia
Copy link

Cryolitia commented Oct 13, 2023

Check for existing issues

检查是否已存在相同issue

  • Completed/已检查

Describe the feature

描述你的新功能

There's a filed in MPRIS v2 metadata guidelines that called xesam:asText, which could provide the track lyrics.

@Cryolitia
Copy link
Author

这个实现是不是不太对劲……我的理解是当前一句的歌词而不是完整的歌词,不然歌词显示器就完全没办法做了……

@anhoder
Copy link
Member

anhoder commented Nov 11, 2023

我倒觉得应该推送这首歌的原始歌词内容(包含每句歌词的时间信息),而不是解析后的纯歌词文本

显示方可以进行解析,然后根据时间定位显示某句歌词

@anhoder anhoder reopened this Nov 11, 2023
@Cryolitia
Copy link
Author

我几乎没有在互联网上找到这个字段更详细的说明,并不反对推送包含时间信息的完整歌词的做法(尽管并没有任何标准规范时间信息应以何种方式传递),或许我们可以考虑使用自定义字段例如 musicfox:currentLyric 传递当前歌词同时使用 xesam:asText 传递完整歌词。

@imxyy1soope1
Copy link
Contributor

可以的,主要是因为文档里也没有详细的描述,就安装自己理解做了

可以在xesam:asText字段提供接口返回的原始歌词(带时间戳),配合播放位置就可以获取当前歌词了,也基本不需要额外的实现。

imxyy1soope1 added a commit to imxyy1soope1/go-musicfox that referenced this issue Dec 9, 2023
@imxyy1soope1
Copy link
Contributor

@Cryolitia 请查看#216

@Cryolitia
Copy link
Author

@Cryolitia 请查看#216

我的建议是在 xesam:asText 放仅当前一句的歌词,在 musicfox:fullText 中放完整的歌词,这样比较能兼容大部分一句歌词的实现(因为显然更不存在同时读取歌词和时间戳再计算当前歌词的实现和格式规范)

或是至少在 musicfox:currentText 中提供当前仅一句歌词以简化例如状态栏歌词等仅需一句的显示器的实现。

@imxyy1soope1
Copy link
Contributor

按照文档的描述:

xesam:asText
String: The track lyrics.

应该是在 xesam:asText 提供完整的歌词, 在 musicfox:lineLyric 提供单行歌词会更合适

@imxyy1soope1
Copy link
Contributor

不是很行,更新 musicfox:currentText 需要更新整个metadata,性能损耗比较大,会导致画面闪烁

@anhoder
Copy link
Member

anhoder commented Dec 9, 2023

不应该使用单行歌词进行更新,太频繁了,应该只在播放器发生状态变更时才进行更新。

另外歌词文件都是有标准格式的,不同语言也有对应的解析器实现

@imxyy1soope1
Copy link
Contributor

imxyy1soope1 commented Dec 9, 2023

import pylrc
import time
import subprocess


fmt = "playerctl --player=musicfox metadata --format '{}'"
getoutput = lambda x: subprocess.getoutput(fmt.format(f"{{{{{x}}}}}"))

def search(t, lrc) -> str:
    for i in range(len(lrc)):
        if lrc[i].time > t:
            return lrc[i-1].text
    return lrc[-1].text

lrc = ""
trackid = ""
subs = None
longest = 0

def updatelrc():
    global lrc, trackid, subs, longest
    nid = getoutput("mpris:trackid")
    if nid != trackid:
        lrc = getoutput("xesam:asText")
        trackid = getoutput("mpris:trackid")
        subs = pylrc.parse(lrc)
        longest = max(map(lambda x: len(x.text.encode()), subs))

updatelrc()

while True:
    updatelrc()
    t = int(getoutput("position")) / 1e6

    line = search(t, subs)
    print(line + (longest - len(line.encode())) * " ", end="\r")

    time.sleep(0.1)

可以参考这个程序
(需要先用pip安装pylrc)

@Cryolitia
Copy link
Author

@Cryolitia
Copy link
Author

I don't know if we could add a property musicfox: currentText in MediaPlayer2.Player , so that we could update it standalone just like mpris:Position
https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html

@anhoder
Copy link
Member

anhoder commented Dec 12, 2023

我觉得现在的SetPosition更新机制也是不太对的,不应该每200ms更新一次,SetPosition应该只是用来seek之后定位使用
image

远程的position需要mpris client自己维护一个timer,Player应该只是在开始播放、暂停、seek跳转等发生状态变更的操作之后才将当前状态(包括position)同步给mpris(这个逻辑应该和Mac的MPNowPlayingInfoCenter是一致的)

@imxyy1soope1
Copy link
Contributor

其实SetPosition是一个接口,更新position的实现是修改position property
IMG_20231212_192319

@anhoder
Copy link
Member

anhoder commented Dec 12, 2023

按mpris文档里,position是只读的,是不是意味着这个调用没什么作用

@imxyy1soope1
Copy link
Contributor

并不是,这种方式是能够正常更新position的

anhoder pushed a commit that referenced this issue May 12, 2024
@anhoder
Copy link
Member

anhoder commented May 12, 2024

Implemented in v4.4.0

@anhoder anhoder closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants