Skip to content

Commit

Permalink
youtube issues fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
netptop committed Mar 6, 2020
1 parent b53303c commit 8648ecb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
onError: (err, req, res) => {
console.log(`onerror: ${err}`)
try {
// res.status(404).send(`onError: ${err}`)
// res.status(404).send(`{"error": "${err}"}`)
} catch(e) {
console.log(`error of sending 404: ${e}`)
}
Expand All @@ -178,15 +178,15 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
logSave(`zlib.gunzip...`)
}
} catch(e) {
res.status(404).send(`error:${e}`)
res.status(404).send(`{"error": "${e}"}`)
return
}
if (proxyRes.headers["content-type"].indexOf('text/') !== -1 ||
proxyRes.headers["content-type"].indexOf('javascript') !== -1 ||
proxyRes.headers["content-type"].indexOf('urlencoded') !== -1 ||
proxyRes.headers["content-type"].indexOf('json') !== -1) {
if (!gunzipped) {
res.status(404).send()
res.status(404).send(`{"error":"failed unzip"}`)
return
}
logSave(`utf-8 text...`)
Expand Down Expand Up @@ -264,7 +264,7 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
onProxyReq: (proxyReq, req, res) => {
let {host, httpType} = getHostFromReq(req)
if (host == '' || host.indexOf('.') === -1) {
res.status(404).send()
res.status(404).send("{}")
return
}
logClear()
Expand All @@ -284,7 +284,7 @@ let Proxy = ({httpprefix, serverName, port, cookieDomainRewrite, locationReplace
logSave(`req host:${host}, req.url:${req.url}, proxyReq.path:${proxyReq.path}, proxyReq.url:${proxyReq.url} proxyReq headers:${JSON.stringify(proxyReq.getHeaders())}`)
if(host === '' || !host) {
logSave(`------------------ sending status 404`)
res.status(404).send()
res.status(404).send("{}")
res.end()
}

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# siteproxy
pure web page proxy, zero configuration from client side. Reverse proxy to all internet. 一键部署,翻墙利器。
pure web page proxy to google, zero configuration from client side. Reverse proxy to all internet. 一键部署,翻墙利器。

```
+----> google
Expand Down Expand Up @@ -31,8 +31,8 @@ user browser +-------------->+ siteproxy +-------> wikipedia

## supported websites
```
1. www.google.com, and search action
2. zh.wikipedia.org, and search action
1. www.google.com, and search action.
2. zh.wikipedia.org, and search action.
3. facebook, login is not verified.
4. other websites.
```
Expand All @@ -54,6 +54,4 @@ user browser +-------------->+ siteproxy +-------> wikipedia

## issues
- 部分网站加载有问题;
- 暂时无法看视频网站;
- twitter访问有问题;
- recaptcha验证码有问题;
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<br />
<div class="descriptionSeg">3.由于从本代理发出的Google请求过多, google会自动限制搜索流量; 如果google不能用,请使用bing和yahoo搜索引擎. </div>
<br />
<div class="descriptionSeg">4.请登录telegram,加群@siteproxy,以便在本代理失效后及时获取更新</div>
<div class="descriptionSeg">5.请登录telegram,加群@siteproxy,以便在本代理失效后及时获取更新</div>
<form class="lead-title">
<p>指定网址:<input class="lead-title" type="text" id="address" value="https://www.google.com">
<input id="addrAccess" class="lead-title button1" type="button" onclick="onsubmit" value="访问网站"/>
Expand Down
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ const pathReplace = ({host, httpType, body}) => {
myRe = new RegExp('([:, ]url[(]["\']?)/([-a-z0-9]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

myRe = new RegExp('("url":")/([-a-z0-9_]+?)', 'g')
myRe = new RegExp('("url":[ ]?")/([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

myRe = new RegExp('(url:[ ]?")/([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

myRe = new RegExp('(rl.":.")./([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1\\/${httpType}\\/${host}\\/$2`)

myRe = new RegExp('("path":")/([-a-z0-9_]+?)', 'g')
body = body.replace(myRe, `$1/${httpType}/${host}/$2`)

Expand Down Expand Up @@ -119,15 +125,15 @@ const siteSpecificReplace = {
'c<a.C.length': `c<a.C.length&&a.C[c].style`, // fixed the exception.
' .......*?"Captions URL".': ' true', // Ms(Os(a, jfa, null), a, b, "Captions URL")
'throw Error."Untrusted URL.+?;': ';',
// '&&[a-zA-Z.]+?.Error."Player URL validator detects invalid url.*?;': `&&a=true;`,
'"//"(.this\..\...\...."/api/stats/qoe")': `"//${serverName}:${port}/https/"$1`,
//;b=g.$g("//"+this.o.ab.Ff+"/api/stats/qoe",a);
'return .\.protocol."://(i1.ytimg.com/vi/)"': `return "${httpprefix}://${serverName}:${port}/https/$1"`,
// {return a.protocol+"://i1.ytimg.com/vi/"+b+"/"+(c||"hqdefault.jpg")};
'"//"(.this\..\...\...."/api/stats/qoe")': `"//${serverName}:${port}/https/"$1`, //;b=g.$g("//"+this.o.ab.Ff+"/api/stats/qoe",a);
'return .\.protocol."://(i1.ytimg.com/vi/)"': `return "${httpprefix}://${serverName}:${port}/https/$1"`, // {return a.protocol+"://i1.ytimg.com/vi/"+b+"/"+(c||"hqdefault.jpg")};
'(rl%22%3A%22%2F%2F)([-a-z0-9A-Z.]+?)': `$1${serverName}%3A${port}%2Fhttps%2F$2`, // rl%22%3A%22%2F%2Fwww.youtube.com
'(.\..."ptracking",)': `"${httpprefix}://${serverName}:${port}/https/www.youtube.com/ptracking",`,//(d.C+"ptracking", in base.js
':"//"[+].\...[+]"/api/stats/"': `:"//${serverName}:${port}/https/www.youtube.com/api/stats/"`, // his.sa=this.O?"/api/stats/"+c:"//"+b.If+"/api/stats/"+c;d&&(t
// 'this\..\.logo\.hidden=.[01][,;]': ``, // this.$.logo.hidden = !1,
'iconChanged_:function.[a-z],[a-z],[a-z]...*\},': `iconChanged_:function(a,b,c){},`, // iconChanged_:function(a,b,c){
'"/youtubei': `"/https/www.youtube.com/youtubei`,
'"/api/stats/"': `"/https/www.youtube.com/api/stats/"`,
'"/service_ajax"': `"/https/www.youtube.com/service_ajax"`,
},
'search.yahoo.com': {
'"./ra./click"': `"\\/https\\/search.yahoo.com\\/ra\\/click"`,
Expand Down
31 changes: 26 additions & 5 deletions test/siteproxylocal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,38 @@ test('youtube url check issue', async () => {
expect(response.data.indexOf(`("//${serverName}:${port}/https/"+this.`)).not.toBe(-1)
expect(response.data.indexOf(`://i1.ytimg.com/vi`)).toBe(-1)
expect(response.data.indexOf(`"ptracking"`)).toBe(-1)
expect(response.data.indexOf(`+"/api/stats/"`)).toBe(-1)
expect(response.data.indexOf(`"/api/stats/"`)).toBe(-1)
}, 30000);

/*
test('youtube desktop_polymer_v2.js issue', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/yts/jsbin/desktop_polymer_v2-vflUBXo7B/desktop_polymer_v2.js`
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/yts/jsbin/desktop_polymer_v2-vflv5mvtW/desktop_polymer_v2.js`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
console.log(`${response.data}`)
expect(response.data.indexOf(`this.$.logo.hidden=`)).toBe(-1)
expect(response.data.indexOf(`iconChanged_:function(a,b,c){},`)).not.toBe(-1)
expect(response.data.indexOf(`g+("/youtubei/"`)).toBe(-1)
expect(response.data.indexOf(`"/service_ajax"`)).toBe(-1)
}, 30000);



test('youtube url conversion', async () => {
const url = `${httpprefix}://${serverName}:${port}/https/www.youtube.com/watch?v=I9K4MbvlDss&frags=pl%2Cwn`
const response = await axios({
method: 'get',
headers: {
'Accept': `text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9`,
'Cookie': `VISITOR_INFO1_LIVE=WxtnB8UaTM4; YSC=QPym_D-ojR0`,
},
url,
})
// console.log(`${JSON.stringify(response.headers)}`)
// console.log(`${response.data}`)
expect(response.data.indexOf(`"\\/service_ajax\\",`)).toBe(-1)
}, 30000);
*/

0 comments on commit 8648ecb

Please sign in to comment.