Centos 7 配置 FlexGet

标签: none

FlexGet 的用途主要是订阅网站最新 Free 的种子并自动下载。可以直接传给 qBittorrent, Deluge, transmission 客户端进行下载。

准备工作

  1. Python 3.6 and higher (Python 3.10)
  2. pip3 (pip 22.0.2)
  3. FlexGet 3.2.16 (2022-01-27)
  4. transmission-rpc (3.3.0)

安装

# 安装 FlexGet
pip3 install flexget

# 更新 FlexGet
pip3 install --upgrade flexget

# 删除 transmissionrpc (0.11)
pip3 uninstall transmissionrpc

# 安装 transmission-rpc (3.3.0)
pip3 install transmission-rpc

# 创建配置文件夹
mkdir -p /home/flexget/.config/flexget

# 创建日志文件并设置权限 (不然反代看不到日志)
touch /home/flexget/.config/flexget/flexget.log
chmod 640 /home/flexget/.config/flexget/flexget.log

# 查看版本号
[root@centos7 ~]# flexget --version
3.2.16
You are on the latest release.

创建默认配置

[root@centos7 ~]# vim /home/flexget/.config/flexget/config.yml
templates:
  # 剩余空间模板,当配置的 path 路径的剩余空间小于 space 规定的数值时,停止 RSS 下载
  freespace:
    free_space:
      path: /home/flexget
      space: 10240
  qb:
    qbittorrent:
      path: /home/flexget/qbittorrent/download/
      host: localhost
      port: 2017
      username: flexget
      password: 51522zzwlwlbb
  tr:
    transmission:
      path: /home/flexget/transmission/download/
      host: localhost
      port: 9099
      username: flexget
      password: 51522zzwlwlbb
  de:
    deluge:
      path: /home/flexget/deluge/download/
      host: localhost
      port: 58846
      username: flexget
      password: 51522zzwlwlbb
  # 体积过滤模板,min 是符合条件的最小种子体积,max 是符合条件的最大种子体积,单位均为 MB
  # strict 默认是 yes,表示在无法确定大小的情况下就不下载,这里把它改成 no 了
  # 这段 size 的意思是,只下载体积为 6000-666666 MB 的种子,其他不满足条件的种子不下载
  size:
    content_size:
      min: 6000
      max: 666666
      strict: no
tasks:
  PT-HDSky-WEB:
    rss: https://hdsky.me/torrentrss.php
    # 因为 HDSWEB 发单集的时候用的标题是一样的, 因此下过一次后
    # 之后新发出来的单集由于标题一样,flexget 会当成是以前已经下过的种子
    # 为了避免这个问题,对 seen 插件设定为只检查 url 是否一致
    seen:
      fields:
        - url
    # 正则表达式;标题带 HDSWEB 的种子就下载(accept,接受),不想下载的话就写拒绝(reject)
    regexp:
      accept:
        - HDSWEB
    # 调用上边的 de 模板
    template: de
    # 可以不使用模板的体积过滤,针对每个任务单独设置体积过滤
    content_size:
      min: 3000
      max: 500000
      strict: no
    # 以下设定实现的效果:对这个任务加载到 deluge 的种子,自动添加 WEB-DL 的标签
    # 自动限制上传速度到 10MB/s(防止超速),下完后自动移动到 /mnt/HDSky/HDSWEB
    deluge:
      label: WEB-DL
      # Limit upload speed to 100 MiB/s in case of being auto-banned
      max_up_speed: 102400
      move_completed_path: /mnt/HDSky/HDSWEB
  ADC-AnimeBD-JPN:
    rss: http://asiandvdclub.org/rss.xml
    # 这三个过滤条件组合起来就是,下载标题里带 Anime 和 AVC 且不含 subs only 的种子
    # 并排除掉描述里含有 Custom 的种子
    # 这也就约等于,RSS 日版动画蓝光碟(非日版、DIY 碟、DVD 都过滤掉)
    if:
      - "'Anime' and 'AVC' in title": accept
      - "'subs only' in title": reject
      - "'Custom' in description": reject
    # RSS ADC 需要 Cookies,这里我们用 headers 插件来加上 cookies
    headers:
      Cookie: "uid=12345; pass=abcdefg"
    # 转换 RSS 链接,将原本形如 http://asiandvdclub.org/details.php?id=123456 的种子描述页面链接
    # 替换为形如 http://asiandvdclub.org/download.php?id=123456 的种子下载链接
    urlrewrite:
      sitename:
        regexp: 'http://asiandvdclub.org/details.php\?id=(?P<id>\d+)'
        format: 'http://asiandvdclub.org/download.php?id=\g<id>'
    qbittorrent:
      label: ADC
      # Flexget 支持添加种子到 qBittorrent 的时候自动设定单种限速
      maxdownspeed: 30000
  btschool:
    rss: https://pt.btschool.club/torrents.php
    # 把 RSS 链接里的所有种子都下载下来,不做过滤
    accept_all: yes
    template:
      - freespace
      - size
      - tr
web_server:
  web_ui: yes
  base_url: /flexget
  bind: 127.0.0.1
  port: 6566

# schedules is disabled by default, you need to enable it or use cron to RSS
schedules: no

Web UI 设置

设置 webui 密码

[root@centos7 ~]# flexget web passwd 51522zzwlwlbb

Flexget WebUI 设定

[root@centos7 ~]# vim /home/flexget/.config/flexget/config.yml
web_server:
  web_ui: yes
  base_url: /flexget
  bind: 127.0.0.1
  port: 6566
# base_url 是为了反代设置的,需要使用反代的话就取消这个的注释,然后在安装了 rTorrent 的情况下(不装 rt 的话没有 nginx)
# Flexget WebUI 地址就变成了 https://IP/flexget

nginx 反代设置

[root@centos7 ~]# vim /etc/nginx/conf.d/flexget.conf
location /flexget/ {
    proxy_redirect off;
    proxy_pass http://127.0.0.1:6566/flexget/;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host \$server_name:\$server_port;
    http2_push_preload on;

    # Show realip in flexget access.log
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

创建系统服务

cat>>/etc/systemd/system/flexget.service<<EOF
[Unit]

Description=flexget Daemon
After=network.target

[Service]
User=flexget
Group=flexget
ExecStart=`which flexget` daemon start
ExecStartPre=/bin/rm -f /home/flexget/.config/flexget/.config-lock
ExecStop=`which flexget` daemon stop
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

重新载入 / 开机启动 flexget / 启动 flexget / 查看 flexget 状态

systemctl daemon-reload
systemctl enable flexget
systemctl start flexget
flexget daemon status

定时任务

flexget 自带定时任务

所有任务 60分钟执行一次

schedules:
  - tasks: '*'
    interval:
      minutes: 60

任务名: task_name 15分钟执行一次

schedules:
  - tasks: 'task_name'
    interval:
      minutes: 15

对不同任务设置不同的执行时间

schedules:
  - tasks: 'Update-Queue'
    interval:
      hours: 3
  - tasks: 'Series-*'
    interval:
      minutes: 30
  - tasks: 'Movies-*'
    interval:
      hours: 1
  - tasks: 'Update-trakt-*'
    interval:
      days: 1
      at_time: 4:43 am
  - tasks: [HDC, btschool]
    interval:
      minutes: 30

如果不配置 Schedule 也可以通过 cron 命令来定时执行,比如每隔 5 分钟执行一次

[root@centos7 ~]# crontab -e
*/5 * * * * /usr/bin/flexget --cron execute

常用命令

  • flexget check : 用于检查 config.yml 配置文件是否有格式错误。
  • flexget --test execute : 手动模拟一次 RSS 操作,仅供测试,不会下载种子文件到本地。
  • flexget execute : 手动执行所有任务
  • flexget execute --tasks Series-*: 手动执行指定的任务
  • flexget status : 查看 flexget 的 RSS 记录。
  • flexget execute --learn : 这样子不会下载种子,但是会把这次 RSS
    到的种子标记为已下载,这样之后就不会下到老种了

更多任务模板

templates:
  # freespace 插件
  freespace:
    free_space:
      path: /data
      space: 10240
  qb:
    qbittorrent:
      path: /data
      host: localhost
      port: 8080
      username: admin
      password: password
  de:
    deluge:
      password: "deluge"
      path: /data
  tr:
    transmission:
      host: localhost
      port: 9091
      username: admin
      password: "password"
tasks:
  BTSchool:
    rss: https://pt.btschool.net/torrentrss.php
    accept_all: yes
    template:
      - de
  HDChina:
    rss: https://hdchina.org/torrentrss.php
    accept_all: yes
    template:
      - qb
    qbittorrent:
      label: HDChina
  CHDBits:
    rss: https://chdbits.co/torrentrss.php
    accept_all: no
    if:
      - "'CHDPAD' in title": reject
      - "'CHDPad' in title": reject
      - "'CHD' in title": accept
    template:
      - tr
  U2:
    rss: https://u2.dmhy.org/torrentrss.php
    accept_all: no
    regexp:
      accept_excluding:
        - DVD
        - ADC
        - TTG
        - TSDM
      from: title
    download: /data/torrent/
  Mteam:
    rss: https://tp.m-team.cc/torrentrss.php
    accept_all: no
    regexp:
      accept:
        - sweety
      from: title
    download: /data/torrent/
  GZtown:
    rss: https://pt.gztown.net/torrentrss.php
    accept_all: no
    if:
      - "'GZtown' in title": accept
    download: /data/torrent/
  HDSky:
    rss: https://hdsky.me/torrentrss.php
    accept_all: yes
    download: /data/torrent/
  Ourbits:
    rss: https://ourbits.club/torrentrss.php
    accept_all: yes
    download: /data/torrent/
  ezrss:
    rss: http://eztv.ag/ezrss.xml
    accept_all: yes
    content_size:
      min: 200
      max: 4444
      strict: no
    download: /data

扫描二维码,在手机上阅读!

添加新评论