这个文章打算是去年11月份写的,但是咕咕咕太舒服了....

那么教程开始?

需要准备东西

  • 服务器一台(Ubuntu 20.04)
  • Emby
  • OneDrive
  • qbittorrent
  • rclone挂载Onedrive用
  • python3 执行脚本用

这里我服务器买的是BuyVM家的,因为要下载种子硬盘要大不然一下子就吃满了有些资源

荷兰那台服务器自从黑五之后性能暴跌(


首先连接SSH

安装Emby服务端

这是官网 https://emby.media

点击Download按钮跳转下载页面
选择系统版本 这里我选择的是 Ubuntu X64

在ssh里面输入

wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.6.7.0/emby-server-deb_4.6.7.0_amd64.deb
//PS:Emby可能有变需要去官网自己复制链接

使用

dpkg -i emby-server-deb_4.6.7.0_amd64.deb
//PS:Emby可能有变需要去官网自己复制名字
这样就安装好了

接下来配置Emby服务器

浏览器打开 http://ip:8096

路过打不开请先检查防火墙是否放行了

打开后是这个界面

然后设置就行了 :P

遇到媒体库先不设置,后面把OneDrive挂载上再设置

有了上头这个界面就代表你的Emby安装完成了!


接下来装qbittorrent-nox

qbittorrent-nox是个网页版的qbittorrent可以RSS订阅动漫资源站点自动下载

首先先安装 qBittorrent PPA

Ubuntu自带的源那个版本太太老了连RSS都不支持(

sudo apt update
sudo apt upgrade
sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable
这里回车就行了
sudo apt -y install qbittorrent-nox 
//安装qbittorrent-nox

解决add-apt-repository: command not found

sudo apt-get install software-properties-common

然后使用

qbittorrent-nox
这里按y回车就行了

然后打开 http://ip:8080 设置 qbittorrent

用户名是 admin

密码是 adminadmin

注意一定要改密码哦

进入主界面后进入设置

密码在这里面更改

User Interface Language: 选择中文

界面就是中文的啦!

下载这样设置
下载种子可以这样设置

你服务器流量不限制的话也可以不设置做种子限制。

RSS这边这样子设置

这样 qbittorrent 设置告一段落....

然后把 qbittorrent 加入系统服务

用ctrl+c结束掉 qbittorrent 服务

然后

sudo nano /usr/lib/systemd/system/qbittorrent.service

把以下东西输入进去

[Unit]
Description=qBittorrent Daemon Service
After=network.target

[Service]
User=root
ExecStart=/usr/bin/qbittorrent-nox
ExecStop=/usr/bin/killall -w qbittorrent-nox

[Install]
WantedBy=multi-user.target

保存后,重新启动systemd 服务

sudo systemctl daemon-reload

然后设置让它开机自动启动

sudo systemctl enable qbittorrent

然后让 qbittorrent 启动

sudo systemctl start qbittorrent

接下来挂载OneDrive

在服务器上安装rclone

curl https://rclone.org/install.sh | sudo bash
这样就安装好了

接下来转到你的电脑上面来

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/。然后解压出来,比如我解压到D盘,文件夹命名rclone,此时点击Win+R,然后输入cmd,确定。再输入以下命令:

cd /d d:\rclone #rclone位置
rclone authorize "onedrive"

会出现以下信息:

PS D:\rclone-v1.57.0-windows-amd64> ./rclone authorize "onedrive"
2022/01/14 22:25:36 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=HCxu-zSH5J6a9FWiYAllNA
2022/01/14 22:25:36 NOTICE: Log in and authorize rclone for access
2022/01/14 22:25:36 NOTICE: Waiting for code...
2022/01/14 22:25:57 NOTICE: Got code
Paste the following into your remote machine --->
{""} ←这个要保存下来服务器要用到)

<---End paste

Rclone配置

初始化配置

rclone config
————————
root@localhost:~# rclone config
2022/01/14 09:27:58 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #选择n
name> onedrive #设置名字为onedrive 可自定义
Option Storage.
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ "fichier"
......
27 / Microsoft OneDrive
   \ "onedrive"
.....
45 / seafile
   \ "seafile"
Storage> 27 #27号是OneDrive 有可能会变 自行寻找
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> #回车
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> #回车
Option region.
Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value.
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 1 #选择1
Edit advanced config?
y) Yes
n) No (default)
y/n> n #选择n
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
y/n> n #选择n
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive"
Then paste the result.
Enter a string value. Press Enter for the default ("").
config_token> #这里填写你刚才在本地获取到的{"....."}
Option config_type.
Type of connection
Enter a string value. Press Enter for the default ("onedrive").
Choose a number from below, or type in an existing value.
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
   / Sharepoint site name or URL
 3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
   / Sharepoint server-relative path (advanced)
 7 | E.g. /teams/hr
   \ "path"
config_type> 1 #选择 1
Drive OK?

Found drive "root" of type "business"
URL: https://#
y) Yes (default)
n) No
y/n> y #选择y
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y #选择y

Current remotes:

Name                 Type
====                 ====
onedrive             onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q #退出

这样就在rclone上配置好了

接下来挂载

#新建本地文件夹,路径自己定,即下面的LocalFolder
mkdir /root/OneDrive
#挂载为磁盘,下面的DriveName、Folder、LocalFolder参数根据说明自行替换
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

DriveName为初始化配置填的nameFolderOneDrive里的文件夹,LocalFolderVPS上的本地文件夹。

如果挂载过程中出现NOTICE: One drive root 'test': poll-interval is not supported by this remote错误,可以无视该错误。

挂载成功后,输入df -h命令查看即可!

开机自启

先新建systemd配置文件

再使用命令:

#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command="mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000"
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

开始启动:

systemctl start rclone

开机启动:

systemctl enable rclone

其他命令:

重启:systemctl restart rclone
停止:systemctl stop rclone
状态:systemctl status rclone

到这里onedrive就挂着完成了

rclone挂载教程参考自在Debian/Ubuntu上使用rclone挂载OneDrive网盘 - Rat's Blog (moerats.com)

Opnevz不支持挂载

KVM遇到 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

apt install fuse

即可解决


接下来我们转到Emby那边

先进入设置里面添加媒体库

选择到OneDrive里面


接下来设置脚本这边

我用的python实现的

import getopt
import telebot
import os
from telebot import apihelper
import shutil
from urllib.parse import quote
import time

bot = telebot.TeleBot("xx:xx", parse_mode=None)
#apihelper.proxy = {'https':'socks5://127.0.0.1:8089'}


def guup():
    name = None
 
    argv = sys.argv[1:]
 
    try:
        opts, args = getopt.getopt(argv, "i:")  # 短选项模式
     
    except:
        print("Error")
 
    for opt, arg in opts:
        if opt in ['-i']:
            name = arg
    okname = name[16:len(name)]
    try:
        text = bot.send_message("@Gu_Fan","开始上传【"+okname+"】到 OneDrive 中...")
        #shutil.move(name,"/root/OneDrive/Bangumi")
        os.system('rclone copy "'+name+'" onedrive:/tmp')
        #bot.edit_message_text("【"+okname+"】上传完成!",text.chat.id, text.message_id)
        bot.reply_to(text, "【"+okname+"】上传完成!")
        #os.remove(name)
        os.system('mv "'+name+'" /Bangumi')
        time.sleep(10)
        outte = os.system('python3 "/py/list.py"')
        outtt =os.system("python3 '/gu/Episode-ReName/EpisodeReName.py' '/onedrive/Bangumi'")
        #bot.reply_to(text,outte)
    except Exception as err:
        bot.send_message("@Gu_Fan", err)
    #bot.send_message("@Gu_Fan", name)
    return name

#bot.send_message("@Gu_Fan", guup())
guup()

这样子完成的简单上传+通知

下面是分类脚本

import re
import os
import shutil


def fuzzyfinder(user_input, collection):
    suggestions = []
    pattern = '.*'.join(user_input) # Converts 'djm' to 'd.*j.*m'
    regex = re.compile(pattern)     # Compiles a regex.
    for item in collection:
        match = regex.search(item)  # Checks if the current item matches the regex.
        if match:
            suggestions.append(item)
    if suggestions != []:
        return suggestions
    else:
        return False

oklist = os.listdir("/onedrive/Bangumi")

dirlist = os.listdir("/onedrive/tmp")

for i in range(0,len(oklist)):
    listfil = fuzzyfinder(oklist[i], dirlist)
    if listfil != False:
        for b in range(0,len(listfil)):
            try:
                shutil.move("/onedrive/tmp/"+listfil[b],"/onedrive/Bangumi/"+oklist[i]+"/Season 1")
                #mvfillname = "/onedrive/tmp/"+listfil[b]
                #okdir = "/onedrive/Bangumi/"+oklist[i]+"/Season 1"
                #os.system('mv "'+name+'" /Bangumi')
                print("/onedrive/tmp/"+listfil[b]+"  转移成功")
            except:
                print("/onedrive/tmp/"+listfil[b]+"  转移失败")

print("执行完成!")

#oklist = os.listdir("/onedrive/Bangumi")

如果需要更细致分类集数需要

Nriver/Episode-ReName: 电视剧/番剧自动化重命名工具 (github.com)


番剧订阅(填坑ing)

「世界に忘れられた」
最后更新于 2023-07-11