netease.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. request(config,id,channel)
  34. break;
  35. case 'song':
  36. config['params'] = {
  37. 'c': JSON.stringify([{ id: id }]),
  38. "ids": '[' + id + ']',
  39. "csrf_token": ""
  40. }
  41. request(config,id,channel)
  42. break;
  43. default:
  44. res.send({
  45. data: {},
  46. status: {
  47. code: -1,
  48. msg: 'no support url. Please set `song` or `playlist`'
  49. }
  50. })
  51. break;
  52. }
  53. });
  54. function request(config,id,channel){
  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;