Rat's

一个可以解决因api抽风出现空目录的OneDrive目录程序:OneList
说明:目前OneDrive目录程序已经很多了,比如:PyOne、OneIndex和OLAINDEX。这几个各有特色...
扫描右侧二维码阅读全文
05
2019/03

一个可以解决因api抽风出现空目录的OneDrive目录程序:OneList

说明:目前OneDrive目录程序已经很多了,比如:PyOneOneIndexOLAINDEX。这几个各有特色,都挺好用的,不过有时候api在高峰期抽风的时候,都很容易出现空目录的情况,导致下载会出现问题,这里萌咖sxyazi大佬就历时N天,写了个基于Python3的简约OneDrive目录列表,同时换了一种api来防止因使用人过多导致抽风等问题,稳定性大大的增加,而且使用Redis动态缓存策略,打开目录的速度是相当的快,不过该程序初衷只想安静的做个目录程序,所以是不会增加看视频的功能,如果你想看视频,那就选择开头的3个程序。

截图

请输入图片描述

安装

Github地址:https://github.com/0oVicero0/OneList/

说明:该程序不适用OneDrive个人版,且建议使用Debian系统安装,会很快。

1、安装依赖
CenOS 6系统:

#安装EPEL
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
#安装Python3和Redis
yum install python34 redis git -y
#安装pip3
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
#启动Redis
service redis start
#设置Redis开机自启
chkconfig redis on

CenOS 7系统:

#安装EPEL
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#安装Python3和Redis
yum install python36 redis git -y
#配置Python3软链接
ln -s /usr/bin/python3.6 /usr/bin/python3
#安装pip3
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
#启动Redis
systemctl start redis
#设置Redis开机自启
systemctl enable redis

Debian/Ubuntu系统:

#安装pip3和Redis
apt update
apt install python3-pip redis-server git -y

2、安装OneList

#拉取源码
git clone https://github.com/0oVicero0/OneList.git
#安装依赖
cd OneList && pip3 install -r requirements.txt

3、获取auth_token

提示:获取方式建议选择方法一。

方法一:直接访问地址→传送门,然后登录你的账号获取auth_token即可。

方法二:先使用浏览器访问该地址→传送门,登录你的OneDrive账号,复制地址栏code=&session之间的参数。

获取refresh_token,在SSH客户端使用命令:

#将下面auth_token替换成你获取到的参数,再使用命令
code="auth_token"
wget --no-check-certificate --post-data="client_id=ea2b36f6-b8ad-40be-bc0f-e5e4a4a7d4fa&client_secret=h27zG8pr8BNsLU0JbBh5AOznNS5Of5Y540l/koc7048=&grant_type=authorization_code&resource=https://api.office.com/discovery/&redirect_uri=http://localhost/onedrive-login&code=$code" 'https://login.microsoftonline.com/common/oauth2/token' -qO-

然后复制refresh_token参数后面的字段。

4、运行
接下来在OneList目录新建config.json配置文件。

nano config.json

将以下内容复制进去:

#将下面refresh_token替换成你获取到的字段
{
  "token": "<refresh_token>",
  "location_path": "/",
  "start_directory": "/",
  "threads": 3,
  "diff_seconds": 480,
  "refresh_seconds": 720,
  "metadata_cached_seconds": 768,
  "structure_cached_seconds": 840
}

再使用ctrl+xy保存退出。

开始运行:

gunicorn app:app -b 127.0.0.1:8888 -D

此时访问地址为127.0.0.1:8888,还需要使用域名反代才能访问,如果你要使用ip访问,将运行命令改成0.0.0.0:8888即可。

5、域名反代
安装Caddy

wget -N --no-check-certificate https://raw.githubusercontent.com/iiiiiii1/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh
#备用地址
wget -N --no-check-certificate https://www.moerats.com/usr/shell/Caddy/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh

配置Caddy

#以下全部内容是一个整体,请修改域名后一起复制到SSH运行!
echo "www.moerats.com {
 gzip
 tls admin@moerats.com
 proxy / 127.0.0.1:8888
}" > /usr/local/caddy/Caddyfile

该配置会自动签发SSL,请提前解析域名到VPS服务器。

启动Caddy

/etc/init.d/caddy start

就可以打开域名进行访问了。

最后如果你没有OneDrive大容量网盘可以申请1年开发者计划,申请地址→传送门

Vultr新用户注册送100美元/16个机房按小时计费,支持支付宝,【点击查看】。
最后修改:2019 年 06 月 17 日 04 : 07 PM

发表评论

84 条评论

  1. 无关风月

    请问如何设置开机自启动,刚接触linux

    1. Rat's
      @无关风月

      用个简单的,rc.local,参考这个文章https://www.moerats.com/archives/831/,替换命令就行了

  2. 麻豆

    宝塔面板,试了三遍,失败告终~,一直提示404

    1. Rat's
      @麻豆

      一般404就是refresh_token不对,或者说要更新了。

      1. 麻豆
        @Rat's

        宝塔面板是不是可以用python项目管理器这种方式搞啊,大佬有时间看看,感激不尽
        http://ww1.sinaimg.cn/large/ee1c0145gy1g6onlt852tj20ws0jmjtx.jpg

        1. Rat's
          @麻豆

          你试试,我没用过

  3. windxx

    运行gunicorn app:app -b 0.0.0.0:8888 -D没有错误提示,但是程序没跑起来,应该怎么查错啊...

    1. Rat's
      @windxx

      先不要-D参数,启动看看

  4. kenshin

    {"error":{"code":"serviceNotAvailable","message":"Service unavailable","retryAfterSeconds":120}}

    微软给我的解释是服务不可用,我两个5t号都是

    1. Rat's
      @kenshin

      我改了下文章,你用我提供的手动方法获取下refresh_token参数看看。

      1. kenshin
        @Rat's

        用方法一还是不行

  5. Linon

    博主啊,打开网站04 Site is not served on this interface
    E运行gunicorn app:app -b 127.0.0.1:8888显示
    xception in thread Thread-2:
    Traceback (most recent call last):
    File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner

    self.run()

    File "/usr/lib/python3.5/threading.py", line 862, in run

    self._target(*self._args, **self._kwargs)

    File "/root/OneList/process.py", line 40, in worker

    info = od.list_items_with_cache(c['full_path'], True)

    File "/root/OneList/onedrive.py", line 107, in list_items_with_cache

    Cache.set(key, self.list_items(path), 10)

    File "/root/OneList/onedrive.py", line 78, in list_items

    self._append_item(info, children)

    File "/root/OneList/onedrive.py", line 141, in _append_item

    'hash': self._get_item_hash(item),

    File "/root/OneList/onedrive.py", line 165, in _get_item_hash

    dic['folder'] = item['folder']

    KeyError: 'folder'

  6. Linon

    gunicorn app:app -b 127.0.0.1:8888 -D
    -bash: gunicorn: command not found
    不知道咋回事
    还有上边的Since Python 3.5, pip is already bundled with the python distribution, so you can just run python3.6 -m pip instead of pip.

    1. Rat's
      @Linon

      安装依赖那一步做了没?一般这个使用pip3 install gunicorn就可以了

  7. 小白

    安装后 宝塔面板打不开了怎么解决啊?

    1. Rat's
      @小白

      看下默认的python本,python -V,如果是python 3的话,试试这个命令:
      rm -rf /usr/bin/python
      ln -s /usr/bin/python2.7 /usr/bin/python
      然后重启bt 。

      1. 小白
        @Rat's

        [root@izt4ni0q7nfqv33tdbb4nwz ~]# /etc/init.d/bt restart
        Stopping Bt-Tasks... done
        Stopping Bt-Panel... done

        Starting Bt-Panel..........failed

        [Traceback (most recent call last):
        File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class

        mod = import_module('.'.join(components))

        File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module

        return _bootstrap._gcd_import(name[level:], package, level)

        File "<frozen importlib._bootstrap>", line 994, in _gcd_import
        File "<frozen importlib._bootstrap>", line 971, in _find_and_load
        File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 994, in _gcd_import
        File "<frozen importlib._bootstrap>", line 971, in _find_and_load
        File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
        File "<frozen importlib._bootstrap>", line 994, in _gcd_import
        File "<frozen importlib._bootstrap>", line 971, in _find_and_load
        File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
        ModuleNotFoundError: No module named 'geventwebsocket'
        ]

        Error: BT-Panel service startup failed.

        done

        Starting Bt-Tasks... Bt-Tasks (pid 18547) already running

        执行后是这样的

  8. 倚栏听风

    在执行python3 get-pip.py时,报错-bash: python3: command not found
    请问是什么原因呀

    1. Rat's
      @倚栏听风

      python3没安装,检查下哪步没做

  9. xydcz6

    可以加密码吗,

    1. Rat's
      @xydcz6

      通过程序不行,通过caddy,nginx啥得可以,不过一加密整个站点都加密。

      1. xydcz6
        @Rat's

        好的

  10. bingchuan

    支持多盘么?或者未来会支持多盘么?

    1. Rat's
      @bingchuan

      不会支持多盘