Coder Social home page Coder Social logo

waste2time / bili-sync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amtoaer/bili-sync

0.0 0.0 0.0 5.8 MB

基于 python asyncio 编写的 bilibili 收藏夹同步下载工具。

License: GNU General Public License v3.0

Python 96.66% Makefile 1.52% Dockerfile 1.82%

bili-sync's Introduction

bili-sync

简介

为 NAS 用户编写的 BILIBILI 收藏夹同步工具,可方便导入 EMBY 等媒体库工具浏览。

经常在点进自己的收藏夹时看到一大堆失效视频,简直逼死强迫症。想到自己 NAS 还有多余的 20T 存储空间,于是简单写了一个小工具用来实时把收藏夹内容同步下载到 NAS 上。

骄傲地由 python 驱动!

之前基本没有用过 python 的 asyncio,拿这个小工具练练手!(不是

工作截图

下载视频

EMBY 识别

配置文件

对于配置文件的前五项,请参考凭据获取流程

@dataclass
class SubtitleConfig(DataClassJsonMixin):
    font_name: str = "微软雅黑,黑体"  # 字体
    font_size: float = 40  # 字号
    alpha: float = 0.8  # 透明度
    fly_time: float = 5  # 滚动弹幕持续时间
    static_time: float = 10  # 静态弹幕持续时间

class Config(DataClassJsonMixin):
    sessdata: str = ""
    bili_jct: str = ""
    buvid3: str = ""
    dedeuserid: str = ""
    ac_time_value: str = ""
    interval: int = 20    # 任务执行的间隔时间
    path_mapper: dict[int, str] = field(default_factory=dict)  # 收藏夹的 id 到存储目录的映射
    subtitle: SubtitleConfig = field(default_factory=SubtitleConfig)  # 字幕相关设置

程序默认会将配置文件存储于 ${程序路径}/config/config.json,数据库文件存储于 ${程序路径}/data/data.db,如果发现不存在则新建并写入初始配置。

配置文件加载时会校验内容是否为空,对于默认的空配置,校验将会报错,程序将会终止运行。

即:我们可以通过运行一次程序,等程序写入初始配置并提示配置错误终止后编辑 config.json 文件,编辑后即可重新运行。

Docker 运行示例

docker compose 文件:

services:
  bili-sync:
    image: amtoaer/bili-sync:latest
    user: 1000:1000  # 此处可以指定以哪个用户的权限运行,不填写的话默认 root,推荐填写。
    tty: true  # 加上这一行可以让支持的终端以彩色显示日志(如果发现日志出现乱码就去掉)
    volumes:
      - /home/amtoaer/Videos/Bilibilis/:/Videos/Bilibilis/  # 视频文件
      - /home/amtoaer/.config/nas/bili-sync/config/:/app/config/  # 配置文件
      - /home/amtoaer/.config/nas/bili-sync/data/:/app/data/  # 数据库
      # 注:如需在 emby 内查看 up 主头像,需要将 emby 的 metadata/people/ 配置目录挂载至容器的 /app/thumb/
      - /home/amtoaer/.config/nas/emby/metadata/people/:/app/thumb/
    environment:
      - TZ=Asia/Shanghai
    restart: always
    network_mode: bridge
    hostname: bili-sync
    container_name: bili-sync
    logging:
      driver: "local"

对应的配置文件:

{
    "sessdata": "xxxxxxxxxxxxxxxxxx",
    "bili_jct": "xxxxxxxxxxxxxxxxxx",
    "buvid3": "xxxxxxxxxxxxxxxxxx",
    "dedeuserid": "xxxxxxxxxxxxxxxxxx",
    "ac_time_value": "xxxxxxxxxxxxxxxxxx",
    "interval": 20,
    "path_mapper": {
        "711322958": "/Videos/Bilibilis/Bilibili-711322958/"
    },
    "subtitle": {
        "font_name": "微软雅黑,黑体",
        "font_size": 40.0,
        "alpha": 0.8,
        "fly_time": 5.0,
        "static_time": 10.0
    }
}

支持的额外命令

为满足需要,该应用包含几个单独的命令,可在程序目录下使用 python entry.py ${command name} 运行。

  1. once

    处理收藏夹,和一般定时任务触发时执行的操作完全相同,但仅运行一次。

  2. recheck

    将本地不存在的视频文件标记成未下载,下次定时任务触发时将一并下载。

  3. refresh_refresh_poster

    更新本地视频的封面。

  4. refresh_upper

    更新本地up的头像和元数据。

  5. refresh_nfo

    更新本地视频的元数据。(如标签、标题等信息)

  6. refresh_video

    更新本地的视频源文件。

  7. refresh_subtitle

    更新本地的弹幕文件。

对于以 refresh 开头的命令,均支持 --force 参数,如果有 --force 参数,将全量覆盖对应内容,否则默认仅更新缺失的部分。

路线图

  • 凭证认证
  • 视频选优
  • 视频下载
  • 支持并发下载
  • 支持作为 daemon 运行
  • 构建 nfo 和 poster 文件,方便以单集形式导入 emby
  • 支持收藏夹翻页,下载全部历史视频
  • 对接数据库,提前检查,按需下载
  • 提供简单易用的打包(如 docker)

bili-sync's People

Contributors

amtoaer avatar ddsderek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.