netease.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var express = require('express');
  2. var router = express.Router();
  3. const util = require('../utils/util')
  4. const links = {
  5. song: '/weapi/v3/song/detail',
  6. song_url: '/weapi/song/enhance/player/url',
  7. playlist: '/weapi/v3/playlist/detail'
  8. }
  9. /* GET users listing. */
  10. router.get('/:channel', function(req, res, next) {
  11. const id = req.query.id
  12. const br = req.query.br || 999000
  13. const channel = req.params['channel']
  14. // console.log(req)
  15. let config = {
  16. path: links[channel],
  17. params: {
  18. "ids": [id],
  19. "br": 999000,
  20. "csrf_token": ""
  21. }
  22. }
  23. switch (channel) {
  24. case 'playlist':
  25. config['params'] = {
  26. "id": id,
  27. "offset": 0,
  28. "total": true,
  29. "limit": 1000,
  30. "n": 1000,
  31. "csrf_token": ""
  32. }
  33. break;
  34. case 'song':
  35. config['params'] = {
  36. 'c': JSON.stringify([{ id: id }]),
  37. "ids": '[' + id + ']',
  38. "csrf_token": ""
  39. }
  40. break;
  41. default:
  42. res.send({
  43. data: {},
  44. status: {
  45. code: -1,
  46. msg: 'no support url. Please set `song` or `playlist`'
  47. }
  48. })
  49. break;
  50. }
  51. util.requestServer(config).then(ret => {
  52. if (channel == 'song') {
  53. let songs = ret.songs
  54. if (songs.length) {
  55. config['path'] = links.song_url
  56. config['params'] = {
  57. "ids": [id],
  58. "br": br,
  59. "csrf_token": ""
  60. }
  61. util.requestServer(config).then(rt => {
  62. let song = songs[0]
  63. song['mp3'] = rt.data[0]
  64. res.send({
  65. data: song,
  66. status: {
  67. code: 200,
  68. msg: ''
  69. }
  70. })
  71. }).catch(ex => {
  72. res.send({
  73. data: ex,
  74. status: {
  75. code: -1,
  76. msg: 'something happend. Please checked your id or url'
  77. }
  78. })
  79. })
  80. } else {
  81. res.send({
  82. data: {},
  83. status: {
  84. code: -1,
  85. msg: 'sorry, no result, please changed song id.'
  86. }
  87. })
  88. }
  89. } else {
  90. res.send(ret)
  91. }
  92. }).catch(err => {
  93. console.log(err)
  94. res.send({
  95. data: err,
  96. status: {
  97. code: -1,
  98. msg: 'something happend. Please checked your id or url'
  99. }
  100. })
  101. })
  102. });
  103. module.exports = router;