netease.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. let config = {
  15. path: links[channel],
  16. params: {
  17. "ids": [id],
  18. "br": 999000,
  19. "csrf_token": ""
  20. }
  21. }
  22. switch (channel) {
  23. case 'playlist':
  24. config['params'] = {
  25. "id": id,
  26. "offset": 0,
  27. "total": true,
  28. "limit": 1000,
  29. "n": 1000,
  30. "csrf_token": ""
  31. }
  32. break;
  33. case 'song':
  34. config['params'] = {
  35. 'c': JSON.stringify([{ id: id }]),
  36. "ids": '[' + id + ']',
  37. "csrf_token": ""
  38. }
  39. break;
  40. default:
  41. res.send({
  42. data: {},
  43. status: {
  44. code: -1,
  45. msg: 'no support url. Please set `song` or `playlist`'
  46. }
  47. })
  48. break;
  49. }
  50. util.requestServer(config).then(ret => {
  51. if (channel == 'song') {
  52. let songs = ret.songs
  53. if (songs.length) {
  54. config['path'] = links.song_url
  55. config['params'] = {
  56. "ids": [id],
  57. "br": br,
  58. "csrf_token": ""
  59. }
  60. util.requestServer(config).then(rt => {
  61. let song = songs[0]
  62. song['mp3'] = rt.data[0]
  63. res.send({
  64. data: song,
  65. status: {
  66. code: 200,
  67. msg: ''
  68. }
  69. })
  70. }).catch(ex => {
  71. console.log(ex)
  72. res.send({
  73. data: {},
  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: {},
  96. status: {
  97. code: -1,
  98. msg: 'something happend. Please checked your id or url'
  99. }
  100. })
  101. })
  102. });
  103. module.exports = router;