diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c6fe3ef --- /dev/null +++ b/.travis.yml @@ -0,0 +1,53 @@ +if: 'tag IS blank' +env: + global: + - TRAVIS_TAG=v1.3 +jobs: + include: + - + name: 'Python 3.7.5 on Linux (AMD64)' + os: linux + dist: bionic + arch: amd64 + language: python + python: 3.7.5 + env: RELEASE_FILENAME=bilidrive-$TRAVIS_TAG-linux-amd64.tar.gz + - + name: 'Python 3.7.5 on Linux (ARM64)' + os: linux + dist: bionic + arch: arm64 + language: python + python: 3.7.5 + env: ['PATH=~/.ruby/bin:$PATH', GEM_HOME=~/.ruby, RELEASE_FILENAME=bilidrive-$TRAVIS_TAG-linux-arm64.tar.gz] + - + name: 'Python 3.7.4 on macOS (AMD64)' + os: osx + osx_image: xcode11.2 + arch: amd64 + language: shell + env: RELEASE_FILENAME=bilidrive-$TRAVIS_TAG-macos-amd64.zip + - + name: 'Python 3.7.5 on Windows (AMD64)' + os: windows + arch: amd64 + language: shell + env: ['PATH=/c/Python37:/c/Python37/Scripts:$PATH', RELEASE_FILENAME=bilidrive-$TRAVIS_TAG-windows-amd64.zip] + before_install: 'choco install python --version 3.7.5' +install: + - 'if [ "$TRAVIS_OS_NAME" = "windows" ]; then python -m pip install -U pip; else pip3 install -U pip; fi' + - 'pip3 install -r requirements.txt' + - 'pip3 install pyinstaller' +script: + - 'if [ "$TRAVIS_OS_NAME" = "windows" ]; then python drive.py -h; else python3 drive.py -h; fi' + - 'pyinstaller -F -n BiliDrive -i icon.ico drive.py' + - 'mkdir -p release/BiliDrive' + - 'cp {dist/*,LICENSE,README.md} release/BiliDrive' + - 'cd release' + - 'if [ "$TRAVIS_OS_NAME" = "windows" ]; then 7z a -tzip $RELEASE_FILENAME BiliDrive; elif [ "$TRAVIS_OS_NAME" = "osx" ]; then zip -r $RELEASE_FILENAME BiliDrive; else tar -czvf $RELEASE_FILENAME BiliDrive; fi' +deploy: + provider: releases + api_key: $GITHUB_OAUTH_TOKEN + file: $RELEASE_FILENAME + overwrite: true + skip_cleanup: true diff --git a/README.md b/README.md index c23d42f..8a29db2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@
- + +
@@ -58,7 +59,7 @@ file: 待上传的文件路径 ``` drive.py download [-h] [-f] [-t THREAD] meta [file] -meta: META地址(通常以`bdrive://`开头) +meta: META地址(通常以bdrive://开头) file: 另存为新的文件名, 不指定则保存为上传时的文件名 -f: 覆盖已有文件 @@ -72,7 +73,7 @@ file: 另存为新的文件名, 不指定则保存为上传时的文件名 ``` drive.py info [-h] meta -meta: META地址(通常以`bdrive://`开头) +meta: META地址(通常以bdrive://开头) ``` ### 查看历史记录 diff --git a/bilibili.py b/bilibili.py index d217fab..a1b06a6 100644 --- a/bilibili.py +++ b/bilibili.py @@ -35,7 +35,7 @@ def __init__(self): def _log(message): print(f"[{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}] {message}") - def _requests(self, method, url, decode_level=2, retry=10, timeout=15, **kwargs): + def _requests(self, method, url, decode_level=2, retry=0, timeout=10, **kwargs): if method in ["get", "post"]: for _ in range(retry + 1): try: diff --git a/drive.py b/drive.py index d9fa0b7..faac0e0 100644 --- a/drive.py +++ b/drive.py @@ -220,6 +220,9 @@ def write_history(first_4mb_sha1, meta_dict, url): if not os.path.exists(file_name): log(f"{file_name}不存在") return None + if os.path.isdir(file_name): + log("不支持上传文件夹") + return None log(f"上传: {os.path.basename(file_name)} ({os.path.getsize(file_name) / 1024 / 1024:.2f} MB)") first_4mb_sha1 = calc_sha1(read_in_chunks(file_name, chunk_size=4 * 1024 * 1024, chunk_number=1), hexdigest=True) history = read_history() @@ -372,7 +375,7 @@ def is_overwrite(file_name): if __name__ == "__main__": signal.signal(signal.SIGINT, lambda signum, frame: os.kill(os.getpid(), 9)) - parser = argparse.ArgumentParser(description="BiliDrive", epilog="By Hsury, 2019/11/3") + parser = argparse.ArgumentParser(description="BiliDrive", epilog="By Hsury, 2019/11/9") subparsers = parser.add_subparsers() history_parser = subparsers.add_parser("history", help="view upload history") history_parser.set_defaults(func=history_handle) diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..e9eb248 Binary files /dev/null and b/icon.ico differ