LifeActor / ykdl

a video downloader focus on China mainland video sites.
https://github.com/zhangn1985/ykdl
Other
1.43k stars 284 forks source link

acfun 403 #197

Closed zhangn1985 closed 7 years ago

zhangn1985 commented 7 years ago

ykdl http://acfun.cn/v/ac3947859site: AcFun 优酷合作视频 title: acfun_1504007361552 artist: None streams:

airdge commented 7 years ago

acfun从7月初就改版了 mp4/flv必须带cookies: ac__avi 访问才能正常播放/下载

rosynirvana commented 7 years ago

不用cookies

curl http://player.acfun.cn/route_mp4\?uid\=ACFUN\&timestamp\=1504198693\&fid\=0504400204000059A5561000010002EB0000000000-0000-0000-019D-C0DD00000000.mp4\&ns\=video.acfun.cn\&ran\=1010069662930e64d7f81ca59e4035f9c9346d545c9erpcx12125p45p178p2575d7482dbb754\&vid\=59a554910cf23b9f08c46db3\&customer_id\=5859fdaee4b0eaf5dd325b91\&sign\=ct59a840250cf28d96cb8ecebc -L > out.mp4
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   111  100   111    0     0   1373      0 --:--:-- --:--:-- --:--:--  1387
100 1073k  100 1073k    0     0   167k      0  0:00:06  0:00:06 --:--:--  213k

问题在fake_headers上面

rosynirvana commented 7 years ago

和上次api的限制一样,Mozilla这个词被禁掉了

这样改一下能下载

diff --git a/ykdl/util/download.py b/ykdl/util/download.py
index 1e38928..3d6fa7c 100644
--- a/ykdl/util/download.py
+++ b/ykdl/util/download.py
@@ -42,7 +42,9 @@ def save_url(url, name, ext, status, part = None, reporthook = simple_hook):
     read = 0
     blocknum = 0
     open_mode = 'wb'
-    req = Request(url, headers = fake_headers)
+    headers = fake_headers.copy()
+    headers['User-Agent'] = 'ozilla/5.0'
+    req = Request(url, headers = headers)
     response = urlopen(req, None)
     if "content-length" in response.headers:
         size = int(response.headers["Content-Length"])

url_save需要动点手术允许custom headers