luci-app-unblockmusic: sync source

This commit is contained in:
CN_SZTL 2019-07-17 20:53:41 +08:00
parent ccf1d0cdae
commit 85e1d9f70b
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
7 changed files with 34 additions and 20 deletions

View File

@ -15,8 +15,8 @@ LUCI_TITLE:=LuCI support for UnblockNeteaseMusic
LUCI_DEPENDS:=+node +bash +dnsmasq-full +ipset
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-unblockmusic
PKG_VERSION:=1.2
PKG_RELEASE:=3
PKG_VERSION:=1.3
PKG_RELEASE:=1
PKG_MAINTAINER:=<https://github.com/shell-script/luci-app-unblockmusic>

View File

@ -52,7 +52,9 @@ hook.target.path = [
'/api/v1/playlist/manipulate/tracks',
'/api/song/like',
'/api/v1/play/record',
'/api/playlist/v4/detail'
'/api/playlist/v4/detail',
'/api/v1/radio/get',
'/api/v1/discovery/recommend/songs'
]
hook.request.before = ctx => {
@ -257,7 +259,7 @@ const tryMatch = ctx => {
if((item.code != 200 || item.freeTrialInfo) && (target == 0 || item.id == target)){
return match(item.id)
.then(song => {
item.url = `${global.endpoint || 'http://music.163.com'}/package/${crypto.base64.encode(song.url)}/${item.id}.mp3`
item.url = global.endpoint ? `${global.endpoint}/package/${crypto.base64.encode(song.url)}/${item.id}.mp3` : song.url
item.md5 = song.md5 || crypto.md5.digest(song.url)
item.size = song.size
item.code = 200
@ -280,8 +282,8 @@ const tryMatch = ctx => {
try{
let header = netease.param.header
header = typeof header === 'string' ? JSON.parse(header) : header
let {os, appver} = header
if(os in limit && newer(limit[os], appver))
let os = header.os, version = header.appver
if(os in limit && newer(limit[os], version))
return cache(computeHash, task, 7 * 24 * 60 * 60 * 1000).then(value => item.md5 = value)
}
catch(e){}

View File

@ -1,5 +1,5 @@
{
"name": "unblockneteasemusic",
"version": "0.15.2",
"version": "0.16.0",
"lockfileVersion": 1
}

View File

@ -1,6 +1,6 @@
{
"name": "unblockneteasemusic",
"version": "0.15.2",
"version": "0.16.0",
"description": "Revive unavailable songs for Netease Cloud Music",
"main": "provider/match.js",
"bin": {

View File

@ -14,9 +14,9 @@ const find = id => {
let info = filter(jsonBody.songs[0], ['id', 'name', 'alias', 'duration'])
info.album = filter(jsonBody.songs[0].album, ['id', 'name'])
info.artists = jsonBody.songs[0].artists.map(artist => filter(artist, ['id', 'name']))
info.keyword = info.artists.map(artist => artist.name).join(' / ') + ' - ' + info.name
info.keyword = info.name + ' - ' + info.artists.map(artist => artist.name).join(' / ')
return info
})
}
module.exports = id => cache(find, id)
module.exports = id => cache(find, id)

View File

@ -62,7 +62,7 @@ const request = (method, url, headers, body) => {
.end(body)
)
.on('error', error => reject(error))
.end(body)
.end(options.method.toUpperCase() === 'CONNECT' ? null : body)
})
.then(response => {
if([201, 301, 302, 303, 307, 308].includes(response.statusCode))

View File

@ -24,6 +24,7 @@ const proxy = {
else{
const ctx = {res, req}
Promise.resolve()
.then(() => proxy.protect(ctx))
.then(() => proxy.authenticate(ctx))
.then(() => hook.request.before(ctx))
.then(() => proxy.filter(ctx))
@ -37,6 +38,7 @@ const proxy = {
tunnel: (req, socket, head) => {
const ctx = {req, socket, head}
Promise.resolve()
.then(() => proxy.protect(ctx))
.then(() => proxy.authenticate(ctx))
.then(() => hook.connect.before(ctx))
.then(() => proxy.filter(ctx))
@ -47,6 +49,19 @@ const proxy = {
.catch(() => proxy.tunnel.close(ctx))
}
},
abort: (socket, from) => {
// console.log('call abort', from)
if(socket) socket.end()
if(socket && !socket.destroyed) socket.destroy()
},
protect: ctx => {
const req = ctx.req
const res = ctx.res
const socket = ctx.socket
if(req) req.on('error', () => proxy.abort(req.socket, 'req'))
if(res) res.on('error', () => proxy.abort(res.socket, 'res'))
if(socket) socket.on('error', () => proxy.abort(socket, 'socket'))
},
log: ctx => {
const mark = {close: '|', blank: '-', proxy: '>'}[ctx.decision] || '>'
if(ctx.socket)
@ -59,7 +74,8 @@ const proxy = {
const res = ctx.res
const socket = ctx.socket
let credential = Buffer.from((req.headers['proxy-authorization'] || '').split(/\s+/).pop() || '', 'base64').toString()
if(server.authentication && credential != server.authentication){
if('proxy-authorization' in req.headers) delete req.headers['proxy-authorization']
if(server.authentication && credential != server.authentication && (socket || req.url.startsWith('http://'))){
if(socket)
socket.write('HTTP/1.1 407 Proxy Auth Required\r\nProxy-Authenticate: Basic realm="realm"\r\n\r\n')
else
@ -101,24 +117,20 @@ const proxy = {
}),
response: ctx => {
const res = ctx.res
const proxyRes = ctx.proxyRes
const proxyRes = ctx.proxyRes.on('error', () => proxy.abort(ctx.proxyRes.socket, 'proxyRes'))
res.writeHead(proxyRes.statusCode, proxyRes.headers)
proxyRes.readable ? proxyRes.pipe(res) : res.end(proxyRes.body)
},
close: ctx => {
ctx.res.socket.end()
proxy.abort(ctx.res.socket, 'mitm')
}
},
tunnel: {
connect: ctx => new Promise((resolve, reject) => {
if(ctx.decision === 'close') return reject(ctx.error = ctx.decision)
const req = ctx.req
const socket = ctx.socket
const head = ctx.head
const url = parse('https://' + req.url)
socket.on('error', error => {
return reject(ctx.error = error)
})
if(global.proxy && !req.local){
const options = request.configure(req.method, url, req.headers)
request.create(proxy)(options)
@ -150,12 +162,12 @@ const proxy = {
pipe: ctx => new Promise((resolve, reject) => {
if(ctx.decision === 'blank') return reject(ctx.error = ctx.decision)
const socket = ctx.socket
const proxySocket = ctx.proxySocket
const proxySocket = ctx.proxySocket.on('error', () => proxy.abort(ctx.proxySocket, 'proxySocket'))
socket.pipe(proxySocket)
proxySocket.pipe(socket)
}),
close: ctx => {
ctx.socket.end()
proxy.abort(ctx.socket, 'tunnel')
}
}
}