用OneDrive很好,抵制百度网盘我强烈支持,但是OneDrive国内有时候抽风比较厉害,而在国外OneDrive下载几乎能跑满带宽,我G口的服务器可以跑到110M/s,所以用国外服务器下载,然后再下载自己服务器里的东西会比较好。
但是因为OneDrive有些坑,无法从分享界面获取真实下载链接,比如下面这个链接
点开之后,找个文件点击下载,会得到这样的下载链接:
但是如果直接在服务器里 wget 这个下载链接,100%会得到403: Forbidden.
有经验的老手都知道肯定是没带 Cookie ,但是要怎么带Cookie呢,其实很简单,
请使用Chrome或者是Firefox,实测Firefox最快捷,不用进行更改,我下面就用Firefox进行演示。
首先你需要按下F12,打开开发人员工具,然后转到网络选项,之后点击想要下载的文件进行下载,同时观察开发人员工具窗口,找到带有download.aspx/?…. 的那个链接.
之后在那个链接上右键,选择 复制-复制为cURL命令(POSIX)
会在剪切板出现类似下面的命令语句:
curl 'https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/download.aspx?UniqueId=cb44677f%2Dc4af%2D44ad%2D88d4%2Dceb07d9625da' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: zh-HK,zh-TW;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Referer: https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/onedrive.aspx?.......' -H 'Cookie: CCSInfo=NS8yOS8yMDIwIDEwOjE1OjE0IEFNC/.....; FeatureOverrides_enableFeatures=; FeatureOverrides_disableFeatures=' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: iframe' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: same-origin'
之后粘贴到Linux的命令行里,最后在后面补加一句--output file.extension
,其中file.extension
是想要保存的文件名。最终执行的命令就是类似这样的:
curl 'https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/download.aspx?UniqueId=cb44677f%2Dc4af%2D44ad%2D88d4%2Dceb07d9625da' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: zh-HK,zh-TW;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Referer: https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/onedrive.aspx?.......' -H 'Cookie: CCSInfo=NS8yOS8yMDIwIDEwOjE1OjE0IEFNC/.....; FeatureOverrides_enableFeatures=; FeatureOverrides_disableFeatures=' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: iframe' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: same-origin' --output file.extension
最后就能享受高速下载了.
同这个方法也适合文件夹下载,只不过前缀是 xxxxx-mediap.svc.ms
,其中xxxxx
是地区代号,不同的下载链接所指向的地区不同,具体看情况,这里就不再赘述。
如果使用Chrome下载,需要选择 复制cURL(Bash) 然后把里面的换行和\ 都处理掉,要不然会不行,但是我没成功过,按理讲应该是能成功的,算了,Firefox能用就行了,又不是天天下载。
----------------------------------------------------
在纯命令行环境下批量下载OneDrive/SharePoint分享链接中的文件
上面的文章其实解决了一些痛点,在没有图形化界面的Linux上终于可以无痛下载OneDrive分享的文件而不是只能在有图形化界面的系统上用浏览器下载。但是虽然解决了一些痛点,但是还没彻底解决,还有一些痛点如下
- 只能使用curl下载(虽然可以用其他工具下载,但是还得一条一条复制,麻烦)
- 需要自己打文件名
- 不能多线程下载
- 仍然需要一个图形化界面同时可以调试的终端
但是这些痛点还不算痛了,总有办法解决,这里就给出了一个解决方案, https://github.com/gaowanliang/OneDriveShareLinkPushAria2 ,新轮子实现了使用python环境,自动解析下载链接并推送到Aria2下载,使用方法如下:
程序一共有两个函数,getFiles
和downloadFiles
,由于程序是两个小时摸鱼摸出来的,所以写的很糙,不过能用就好。需要翻到程序最后。
getFiles
自不用说,是获取链接下文件的目录,参数只有一个,也就是下载链接
downloadFiles
是获取链接下文件下载链接并推送到Aria2,这里需要填写3个参数,第一个是下载链接;第二个是aria2RPC的地址,这个一般就是改两个地方,就是IP和端口,localhost
改成aria2所在位置的IP,如果是本机就不用管了,冒号后面是端口,一般是6800,我代码给的是5800,记得修改;第三个是aria2的密钥,这个也不用详细说了,改好之后直接运行即可,此时所有的文件都会被推送过去。
现在剩下的痛点就是如果链接里有文件夹的话,目前还没解析,同时如果链接有密码也不能下载,慢慢解决吧。
最后记录一下,aria2的header居然是字符串形式的,形如accept: application/json\naccept-encoding: gzip, deflate, br\naccept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
,一定要注意不要被坑.
-------------------------------------
Extract download URLs from OneDrive or SharePoint share links and push them to aria2, even on systems without a GUI.
OneDriveShareLinkPushAria2
Extract download URLs from OneDrive or SharePoint share links and push them to aria2, even on systems without a GUI (such as Linux).
从OneDrive或SharePoint共享链接提取下载URL并将其推送到aria2,即使在无图形界面的系统中(如Linux)依然可以使用。
Dependent
requests==2.25.1
pyppeteer==0.2.5
Feature
At present, this program supports the following download methods:
- xxx-my.sharepoint.com Download of share links
- Downloading multiple files without password for shared links
- Downloading multiple files with password for shared links
- Download of files in nested folders
- Download any file of your choice
- Traversal view and download for multiple files (more than 30) of shared links
- xxx.sharepoint.com Downloads with share links
- xxx-my.sharepoint.cn Download of share links (theoretically supported)
Note: aria2 itself does not support HTTP POST download links, while onedrive folder package download is HTTP POST download links, so this program will not support onedrive folder package download
Output file list
input this command then you can get file list in list.txt
python main.py > list.txt
It maybe output gibberish in powershell, you can input this command before to fix
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Without password for shared links
Take this download link as an example:
At this time, you need to use the download code for no password link, that is, main.py. Open this file and you can see that there are some global variables:
- OneDriveShareURL: The download address, which should be filled in here https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh
- aria2Link: aria2's rpc address, usually
http://localhost:Port/jsonrpc
if it's native - aria2Secret: the password of aria2
- isDownload: whether to download or not, if
False
, only the file list is output - downloadNum: List of files to download, 0 means all of them
If you want to download the second file, you need downloadNum="2"
If you want to download the second and third file, you need downloadNum="2-3"
If you want to download the second, third, fourth, seventh file, you need downloadNum="2-4,7"
and so on.
After modifying, make sure the target aria2 is on and execute python3 main.py
With password for shared links
Take this download link as an example:
At this time, you need to use the download code for have password link, that is, havepassword.py. Open this file and you can see that there are some global variables (repeated without further ado):
- OneDriveSharePwd: Password for the OneDrive link
Usage is similar to the above.
Note
Before you use it, clone the whole project with git clone https://github.com/gaowanliang/OneDriveShareLinkPushAria2.git
to use it. havepassword.py depends on main.py, if you want to use the
version that requires a password If you want to use a version that
requires a password, you need to pip install pyppeteer
The basic functions of this program have been realized. For a long time, if the software is not unusable, it will not be maintained. If there is a running problem, please bring a download link when raising the issue. The bug type issue that does not provide a download link will not be solved.
from https://github.com/gaowanliang/OneDriveShareLinkPushAria2
No comments:
Post a Comment