netease.js 3.0 KB

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