123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- function fiveSing(packages) {
- const { axios, cheerio } = packages;
- const pageSize = 10;
- function formatMusicItem(_) {
- return {
- id: _.songId,
- title: cheerio.load(_.songName).text(),
- artist: _.singer,
- singerId: _.singerId,
- album: _.typeName,
- type: _.type,
- typeName: _.typeName,
- typeEname: _.typeEname
- }
- }
- function formatAlbumItem(_) {
- return {
- id: _.songListId,
- artist: _.userName,
- title: cheerio.load(_.title).text(),
- artwork: _.pictureUrl,
- description: _.content,
- date: _.createTime,
- }
- }
- function formatArtistItem(_) {
- return ({
- id: _.id,
- name: cheerio.load(_.nickName).text(),
- fans: _.fans,
- avatar: _.pictureUrl,
- description: _.description,
- worksNum: _.totalSong
- })
- }
- const searchHeaders = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Host': 'search.5sing.kugou.com',
- 'Accept': 'application/json, text/javascript, */*; q=0.01',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'zh-CN,zh;q=0.9',
- 'Referer': 'http://search.5sing.kugou.com/home/index'
- }
- async function searchMusic(query, page) {
- const res = (await axios.get('http://search.5sing.kugou.com/home/json', {
- headers: searchHeaders,
- params: {
- keyword: query,
- sort: 1,
- page,
- filter: 0,
- type: 0,
- }
- })).data;
- const songs = res.list.map(formatMusicItem);
- return {
- isEnd: res.pageInfo.cur >= res.pageInfo.totalPages,
- data: songs
- }
- }
- async function searchAlbum(query, page) {
- const res = (await axios.get('http://search.5sing.kugou.com/home/json', {
- headers: searchHeaders,
- params: {
- keyword: query,
- sort: 1,
- page,
- filter: 0,
- type: 1,
- }
- })).data;
- const songs = res.list.map(formatAlbumItem);
- return {
- isEnd: res.pageInfo.cur >= res.pageInfo.totalPages,
- data: songs
- }
- }
- async function searchArtist(query, page) {
- const res = (await axios.get('http://search.5sing.kugou.com/home/json', {
- headers: searchHeaders,
- params: {
- keyword: query,
- sort: 1,
- page,
- filter: 1,
- type: 2,
- }
- })).data;
- const songs = res.list.map(formatArtistItem);
- return {
- isEnd: res.pageInfo.cur >= res.pageInfo.totalPages,
- data: songs
- }
- }
- let fcEnd = false;
- let ycEnd = false;
- let bzEnd = false;
- async function getArtistMusicWorks(artistItem, page) {
- if(page === 1) {
- fcEnd = false;
- ycEnd = false;
- bzEnd = false;
- }
- const headers = {
- 'Accept': 'application/json, text/plain, */*',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'zh-CN,zh;q=0.9',
- 'Cache-Control': 'no-cache',
- 'Connection': 'keep-alive',
- 'Host': 'service.5sing.kugou.com',
- 'Origin': 'http://5sing.kugou.com',
- 'Pragma': 'no-cache',
- 'Referer': 'http://5sing.kugou.com/',
- 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
- }
- let data = [];
- if(!fcEnd) {
- const res = (await (axios.get('http://service.5sing.kugou.com/user/songlist', {
- headers,
- params: {
- userId: artistItem.id,
- type: 'fc',
- pageSize,
- page
- }
- }))).data;
- if(res.count <= page * pageSize) {
- fcEnd = true;
- }
- data = data.concat(res.data.map(_ => ({
- id: _.songId,
- artist: artistItem.name,
- title: _.songName,
- typeEname: 'fc',
- typeName: '翻唱',
- type: _.songType,
- album: '翻唱'
- })))
- }
- if(!ycEnd) {
- const res = (await (axios.get('http://service.5sing.kugou.com/user/songlist', {
- headers,
- params: {
- userId: artistItem.id,
- type: 'yc',
- pageSize,
- page
- }
- }))).data;
- if(res.count <= page * pageSize) {
- ycEnd = true;
- }
- data = data.concat(res.data.map(_ => ({
- id: _.songId,
- artist: artistItem.name,
- title: _.songName,
- typeEname: 'yc',
- typeName: '原唱',
- type: _.songType,
- album: '原唱'
- })));
- }
- if(!bzEnd) {
- const res = (await (axios.get('http://service.5sing.kugou.com/user/songlist', {
- headers,
- params: {
- userId: artistItem.id,
- type: 'bz',
- pageSize,
- page
- }
- }))).data;
- if(res.count <= page * pageSize) {
- bzEnd = true;
- }
- data = data.concat(res.data.map(_ => ({
- id: _.songId,
- artist: artistItem.name,
- title: _.songName,
- typeEname: 'bz',
- typeName: '伴奏',
- type: _.songType,
- album: '伴奏'
- })));
- }
- return {
- isEnd: fcEnd && ycEnd && bzEnd,
- data
- }
- }
- async function getArtistWorks(artistItem, page, type) {
- if (type === 'music') {
- return getArtistMusicWorks(artistItem, page);
- }
- }
- async function getLyric(musicItem) {
- const headers = {
- 'Accept': '*/*',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'zh-CN,zh;q=0.9',
- 'Host': 'service.5sing.kugou.com',
- 'Referer': 'http://5sing.kugou.com/',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
- };
- const res = (await axios.get('http://5sing.kugou.com/fm/m/json/lrc', {
- headers,
- params: {
- songId: musicItem.id,
- songType: musicItem.typeEname
- }
- })).data;
- return {
- rawLrc: res.txt
- }
- }
- async function getAlbumInfo(albumItem) {
- const headers = {
- 'Accept': 'application/json, text/plain, */*',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'zh-CN,zh;q=0.9',
- 'Cache-Control': 'no-cache',
- 'Host': 'service.5sing.kugou.com',
- 'Origin': 'http://5sing.kugou.com',
- 'Referer': 'http://5sing.kugou.com/',
- 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
- }
- const res = (await axios.get('http://service.5sing.kugou.com/song/getPlayListSong', {
- headers: headers,
- params: {
- id: albumItem.id,
- }
- })).data;
- return {
- ...albumItem,
- musicList: res.data.map(_ => ({
- id: _.ID,
- typeEname: _.SK,
- title: _.SN,
- artist: _.user.NN,
- singerId: _.user.ID,
- album: albumItem.title,
- artwork: albumItem.artwork,
- }))
- }
- }
- return {
- platform: '5sing',
- version: '0.0.0',
- srcUrl: 'https://gitee.com/maotoumao/MusicFreePlugins/raw/master/5sing.js',
- cacheControl: 'no-cache',
- async search(query, page, type) {
- if (type === 'music') {
- return await searchMusic(query, page);
- }
- if (type === 'album') {
- return await searchAlbum(query, page);
- }
- if (type === 'artist') {
- return await searchArtist(query, page);
- }
- },
- async getMediaSource(musicItem) {
- const headers = {
- 'Accept': '*/*',
- 'Accept-Encoding': 'gzip, deflate',
- 'Accept-Language': 'zh-CN,zh;q=0.9',
- 'Host': 'service.5sing.kugou.com',
- 'Referer': 'http://5sing.kugou.com/',
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
- };
- const res = (await axios.get('http://service.5sing.kugou.com/song/getsongurl', {
- headers,
- params: {
- songid: musicItem.id,
- songtype: musicItem.typeEname,
- from: 'web',
- version: '6.6.72',
- _: Date.now()
- }
- })).data;
- const data = JSON.parse(res.substring(1, res.length - 1)).data;
- return {
- url: data.hqurl || data.lqurl || data.squrl
- };
- },
- getAlbumInfo,
- getLyric,
- getArtistWorks
- }
- }
|