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. let ip = req.ip.replace('::1', '127.0.0.1')
  12. const id = req.query.id
  13. const br = req.query.br || 999000
  14. const channel = req.params['channel']
  15. let config = {
  16. path: links[channel],
  17. params: {
  18. "ids": [id],
  19. "br": 999000,
  20. "csrf_token": ""
  21. },
  22. headers: {
  23. 'X-Real-IP': ip
  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. break;
  53. }
  54. util.requestServer(config).then(ret => {
  55. if (channel == 'song') {
  56. let songs = ret.songs
  57. if (songs.length) {
  58. config['path'] = links.song_url
  59. config['params'] = {
  60. "ids": [id],
  61. "br": br,
  62. "csrf_token": ""
  63. }
  64. util.requestServer(config).then(rt => {
  65. let song = songs[0]
  66. song['mp3'] = rt.data[0]
  67. res.send({
  68. data: song,
  69. status: {
  70. code: 200,
  71. msg: ''
  72. }
  73. })
  74. }).catch(ex => {
  75. console.log(ex)
  76. res.send({
  77. data: {},
  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: {},
  100. status: {
  101. code: -1,
  102. msg: 'something happend. Please checked your id or url'
  103. }
  104. })
  105. })
  106. });
  107. module.exports = router;