index.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import axios from "axios";
  2. import { load } from "cheerio";
  3. async function search(query, page, type){
  4. if (type !== 'lyric') {
  5. return;
  6. }
  7. const result = (await axios.get('https://zh.followlyrics.com/search', {
  8. params: {
  9. name: query,
  10. type: 'song'
  11. }
  12. })).data;
  13. const $ = load(result);
  14. const results = $('.table.table-striped > tbody');
  15. const items = results.children('tr');
  16. const data = items.map((index, el) => {
  17. const tds = $(el).children();
  18. const title = $(tds.get(0)).text().trim();
  19. const artist = $(tds.get(1)).text().trim();
  20. const album = $(tds.get(2)).text().trim();
  21. const id = $(tds.get(3)).children('a').attr('href');
  22. return {
  23. title,
  24. artist,
  25. album,
  26. id
  27. }
  28. }).toArray();
  29. return {
  30. isEnd: true,
  31. data
  32. }
  33. }
  34. async function getLyric(musicItem) {
  35. const res = (await axios.get(musicItem.id)).data;
  36. const $ = load(res);
  37. const rawLrc = $('div#lyrics').text().replace(/\n/g, '');
  38. return {
  39. rawLrc: rawLrc,
  40. };
  41. }
  42. module.exports = {
  43. platform: "歌词网",
  44. version: "0.0.0",
  45. srcUrl: 'https://gitee.com/maotoumao/MusicFreePlugins/raw/v0.1/dist/geciwang/index.js',
  46. cacheControl: "no-store",
  47. supportedSearchType: ['lyric'],
  48. search,
  49. getLyric
  50. };
  51. // search('夜曲', 1, 'lyric').then(console.log);
  52. // getLyric({
  53. // title: '夜曲',
  54. // artist: '周杰伦',
  55. // album: '十一月的萧邦',
  56. // id: 'https://zh.followlyrics.com/lyrics/99416/ye-qu'
  57. // }).then(console.log);