123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- import axios from "axios";
- const pageNum = 20;
- function formatMusicItem(item) {
- return {
- id: item.id,
- title: item.title,
- artist:
- item?.allArtistNames ||
- item.artists?.map?.((s) => s.name).join(", ") ||
- item.user?.niceName,
- artwork: item?.headImg,
- urls: item?.fullClip?.urls,
- };
- }
- function formatArtistItem(item) {
- return {
- id: item.id,
- name: item.name,
- avatar: item.headImg,
- };
- }
- let lastQuery;
- let lastMusicId;
- async function searchMusic(query, page) {
- // 新的搜索
- if (query !== lastQuery || page === 1) {
- lastMusicId = 0;
- }
- lastQuery = query;
- let data = JSON.stringify({
- searchType: "MV",
- key: query,
- sinceId: lastMusicId,
- size: pageNum,
- requestTagRows: [
- {
- key: "sortType",
- chosenTags: ["HOTTEST"],
- },
- {
- key: "source",
- chosenTags: ["-1"],
- },
- {
- key: "duration",
- chosenTags: ["-1"],
- },
- ],
- });
- let config = {
- method: "post",
- maxBodyLength: Infinity,
- url: "https://search-api.yinyuetai.com/search/get_search_result.json",
- headers: {
- referrer: "https://www.yinyuetai.com/",
- accept: "application/json",
- "content-type": "application/json",
- wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
- },
- data: data,
- };
- const response = (await axios.request(config)).data.data;
- lastMusicId = response[response.length - 1].id;
- return {
- isEnd: pageNum > response.length,
- data: response.map(formatMusicItem),
- };
- }
- // async function searchArtist(query, page) {
- // let data = JSON.stringify({
- // searchType: "ARTIST",
- // key: query,
- // sinceId: 0,
- // size: 2 * pageNum,
- // });
- // let config = {
- // method: "post",
- // maxBodyLength: Infinity,
- // url: "https://search-api.yinyuetai.com/search/get_search_result.json",
- // headers: {
- // referrer: "https://www.yinyuetai.com/",
- // accept: "application/json",
- // "content-type": "application/json",
- // wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
- // },
- // data: data,
- // };
- // const response = (await axios.request(config)).data.data;
- // return {
- // isEnd: true,
- // data: response.map(formatArtistItem),
- // };
- // }
- async function search(query, page, type) {
- if (type === "music") {
- return await searchMusic(query, page);
- }
- // else if (type === "artist") {
- // return await searchArtist(query, page);
- // }
- }
- async function getMediaSource(musicItem, quality) {
- let url;
- if (quality === "standard") {
- url = musicItem.urls.find((it) => it.streamType === 5).url;
- } else if (quality === "high") {
- url = musicItem.urls.find((it) => it.streamType === 1).url;
- }
- return {
- url,
- };
- }
- // let lastArtistId;
- // let lastArtistSinceId = 0;
- // let cacheExtendId;
- // async function getArtistWorks(artistItem, page, type) {
- // if (type === "music") {
- // let sinceId =
- // page === 1 || artistItem.id !== lastArtistId ? 0 : lastArtistSinceId;
- // lastArtistId = artistItem.id;
- // if (sinceId === 0) {
- // const personBaseInfo = (
- // await axios.get("https://person-api.yinyuetai.com/person/getBase", {
- // params: {
- // id: artistItem.id,
- // },
- // headers: {
- // referrer: "https://www.yinyuetai.com/",
- // accept: "application/json",
- // "content-type": "application/json",
- // wua: "YYT/1.0.0 (WEB;web;11;zh-CN;kADiV2jNJFy2ryvuyB5Ne)",
- // },
- // })
- // ).data;
- // console.log(personBaseInfo)
- // cacheExtendId = personBaseInfo.extendId;
- // }
- // const medias = (
- // await axios.get("https://video-api.yinyuetai.com/video/listByArtist", {
- // params: {
- // artistId: cacheExtendId,
- // size: pageNum,
- // sinceId,
- // },
- // })
- // ).data.data;
- // lastArtistSinceId = medias[medias.length - 1].id;
- // return {
- // isEnd: medias.length < pageNum,
- // data: medias.map(formatMusicItem),
- // };
- // }
- // }
- module.exports = {
- platform: "音悦台",
- version: "0.0.0",
- supportedSearchType: ["music"],
- srcUrl:
- "https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/yinyuetai/index.js",
- cacheControl: "no-cache",
- search,
- getMediaSource,
- // getArtistWorks,
- };
|