Skip to content

Commit

Permalink
Merge pull request #34 from chuxiuhong/main
Browse files Browse the repository at this point in the history
Modify the execution parameters to be received via command-line input.
  • Loading branch information
gaowanliang authored Jan 3, 2025
2 parents a863289 + 8999dd4 commit 84ceada
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ local-chromium
__pycache__
example.png
test
*.txt
*.txt
.DS_Store
64 changes: 52 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ requests==2.25.1

pyppeteer==0.2.5

# Setup aria2

## Install aria2

For macOS:
```bash
brew install aria2
```

For Ubuntu/Debian:
```bash
sudo apt-get install aria2
```

For CentOS/RHEL:
```bash
sudo yum install aria2
```

For Windows:
Download and install aria2 from https://aria2.github.io/

## Configure aria2 RPC

Start aria2 with RPC:
```bash
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -D -d <download-directory>
```

# Feature

At present, this program supports the following download methods:
Expand All @@ -32,7 +61,7 @@ At present, this program supports the following download methods:
input this command then you can get file list in list.txt

```bash
python main.py > list.txt
python main.py "https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh" > list.txt
```

It maybe output gibberish in powershell, you can input this command before to fix
Expand All @@ -56,23 +85,34 @@ Take this download link as an example:

https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh

At this time, you need to use the download code for no password link, that is, [main.py](main.py). Open this file and you can see that there are some global variables:
The program now uses command line arguments. Here are the available options:

- OneDrive URL: The download address (required argument)
- `--aria2-link`: aria2's rpc address, default is `http://127.0.0.1:6800/jsonrpc`
- `--aria2-secret`: the password of aria2, default is empty
- `--download`: whether to download or not, if not specified, only the file list is output
- `--download-num`: List of files to download, default is "0" (means all files)

- 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 specific files, use the `--download-num` option:

If you want to download the second file, you need `downloadNum="2"`
- Download the second file: `--download-num "2"`
- Download the second and third file: `--download-num "2-3"`
- Download the second, third, fourth, seventh file: `--download-num "2-4,7"`

If you want to download the second and third file, you need `downloadNum="2-3"`
Example usage:
```bash
# List files only
python main.py "your-onedrive-share-url"

If you want to download the second, third, fourth, seventh file, you need `downloadNum="2-4,7"`
# Download all files
python main.py "your-onedrive-share-url" --download

and so on.
# Download specific files
python main.py "your-onedrive-share-url" --download --download-num "2-4,7"

After modifying, make sure the target aria2 is on and execute `python3 main.py`
# Use custom aria2 settings
python main.py "your-onedrive-share-url" --download --aria2-link "http://localhost:6800/jsonrpc" --aria2-secret "your-secret"
```

## With password for shared links

Expand Down
83 changes: 60 additions & 23 deletions docs/Readme_zh-cn.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# OneDriveShareLinkPushAria2

Extract download URLs from OneDrive or SharePoint share links and push them to aria2, even on systems without a GUI.

从 OneDrive 或 SharePoint 共享链接提取下载 URL 并将其推送到 aria2,即使在无图形界面的系统中依然可以使用。

# 依赖
Expand All @@ -10,6 +8,35 @@ requests==2.25.1

pyppeteer==0.2.5

# 配置 aria2

## 安装 aria2

macOS 系统:
```bash
brew install aria2
```

Ubuntu/Debian 系统:
```bash
sudo apt-get install aria2
```

CentOS/RHEL 系统:
```bash
sudo yum install aria2
```

Windows 系统:
https://aria2.github.io/ 下载并安装 aria2

## 配置 aria2 RPC

启动 aria2 RPC 服务:
```bash
aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all -D -d <下载目录>
```

# 特点

目前本程序支持的下载方式:
Expand All @@ -27,10 +54,10 @@ pyppeteer==0.2.5

## 输出文件列表

使用以下命令输出文件列表到 list.txt
使用以下命令输出文件列表到 list.txt

```bash
python main.py > list.txt
python main.py "https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh" > list.txt
```

使用 powershell 运行此命令可能会输出乱码, 先运行以下命令即可修复
Expand All @@ -51,38 +78,48 @@ python main.py > list.txt

## 无密码的链接

https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh 这个下载链接为例
程序现在使用命令行参数。以下是可用的选项:

此时需要使用无密码的下载代码,也就是[main.py](../main.py),打开这个文件,可以看到有一些全局变量:
- OneDrive URL:下载地址(必需参数)
- `--aria2-link`:aria2 的 RPC 地址,默认为 `http://127.0.0.1:6800/jsonrpc`
- `--aria2-secret`:aria2 的密码,默认为空
- `--download`:是否下载,如果不指定则只输出文件列表
- `--download-num`:要下载的文件列表,默认为 "0"(表示全部文件)

- OneDriveShareURL: 下载地址,此处应该填写 https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh
- aria2Link: aria2 的 rpc 地址,如果是本机,一般是 `http://localhost:端口号/jsonrpc`
- aria2Secret: aria2 的密码
- isDownload: 是否下载,如果是`False`,只输出文件列表
- downloadNum: 要下载的文件列表,**0**表示全部下载
如果要下载特定文件,使用 `--download-num` 选项:

如果想要下载第二个文件,则需要`downloadNum="2"`
- 下载第二个文件:`--download-num "2"`
- 下载第二和第三个文件:`--download-num "2-3"`
- 下载第二、第三、第四、第七个文件:`--download-num "2-4,7"`

如果想要下载第二、第三个文件,则需要`downloadNum="2-3"`
使用示例:
```bash
# 仅列出文件
python main.py "你的-onedrive-分享链接"

如果想要下载第二、第三、第四、第七个文件,则需要`downloadNum="2-4,7"`
# 下载所有文件
python main.py "你的-onedrive-分享链接" --download

以此类推
# 下载指定文件
python main.py "你的-onedrive-分享链接" --download --download-num "2-4,7"

修改好后,确保目标 aria2 处于开启状态,执行`python3 main.py`
# 使用自定义 aria2 设置
python main.py "你的-onedrive-分享链接" --download --aria2-link "http://localhost:6800/jsonrpc" --aria2-secret "你的密码"
```

## 有密码的链接
## 有密码链接下载

https://jia666-my.sharepoint.com/:f:/g/personal/1025_xkx_me/EsqNMFlDoyZKt-RGcsI1F2EB6AiQMBIpQM4Ka247KkyOQw?e=oC1y7r 这个下载链接为例
以下载链接为例:
https://jia666-my.sharepoint.com/:f:/g/personal/1025_xkx_me/EsqNMFlDoyZKt-RGcsI1F2EB6AiQMBIpQM4Ka247KkyOQw?e=oC1y7r

此时需要使用有密码的下载代码,也就是[havepassword.py](../havepassword.py)打开这个文件,可以看到有一些全局变量(重复的不再赘述):
此时需要使用有密码的下载代码,[havepassword.py](../havepassword.py)打开这个文件,可以看到一些全局变量(重复的不再赘述):

- OneDriveSharePwd: OneDrive 链接的密码
- OneDriveSharePwdOneDrive 链接的密码

使用方法和上面类似
使用方法与上面类似

# 注意

使用前,使用 `git clone https://github.com/gaowanliang/OneDriveShareLinkPushAria2.git` 将项目整个克隆,才能使用,havepassword.py 依赖于 main.py,如果要使用需要密码的版本,需要 `pip install pyppeteer`
使用前,需要使用 `git clone https://github.com/gaowanliang/OneDriveShareLinkPushAria2.git` 将项目整个克隆下来才能使用。havepassword.py 依赖于 main.py,如果要使用需要密码的版本,需要 `pip install pyppeteer`

此程序基本功能都已实现,之后很长的一段时间内,如果不是软件无法使用了,则不再维护如有运行问题,请在提出 issue 时带上下载链接,不提供下载链接的 bug 类型的 issue 将不会解决。
此程序基本功能都已实现,之后很长的一段时间内,如果不是软件无法使用了,则不再维护如有运行问题,请在提出 issue 时带上下载链接,不提供下载链接的 bug 类型的 issue 将不会解决。
34 changes: 20 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import urllib
import urllib.request
import argparse

from pprint import pprint
from urllib import parse
Expand All @@ -17,14 +18,18 @@

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")

OneDriveShareURL = "https://1drv.ms/f/c/5973e13d37fc66d0/EucPv2vQu4ZBq2FNh_Ara-kBpou6yfkbtePq3JFgq8oGgg?e=4KWQP1"

aria2Link = "http://127.0.0.1:6800/jsonrpc"
aria2Secret = ""


isDownload = False
downloadNum = "0" # 1,2-4,5
def parse_arguments():
parser = argparse.ArgumentParser(description='OneDrive Share Link Push to Aria2')
parser.add_argument('onedrive_url', help='OneDrive share URL')
parser.add_argument('--aria2-link', default="http://127.0.0.1:6800/jsonrpc",
help='Aria2 JSON-RPC URL (default: http://127.0.0.1:6800/jsonrpc)')
parser.add_argument('--aria2-secret', default="",
help='Aria2 RPC secret (default: "")')
parser.add_argument('--download', action='store_true',
help='Enable download mode (default: False)')
parser.add_argument('--download-num', default="0",
help='Download file numbers, e.g., "1,2-4,5" (default: "0")')
return parser.parse_args()

fileCount = 0

Expand Down Expand Up @@ -536,17 +541,18 @@ def getAria2ConfigDir(aria2URL, token):


if __name__ == "__main__":
if isDownload:
args = parse_arguments()
if args.download:
downloadFiles(
OneDriveShareURL,
args.onedrive_url,
None,
0,
aria2Link,
aria2Secret,
num=wildcardsMatchFiles(downloadNum),
args.aria2_link,
args.aria2_secret,
num=wildcardsMatchFiles(args.download_num),
)
else:
getFiles(OneDriveShareURL, None, 0)
getFiles(args.onedrive_url, None, 0)
#
# getFilesHavePwd(
# "https://jia666-my.sharepoint.com/:f:/g/personal/1025_xkx_me/EsqNMFlDoyZKt-RGcsI1F2EB6AiQMBIpQM4Ka247KkyOQw?e=oC1y7r&guestaccesstoken=xyz", "xkx")

0 comments on commit 84ceada

Please sign in to comment.