123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- function qianqian(packages) {
- const { axios, dayjs, CryptoJs } = packages;
- const pageSize = 20;
- const secret = '0b50b02fd0d73a9c4c8c3a781c30845f';
- function getSignedParams(e) {
- if ("[object Object]" !== Object.prototype.toString.call(e))
- throw new Error("The parameter of query must be a Object.");
- var t = Math.floor(Date.now() / 1e3);
- Object.assign(e, {
- timestamp: t
- });
- var n = Object.keys(e);
- n.sort();
- for (var r = "", i = 0; i < n.length; i++) {
- var s = n[i];
- r += (0 == i ? "" : "&") + s + "=" + e[s]
- }
- return {
- ...e,
- sign: CryptoJs.MD5(r += secret).toString(),
- timestamp: t
- }
- }
- 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',
- 'referer': 'https://music.91q.com/',
- 'from': 'web',
- 'accept': 'application/json, text/plain, */*',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9'
- };
- function formatMusicItem(_) {
- return {
- id: _.id || _.assetId,
- artwork: _.pic,
- title: _.title,
- artist: (_.artist || []).map(ar => ar.name).join('、'),
- artistItems: (_.artist || []).map(formatArtistItem),
- album: _.albumTitle,
- lrc: _.lyric
- }
- }
- function formatAlbumItem(_) {
- return {
- id: _.albumAssetCode,
- artist: (_.artist || []).map(ar => ar.name).join('、'),
- title: _.title,
- artwork: _.pic,
- description: '',
- date: dayjs(_.releaseDate).format('YYYY-MM-DD'),
- }
- }
- function formatArtistItem(_) {
- return {
- name: _.name,
- id: _.artistCode,
- avatar: _.pic,
- worksNum: _.trackTotal,
- description: _.introduce,
- }
- }
- function musicCanPlayFilter(_) {
- return !_.pay_model;
- }
- async function searchBase(query, page, type) {
- const res = (await axios.get('https://music.91q.com/v1/search', {
- headers: searchHeaders,
- params: getSignedParams({
- appid: '16073360',
- type,
- word: query,
- pageNo: page,
- pageSize
- })
- }));
- return res.data;
- }
- async function searchMusic(query, page) {
- const res = await searchBase(query, page, 1);
- return {
- isEnd: res.data.total <= page * pageSize,
- data: res.data.typeTrack.filter(musicCanPlayFilter).map(formatMusicItem)
- }
- }
- async function searchAlbum(query, page) {
- const res = await searchBase(query, page, 3);
- return {
- isEnd: res.data.total <= page * pageSize,
- data: res.data.typeAlbum.map(formatAlbumItem)
- }
- }
- async function searchArtist(query, page) {
- const res = await searchBase(query, page, 2);
- return {
- isEnd: res.data.total <= page * pageSize,
- data: res.data.typeArtist.map(formatArtistItem)
- }
- }
- async function getArtistMusicWorks(artistItem, page) {
- const headers = {
- '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',
- 'referer': `https://music.91q.com/search?word=${encodeURIComponent(artistItem.name)}`,
- 'from': 'web',
- 'accept': 'application/json, text/plain, */*',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9'
- };
- const res = (await axios.get('https://music.91q.com/v1/artist/song', {
- headers,
- params: getSignedParams({
- appid: '16073360',
- artistCode: artistItem.id,
- pageNo: page,
- pageSize
- })
- })).data;
- return {
- isEnd: res.data.total <= page * pageSize,
- data: res.data.result.filter(musicCanPlayFilter).map(formatMusicItem)
- }
- }
- async function getArtistAlbumWorks(artistItem, page) {
- const headers = {
- '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',
- 'referer': `https://music.91q.com/search?word=${encodeURIComponent(artistItem.name)}`,
- 'from': 'web',
- 'accept': 'application/json, text/plain, */*',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9'
- };
- const res = (await axios.get('https://music.91q.com/v1/artist/album', {
- headers,
- params: getSignedParams({
- appid: '16073360',
- artistCode: artistItem.id,
- pageNo: page,
- pageSize
- })
- })).data;
- return {
- isEnd: res.data.total <= page * pageSize,
- data: res.data.result.map(formatAlbumItem)
- }
- }
- async function getArtistWorks(artistItem, page, type) {
- if (type === 'music') {
- return getArtistMusicWorks(artistItem, page);
- } else if (type === 'album') {
- return getArtistAlbumWorks(artistItem, page);
- }
- }
- async function getLyric(musicItem) {
- return {
- lrc: musicItem.lrc
- }
- }
- async function getAlbumInfo(albumItem) {
- if (albumItem.musicList) {
- return albumItem;
- } else {
- const headers = {
- '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',
- 'referer': `https://music.91q.com/search?word=${encodeURIComponent(albumItem.name)}`,
- 'from': 'web',
- 'accept': 'application/json, text/plain, */*',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9'
- };
- const res = (await axios.get('https://music.91q.com/v1/album/info', {
- headers,
- params: getSignedParams({
- appid: '16073360',
- albumAssetCode: albumItem.id,
- })
- }));
- const musicList = (res.data.data.trackList || []).filter(musicCanPlayFilter).map(_ => ({
- ...formatMusicItem(_),
- artwork: albumItem.artwork,
- album: albumItem.name
- }))
- return {
- ...albumItem,
- musicList
- }
- }
- }
- return {
- platform: '千千音乐',
- version: '0.0.0',
- srcUrl: 'https://gitee.com/maotoumao/MusicFreePlugins/raw/master/qianqian.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 = {
- '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',
- 'referer': `https://music.91q.com/artist/${(musicItem.artistItems[0] || {}).id}`,
- 'from': 'webapp_music',
- 'accept': 'application/json, text/plain, */*',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'zh-CN,zh;q=0.9'
- }
- const res = (await axios.get('https://music.91q.com/v1/song/tracklink', {
- headers,
- params: getSignedParams({
- appid: '16073360',
- TSID: musicItem.id,
- })
- })).data;
- return {
- url: res.data.path
- };
- },
- getAlbumInfo,
- getLyric,
- getArtistWorks
- }
- }
|