netease.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. return
  50. break;
  51. }
  52. util.requestServer(config).then(ret => {
  53. if (channel == 'song') {
  54. let songs = ret.songs
  55. if (song && songs.length) {
  56. config['path'] = links.song_url
  57. config['params'] = {
  58. "ids": [id],
  59. "br": br,
  60. "csrf_token": ""
  61. }
  62. util.requestServer(config).then(rt => {
  63. let song = songs[0]
  64. song['mp3'] = rt.data[0]
  65. res.send({
  66. data: song,
  67. status: {
  68. code: 200,
  69. msg: ''
  70. }
  71. })
  72. }).catch(ex => {
  73. res.send({
  74. data: ex,
  75. status: {
  76. code: -1,
  77. msg: 'something happend. Please checked your id or url'
  78. }
  79. })
  80. })
  81. } else {
  82. res.send({
  83. data: {},
  84. status: {
  85. code: -1,
  86. msg: 'sorry, no result, please changed song id.'
  87. }
  88. })
  89. }
  90. } else {
  91. res.send(ret)
  92. }
  93. }).catch(err => {
  94. console.log(err)
  95. res.send({
  96. data: err,
  97. status: {
  98. code: -1,
  99. msg: 'something happend. Please checked your id or url'
  100. }
  101. })
  102. })
  103. });
  104. module.exports = router;