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

有没有可能添加通过长度判断音源的功能? #372

Closed
ghost opened this issue Jan 23, 2020 · 7 comments
Closed

有没有可能添加通过长度判断音源的功能? #372

ghost opened this issue Jan 23, 2020 · 7 comments

Comments

@ghost
Copy link

ghost commented Jan 23, 2020

有时候碰到好多首歌都叫同一个名字,正好变灰的那首歌就被替换为了另一首同名的歌曲播放。
我想了一下,能不能在某些情况下通过歌曲的长度判断是不是找对了。
不过我没读过代码,不确定目前的实现方法能否添加这一功能。

@nondanee
Copy link
Owner

#180
目前 info 里就有 duration

@nondanee nondanee added the help wanted Extra attention is needed label Jan 23, 2020
@ghost
Copy link
Author

ghost commented Jan 24, 2020

我的想法是能不能挑前5个结果,然后判断这5个当中有没有时长相差5s之内的结果,如果没有就播放第一条,如果有就播放第一个符合长度相差5s之内的结果。是否可行?

nondanee added a commit that referenced this issue Feb 8, 2020
@nondanee
Copy link
Owner

nondanee commented Feb 8, 2020

255fd52 给除 youtube 外的提供平台都加了 formatter
(因为 youtube 是视频平台,没有专辑,歌手的说法,PV 一般也会是唱片公司发布,就没做)

用来格式化 歌名 / 歌手 / 专辑 / 时长 字段,方便比较
song.name, song.artists, song.album, song.duration

不过不是所有平台的搜索结果都有时长字段
JOOX、酷我、酷狗、QQ 有
咪咕、虾米、百度 没有

我个人的意见是做这个筛选意义不大,各个平台都会不断优化他们的搜索结果
一般来说第一条就是了
如果不是,那很大可能没这首歌
所以没有改动挑选逻辑 (取第一条)

module.exports = list => list[0]

如果你需要可以自己改 select.js

按照你的需求,代码实现如下

module.exports = (list, info) => {
	const {duration} = info
	const song = list
		.slice(0, 5) // 挑前5个结果
		.find(song => song.duration && Math.abs(song.duration - duration) < 5 * 1e3) // 第一个时长相差5s (5000ms) 之内的结果
	if (song)
		return song
	else
		return list[0] // 没有就播放第一条
}

@nondanee nondanee removed the help wanted Extra attention is needed label Feb 8, 2020
@ghost
Copy link
Author

ghost commented Feb 23, 2020

有道理!感谢回复!

@Dreamiva
Copy link

Dreamiva commented Mar 22, 2020

虾米

您好基于您的项目,写了一个PHP项目,https://music.yaode.xyz/query?id=72569,按照这里提供的思路,匹配歌曲歌手名,歌曲长度提高精度,咪咕时长字段没有找到,虾米是 .length 百度是 .duration,后续项目优化后开源,再次感谢

@nondanee
Copy link
Owner

@Dreamiva
你用的搜索 api 不一样吧?目前我用的是没有的

百度

'http://sug.qianqian.com/info/suggestion?' +
'word=' + encodeURIComponent(info.keyword) + '&version=2&from=0'

{
    "bitrate_fee": "{\"0\":\"129|-1\",\"1\":\"-1|-1\"}",
    "weight": "99",
    "songname": "发如雪",
    "resource_type": "0",
    "songid": "1147070",
    "has_mv": "0",
    "copy_type": 0,
    "yyr_artist": "0",
    "resource_type_ext": "0",
    "artistname": "周杰伦",
    "info": "",
    "resource_provider": "1",
    "control": "1100000000",
    "encrypted_songid": "56061180be0958414d02L"
}

虾米

'http://api.xiami.com/web?v=2.0&app_key=1' +
'&key=' + encodeURIComponent(info.keyword) + '&page=1' +
'&limit=20&callback=jsonp&r=search/songs'

{
    "song_id": 376037,
    "song_name": "发如雪",
    "album_id": 6643,
    "album_name": "十一月的萧邦",
    "album_logo": "http://pic.xiami.net/images/album/img1/376501/66431503376502.jpg",
    "artist_id": 1260,
    "artist_name": "周杰伦",
    "artist_logo": "http://pic.xiami.net/images/artistlogo/36/15162027033536.jpg",
    "listen_file": "",
    "demo": 0,
    "need_pay_flag": 0,
    "lyric": "http://img.xiami.net/lyric/37/376037_1505118871_3899.trc",
    "purview_roles": [
        {
            "quality": "s",
            "operation_list": [
                {
                    "purpose": 1,
                    "upgrade_role": 1
                },
                {
                    "purpose": 2,
                    "upgrade_role": 1
                }
            ]
        },
        {
            "quality": "h",
            "operation_list": [
                {
                    "purpose": 1,
                    "upgrade_role": 1
                },
                {
                    "purpose": 2,
                    "upgrade_role": 1
                }
            ]
        },
        {
            "quality": "l",
            "operation_list": [
                {
                    "purpose": 1,
                    "upgrade_role": 1
                },
                {
                    "purpose": 2,
                    "upgrade_role": 1
                }
            ]
        },
        {
            "quality": "f",
            "operation_list": [
                {
                    "purpose": 1,
                    "upgrade_role": 1
                },
                {
                    "purpose": 2,
                    "upgrade_role": 1
                }
            ]
        },
        {
            "quality": "e",
            "operation_list": [
                {
                    "purpose": 1,
                    "upgrade_role": 1
                },
                {
                    "purpose": 2,
                    "upgrade_role": 1
                }
            ]
        }
    ],
    "is_play": 0,
    "play_counts": 0,
    "singer": ""
}

有更好的 api 可以分享一下多谢

@Dreamiva
Copy link

Dreamiva commented Mar 24, 2020

百度可以直接访问 http://musicapi.taihe.com/v1/restserver/ting?from=qianqianmini&method=baidu.ting.search.merge&isNew=1&platform=darwin&page_no=1&query=十年&version=11.2.1&page_size=30

虾米需要令牌 你之前的源码里有获取方式 https://www.xiami.com/api/search/searchSongs?_q={"key":"十年","pagingVO":{"page":1,"pageSize":30}}&_s=a49cd68076141239fc48564b51dac29a

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

No branches or pull requests

2 participants