Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下載器「片段下载失败」 #143

Closed
partment opened this issue Jun 27, 2019 · 9 comments
Closed

下載器「片段下载失败」 #143

partment opened this issue Jun 27, 2019 · 9 comments
Assignees
Labels
bug bug

Comments

@partment
Copy link

partment commented Jun 27, 2019

Reproduce : https://www.bilibili.com/bangumi/play/ep259676

Error Code :

正在下载: 盾之勇者成名录:第3话
0% [ ]internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^

[Error: EPERM: operation not permitted, open 'C:\盾之勇者成名录:第3话.part0'] {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'C:\盾之勇者成名录:第3话.part0'
}

acgvideo.com和akamaized.net這兩種國內國外CDN都試過了
也試著在別的機器或Linux跑過,都是一樣的結果

@the1812 the1812 self-assigned this Jun 28, 2019
@the1812
Copy link
Owner

the1812 commented Jun 30, 2019

这个问题好像有点严重, 所有的视频都因为这个错误无法下载了.

调试了一下发现 Node.js 对下载链接无法处理(视为无效了)

const request = require('request')
const fs = require('fs')

request.get('https://upos-hz-mirrorks3u.acgvideo.com/upgcxcode/25/49/99934925/99934925-1-112.flv?e=ig8euxZM2rNcNbhVhb4BhwdlhzdgnwUVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEVEuxTEto8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&deadline=1561877792&gen=playurl&nbs=1&oi=0&os=ks3u&platform=pc&trid=24fb38a04143467dbaff4f7fe80eae27&uipk=5&upsig=47452310f6bb5da65df07f470123763a&uparams=e,deadline,gen,nbs,oi,os,platform,trid,uipk&mid=39717974', {
  headers: {
    Origin: "https://www.bilibili.com",
    Referer: "https://www.bilibili.com",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
  }
}).pipe(fs.createWriteStream('test.flv'))

这会产生以下错误 (在下载器中向上传递表现为Error: EPERM: operation not permitted)

internal/streams/legacy.js:57
      throw er; // Unhandled stream error in pipe.
      ^

Error: Parse Error
    at TLSSocket.socketOnData (_http_client.js:447:20)
    at TLSSocket.emit (events.js:197:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:145:17)

如果换成一些普通的网站却可以, 比如https://www.bing.com.
网上查到的资料表明这有两种情况:

  1. 链接里有空格
  2. 服务器返回的数据长度不匹配请求头的Content-Length

下载链接里没有任何空格, 服务器也不是我能控制的, 所以我目前没有什么解决办法, 长期得不到解决的话我可能会考虑把下载器迁移到.NET Core上.

@partment
Copy link
Author

partment commented Jun 30, 2019

試著修改下請求頭,對應解析出連結使用的瀏覽器之User-Agent並修改Referer至此番劇連結

const request = require('request')
const fs = require('fs')

request.get('https://upos-hz-mirrorks3u.acgvideo.com/upgcxcode/52/88/72848852/72848852-1-112.flv?e=ig8euxZM2rNcNbNMnw4BhwdlhbK3nwUVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&deadline=1561886571&gen=playurl&nbs=1&oi=1696929724&os=ks3u&platform=pc&trid=63b431cb93e846dda1da6bd686c4f4a9p&uipk=5&upsig=1489353a98a40b446bfe65e04e9e1c30&uparams=e,deadline,gen,nbs,oi,os,platform,trid,uipk', {
  headers: {
    Origin: "https://www.bilibili.com",
    Referer: "https://www.bilibili.com/bangumi/play/ep259676",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:67.0) Gecko/20100101 Firefox/67.0",
  }
}).pipe(fs.createWriteStream('test.flv'))

成功下載

@partment
Copy link
Author

使用這個頁面提供的curl命令列測試,發現一樣返回403。就懷疑是不是請求頭被伺服器返回Close了,就改了下請求頭發現可以成功下載

@partment
Copy link
Author

只修改User-Agent一樣成功
sublime_text_20190630_155700
powershell_20190630_160045

@the1812
Copy link
Owner

the1812 commented Jun 30, 2019

非常感谢! 我已在下载器的新版本和文档中更换了User-Agent.

但是关于User-Agent的测试结果, 还是有些奇怪:
原本使用的User-Agent取自Chrome 73, 它在下载器和curl中无法使用, 但是在Invoke-WebRequest命令中却能顺利下载
image

@partment
Copy link
Author

partment commented Jun 30, 2019

根據Powershell的文檔,指定User-Agent要使用-UserAgent參數,不能使用-Header
如果使用-Header修改User-Agent的話,會送出預設的User-Agent
Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.15063; en-US) PowerShell/6.0.0

@partment
Copy link
Author

所以可以說是B站的伺服器拒絕了Chrome 73的UA

@the1812
Copy link
Owner

the1812 commented Jun 30, 2019

原来如此. 还是得好好根据文档来写, 那个Invoke-WebRequest也是当时由Chrome开发者工具生成的.

@partment
Copy link
Author

解決問題,皆大歡喜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bug
Projects
None yet
Development

No branches or pull requests

2 participants