标签: qBittorrent

  • Watchtower – 如何优雅地刷 PT

    Watchtower – 如何优雅地刷 PT

    [start-plane type=”2″]转载至:DOV ,原文地址:如何优雅地刷 PT [/start-plane]

    前言

    各大 PT 站一直是我下载高清影视资源、动漫 BD 的好帮手,玩了几年了,虽然没买啥设备,但是当刷子还是有了不少经验(PT(英语:Private Tracker)是一种改良自 BitTorrent 协议 的P2P下载方式,“Private Tracker”指私有种子服务器。与 BT 最大的不同点为:可进行私密范围下载,并且记录每一个用户的详细数据。

    From Wikipedia

    [icon-url href=”https://github.com/Aniverse/inexistence” target=”_blank”]inexistence[/icon-url]

    以前刷 PT 都是用的星大的一键脚本,安装好后就基本上有了需要的环境,自己在安装一下Autoremove-torrents,基本可以满足我的需求。

    不过每次更换服务器都需要很多时间再次编译安装,总归还是麻烦了。最近发现了一个 大佬的项目,基本上把自动 RSS 免费热种、自动删除旧种子、自动签到做齐了,功能十分强大。

    我最终采用的是 qBittorrent+Flexget 的方案,用 Docker 搭建,上述大佬的项目为 Flexget 插件。

    qBittorrent

    由于用 Deluge 总是把机器刷死机,可能是 3O 配置太差了。。。所以我就改用 qBittorrent 了。同时也建议将 Flexget 搭建在不同的机器,因为 Flexget 也很吃内存和 CPU(毕竟是万恶的 Python)。

    首先安装好 Docker Docker Compose,这里就不赘述。

    然后写docker-compose.yml

    version: '3'
    
    services:
      qbittorrent:
        image: linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73
        container_name: qbittorrent
        restart: unless-stopped
        ports:
          - 8080:8080
          - 53168:53168/udp
          - 53168:53168
        environment:
          PUID: 1000
          PGID: 1000
          TZ: Asia/Shanghai
          UMASK_SET: 022
          WEBUI_PORT: 8080
        volumes:
          - /path/to/config:/config
          - /path/to/downloads:/downloads

    注意 qBittorrent 要看你的 PT 站具体要求什么版本,我用的是 4.2.3,其他的可以去 这里 查。

    然后输入命令:

    docker-compose up -d

    登录 qBittorrent 的 Web 后记得将用于传入连接的端口改为53168

    Flexget

    Flexget 安装

    在一台配置较好的 VPS 上(我用的是 GCP)安装Flexget

    docker-compose.yml

    version: '3'
    
    services:
      flexget:
        image: madwind/flexget
        container_name: flexget
        restart: unless-stopped
        ports:
          - 3539:3539
        environment:
          PUID: 1000
          PGID: 1000
          TZ: Asia/Shanghai
          FG_WEBUI_PASSWD: password  # 替换为你自己的密码,登录 Web 用
          FG_LOG_LEVEL: INFO
        volumes:
          - /path/to/config:/config
        logging:
          driver: "json-file"
          options:
            max-size: "200k"
    
      standalone-chrome:
        image: selenium/standalone-chrome
        container_name: standalone-chrome
        restart: unless-stopped
        ports:
          - 4444:4444
        shm_size: '2gb'

    然后输入命令:

    docker-compose up -d

    Flexget将监听在 3539 端口。

    Flexget 安装插件

    Flexget 的插件安装十分简单,只需要把文件丢进插件文件夹即可。

     config 文件夹下创建名为 plugins 的文件夹,并将 这个项目 的所有 .py 文件和 ptsites 文件夹丢进去,并将 另一个项目 nexusphp.py丢进去。

    然后重新启动Flexget

    docker restart flexget

    Flexget 配置

    以下是我的 Flexget 配置文件的示例:

    web_server:
      bind: '0.0.0.0'
      port: 3539
    
    schedules:
      - tasks: [U2, MTeam]
        interval:
          minutes: 1
    
      - tasks: [ol_resume, nas_resume, ol_delete, nas_delete, ol_modify, nas_modify, ol_clean, nas_clean]
        interval:
          minutes: 5
      
      - tasks: [sign_in]
        schedule:
          hour: 8-23/1
    
    variables:
      headers:
        user_agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'
    
    templates:
      ## Online
      # 从 qBittorrent 获取数据
      ol_from_qbittorrent_template:
        from_qbittorrent_mod: &ol_from_qbittorrent_mod
          host: <OL_HOST>
          port: <OL_PORT>
          use_ssl: false
          username: <OL_USERNAME>
          password: <OL_PASSWORD>
    
      # 基础
      ol_qbittorrent_base_template:
        qbittorrent_mod:
          <<: *ol_from_qbittorrent_mod
    
      # 添加
      ol_qbittorrent_add_template:
        qbittorrent_mod:
          action:
            add:
              category: RSS
              autoTMM: yes
              reject_on:
                dl_limit: 5242880
                dl_speed: no
    
      # 删除
      ol_qbittorrent_delete_keeper_template:
        qbittorrent_mod:
          action:
            remove:
              keeper:
                delete_files: yes
                keep_disk_space: 36
                dl_limit_interval: 900
      
      ## NAS
      # 从 qBittorrent 获取数据
      nas_from_qbittorrent_template:
        from_qbittorrent_mod: &nas_from_qbittorrent_mod
          host: <NAS_HOST>
          port: <NAS_PORT>
          use_ssl: false
          username: <NAS_USERNAME>
          password: <NAS_PASSWORD>
    
      # 基础
      nas_qbittorrent_base_template:
        qbittorrent_mod:
          <<: *nas_from_qbittorrent_mod
    
      # 添加
      nas_qbittorrent_add_template:
        qbittorrent_mod:
          action:
            add:
              category: RSS
              autoTMM: yes
              reject_on:
                dl_limit: no
                dl_speed: no
      
      # 删除
      nas_qbittorrent_delete_keeper_template:
        qbittorrent_mod:
          action:
            remove:
              keeper:
                delete_files: yes
                keep_disk_space: 90
                alt_dl_limit_on_succeeded: 5242880
                dl_limit_interval: 900
    
      ## 多种操作
      # 清理
      qbittorrent_delete_cleaner_template:
        qbittorrent_mod:
          action:
            remove:
              cleaner:
                delete_files: yes
    
      # 修改
      qbittorrent_modify_template:
        qbittorrent_mod:
          action:
            modify:
              tag_by_tracker: true
    
      # 恢复
      qbittorrent_resume_template:
        qbittorrent_mod:
          action:
            resume:
              recheck_torrents: true
    
      # 种子大小筛选
      content_size:
        content_size:
          min: 10
          max: 50000
          strict: no
    
    tasks:
      U2:
        rss: 
          url: https://u2.dmhy.org/torrentrss.php?rows=50&trackerssl=1&passkey=<PASSKEY>&linktype=dl
          other_fields:
            - link
        nexusphp:
          cookie: '<U2_COOKIE>'
          user-agent: '{? headers.user_agent ?}'
          comment: yes
          discount:
            - free
            - 2xfree
          seeders:
            min: 1
        verify_ssl_certificates: no
        content_size:
          min: 10
          max: 120000
          strict: no
        template:
          - nas_qbittorrent_base_template
          - nas_qbittorrent_add_template
    
      MTeam:
        rss: https://pt.m-team.cc/
        accept_all: true
        verify_ssl_certificates: no
        content_size:
          min: 10
          max: 50000
          strict: no
        template:
          - ol_qbittorrent_base_template
          - ol_qbittorrent_add_template
    
      resume: &resume
        priority: 2
        disable: [seen, seen_info_hash, retry_failed]
        if:
          - qbittorrent_state == 'pausedUP' and qbittorrent_downloaded == 0 and qbittorrent_added_on > now - timedelta(hours=1): accept
    
      delete: &delete
        priority: 3
        disable: [seen, seen_info_hash, retry_failed]
        if:
          - qbittorrent_category in ['RSS'] and (qbittorrent_last_activity < now - timedelta(days=2) or qbittorrent_added_on < now - timedelta(days=7)): accept
          - qbittorrent_state == 'missingFiles' or (qbittorrent_state in ['pausedDL'] and qbittorrent_completed == 0): accept
        sort_by: qbittorrent_last_activity
    
      modify: &modify
        priority: 4
        disable: [seen, seen_info_hash, retry_failed]
        accept_all: yes
    
      clean: &clean
        priority: 5
        disable: [seen, seen_info_hash, retry_failed]
        regexp:
          accept:
            - '[Tt]orrent not registered with this tracker'
            - 'Torrent banned'
            - 'Unregistered torrent'
          from: qbittorrent_tracker_msg
    
      ol_resume:
        <<: *resume
        template:
          - ol_from_qbittorrent_template
          - ol_qbittorrent_base_template
          - qbittorrent_resume_template
      
      nas_resume:
        <<: *resume
        template:
          - nas_from_qbittorrent_template
          - nas_qbittorrent_base_template
          - qbittorrent_resume_template
    
      
      ol_delete:
        <<: *delete 
        template:
          - ol_from_qbittorrent_template
          - ol_qbittorrent_base_template      
          - ol_qbittorrent_delete_keeper_template
      
      nas_delete:
        <<: *delete
        template:
          - nas_from_qbittorrent_template
          - nas_qbittorrent_base_template
          - nas_qbittorrent_delete_keeper_template
      
      ol_modify:
        <<: *modify
        template:
          - ol_from_qbittorrent_template
          - ol_qbittorrent_base_template
          - qbittorrent_modify_template
      
      nas_modify:
        <<: *modify
        template:
          - nas_from_qbittorrent_template
          - nas_qbittorrent_base_template
          - qbittorrent_modify_template
    
      ol_clean:
        <<: *clean
        template:
          - ol_from_qbittorrent_template
          - ol_qbittorrent_base_template
          - qbittorrent_delete_cleaner_template
      
      nas_clean:
        <<: *clean
        template:
          - nas_from_qbittorrent_template
          - nas_qbittorrent_base_template
          - qbittorrent_delete_cleaner_template
      
      # 自动签到
      sign_in:
        auto_sign_in:
          user-agent: '{? headers.user_agent ?}'
          # command_executor: 'http://standalone-chrome:4444/wd/hub'
          max_workers: 4
          # baidu ocr 参数
          aipocr:
            app_id: '<BAIDU_APP_ID>'
            api_key: '<BAIDU_API_KEY>'
            secret_key: '<BAIDU_SECRET_KEY>'
          sites:
            pthome: '<PTHOME_COOKIE>'
        accept_all: yes
        seen:
          fields:
            - title

    [c-alert type=”warning”]注意:[/c-alert]

    • 自行将形如 <foobar> 的变量替换为自己的信息,关于 Cookie 的获取可以看 此教程
    • 务必要申请自行 Baidu OCR,申请网址: 百度 AI 开放平台
    • 自动签到已经适配的站点可在 此文件夹 中找到。
    • 如无其他需求可直接用我的配置,否则请自行参考 项目 wiki

    这样子 Flexget 就会定时自行下载 PT 站的免费种子、自行删除旧种,全自动辅种,还能够帮我们签到等,无需其他额外的软件。

    qBittorrent不建议经常更新。如果需要自动更新 Flexget,可以用Watchtower

    docker run -d \
        --name watchtower \
        --restart unless-stopped \
        -e TZ=Asia/Shanghai \
        -v /var/run/docker.sock:/var/run/docker.sock \
        containrrr/watchtower \
        --cleanup

    后记

    经过这一波折腾,可以说是彻底的解放了双手,同时有需要的话还可以用 TG 通知签到情况、机器占用情况等,可以说是十分好用了。

    感谢各位大佬们写的好用的插件~