BGmi is a cli tool for subscribed bangumi.
Project description
BGmi
BGmi is a cli tool for subscribed bangumi.
TODO
Update Log
V4
- new WEB UI
- rename option
transmission.rpc_url
totransmission.rpc_host
. - fix transmission default config.
V3
- add
global_include_keywords
option - add
save_path_map
option for per-bangumi save path - Use TOML as config file language
- Remove Python3.7 support
- Remove Python3.6 support as it has reached its end-of-life
- Allow adding new download delegate without modifying the source code
- Remove xunlei-lixian support
- New download delegate qbittorrent-webapi
- Remove Python2 support
- Transmission RPC authentication configuration
- New download delegate deluge-rpc
- You can filter search results by min and max episode
more details can be found at releases and unreleased changelog
Feature
- Multi data sources supported: bangumi_moe, mikan_project or dmhy
- Use aria2, transmission, deluge or qbittorrent to download bangumi
- Web interface to manage bangumi with HTTP API
- Play bangumi online with danmaku
- RSS feed for uTorrent, ICS calendar for mobile devices
- Bangumi Script: Write your own bangumi parser!
- Bangumi calendar / episode information
- Keyword, subtitle group, regular expression filters for download bangumi
- Windows, Linux and Router system supported, BGmi everywhere
Installation
Using pip:
pip install bgmi
Or from source(not recommended):
git clone https://github.com/BGmi/BGmi
cd BGmi
python -m pip install -U pip
pip install .
Init BGmi database and install BGmi web interface:
bgmi install
Upgrade
pip install bgmi -U
bgmi upgrade
Make sure to run bgmi upgrade after you upgrade your bgmi
Docker
go to BGmi/bgmi-docker-all-in-one
Usage of bgmi
Cli completion(bash and zsh. Shell was detected from your env $SHELL)
eval "$(bgmi complete)"
If you want to setup a custom BGMI_PATH instead of default $HOME/.bgmi
:
BGMI_PATH=/bgmi bgmi -h
Or add this code to your .bashrc file:
alias bgmi='BGMI_PATH=/tmp bgmi'
Supported data source:
Help
you can add --help
to all BGmi
sub command to show full options, some of them are not mentioned here.
Show BGmi configure
bgmi config
There are two ways to configure BGmi, configuration files and environment variables.
Configuration file
bgmi config files is located at ${BGMI_PATH}/config.toml
Example of configure file:
data_source = "bangumi_moe" # bangumi source
download_delegate = "aria2-rpc" # download delegate
tmp_path = "tmp/tmp" # tmp dir
save_path = "tmp/bangumi" # dir to save bangumi video files
front_static_path = "tmp/front_static" # dir to save webui static files
db_path = "tmp/bangumi.db" # file path of bangumi sqlite database
script_path = "tmp/scripts" # tools for bgmi scripts
tools_path = "tmp/tools" # tmp dir to download some binary tools
max_path = 3 # max page for fetching bangumi information
bangumi_moe_url = "https://bangumi.moe"
share_dmhy_url = "https://share.dmhy.org"
mikan_username = "" # The username for Mikan Project website
mikan_password = "" # The password for Mikan Project website
lang = "zh_cn" # banugmi moe lang filter
enable_global_filters = true
global_filters = [
"Leopard-Raws",
"hevc",
"x265",
"c-a Raws",
"U3-Web",
]
[save_path_map] # per-bangumi save path
'致不灭的你 第二季' = '/home/trim21/downloads/bangumi/致不灭的你/s2/' # abs path may not work with web-ui
'致不灭的你 第三季' = './致不灭的你/s3/' # relative related to save_path
[http]
admin_token = "dYMj-Z4bDRoQfd3x" # web admin token, generated on install
danmaku_api_url = ""
serve_static_files = false # serve static files with python server, used in bgmi_http
[aria2]
rpc_url = "http://localhost:6800/rpc"
rpc_token = "token:"
[transmission]
rpc_host = "127.0.0.1"
rpc_port = 9091
rpc_username = "your_username"
rpc_password = "your_password"
rpc_path = "/transmission/rpc" # http url path of transmission rpc requests
[qbittorrent]
rpc_host = "127.0.0.1"
rpc_port = 8080
rpc_username = "admin"
rpc_password = "adminadmin"
category = ""
[deluge]
rpc_url = "http://127.0.0.1:8112/json"
rpc_password = "deluge"
Environment Variables
When BGmi’s configuration file has not been initialized, the configuration parameters can be configured by environment variables.
Environment variables start with BGMI_
, are named in all uppercase letters, and are separated by _
for each level of configuration, such as:
BGMI_DATA_SOURCE=bangumi_moe # means data_source = "bangumi_moe" in the configuration file
BGMI_HTTP_ADMIN_TOKEN=dYMj-Z4bDRoQfd3x # means admin_token = "dYMj-Z4bDRoQfd3x" in the [http] section of the configuration file
...
Environment variables do not support configuring the following items:
enable_global_include_keywords
enable_global_filters
global_include_keywords
global_filters
[save_path_map]
Note: After the configuration file is generated, running configuration will be based on the configuration file, and environment variables are only used to generate the first configuration file.
Change data source
All bangumi info in database will be deleted when changing data source! but scripts won't be affected
video files will still be stored on the disk, but won't be shown on website.
If the source to be switched is mikan_project
, please configure MIKAN_USERNAME
and MIKAN_PASSWORD
first, other
sources are not affected.
bgmi source mikan_project
download delegate
download_delegate = "aria2-rpc" # download delegate
supported options are aria2-rpc
, transmission-rpc
, qbittorrent-webapi
and deluge-rpc
Show bangumi calendar
bgmi cal
Subscribe bangumi
bgmi add "Re:CREATORS" "夏目友人帐 陆" "进击的巨人 season 2"
bgmi add "樱花任务" --episode 0
Default episode will be the latest episode.
If you just add a bangumi that you haven't watched any episodes, considering bgmi add $BANGUMI_NAME --episode 0
.
Unsubscribe bangumi
bgmi delete --name "Re:CREATORS"
Update bangumi
Update bangumi database (which locates at ~/.bgmi/bangumi.db acquiescently):
bgmi update --download # download all undownloaded episode fo all followed bangumi
bgmi update "从零开始的魔法书" --download 2 3 # will download specific episide 2 and 3
bgmi update "时钟机关之星" --download # will download all undownloaded episode for specific bangumi
Filter download
Set up the bangumi subtitle group filter and fetch entries:
bgmi list
bgmi fetch "Re:CREATORS"
# include and exclude are case insensitive.
# --include '720p' is equal to --include '720P'
bgmi filter "Re:CREATORS" --subtitle "DHR動研字幕組,豌豆字幕组" --include 720P --exclude BIG5
bgmi fetch "Re:CREATORS"
# remove subtitle, include and exclude keyword filter and add regex filter.
bgmi filter "Re:CREATORS" --subtitle "" --include "" --exclude ""
bgmi filter "Re:CREATORS" --regex "(DHR動研字幕組|豌豆字幕组).*(720P)"
bgmi fetch "Re:CREATORS"
Global Filter
include
You can set global include keywords.
It's disabled by default, You need to enable global include keywords with enable_global_include_keywords = true
enable_global_include_keywords = true
global_include_keywords = ['1080']
exclude
Some words are pre-set as global exclude keywords
You can disable global filter with enable_global_filters = false
.
enable_global_filters = true
global_filters = [
"Leopard-Raws",
"hevc",
"x265",
"c-a Raws",
"U3-Web",
]
Search episodes
bgmi search '为美好的世界献上祝福!' --regex-filter '.*动漫国字幕组.*为美好的世界献上祝福!.*720P.*'
# download
bgmi search '为美好的世界献上祝福!' --regex-filter '.*合集.*' --download
Modify downloaded bangumi episode
bgmi list
bgmi mark "Re:CREATORS" 1
This will tell bgmi to not need to download episode less than or equal to 1.
Manage download items
bgmi download --list
bgmi download --list --status 0
bgmi download --mark 1 --status 2
Status code:
- 0 - Not downloaded items
- 1 - Downloading items
- 2 - Downloaded items
Usage of bgmi_http
Download all bangumi cover first:
bgmi cal --download-cover
Download frontend static files(you may have done it before):
bgmi install
Start BGmi HTTP Service bind on 0.0.0.0:8888:
bgmi_http --port=8888 --address=0.0.0.0
Use bgmi_http on Windows
Just start your bgmi_http and open http://localhost:8888/ in your browser.
Consider most people won't use Nginx on Windows, bgmi_http use tornado.web.StaticFileHandler to serve static files( frontend, bangumi covers, bangumi files) without Nginx.
Use bgmi_http on Linux
Generate Nginx config
bgmi gen nginx.conf --server-name bgmi.whatever.com > bgmi.whatever.com
Or write your config file manually.
server {
listen 80;
server_name bgmi;
root /path/to/bgmi;
autoindex on;
charset utf-8;
location /bangumi {
# ~/.bgmi/bangumi
alias /path/to/bangumi;
}
location /api {
proxy_pass http://127.0.0.1:8888;
# Requests to api/update may take more than 60s
proxy_connect_timeout 500s;
proxy_read_timeout 500s;
proxy_send_timeout 500s;
}
location /resource {
proxy_pass http://127.0.0.1:8888;
}
location / {
# ~/.bgmi/front_static/;
alias /path/to/front_static/;
}
}
Of cause you can use yaaw to manage download items if you use aria2c to download bangumi.
location /yaaw {
alias /path/to/yaaw;
}
location /jsonrpc {
# aria2c rpc
proxy_pass http://127.0.0.1:6800;
}
Example file: bgmi.conf
DPlayer and Danmaku
BGmi use DPlayer to play bangumi.
First, setup nginx to access bangumi files. Second, choose one danmaku backend at DPlayer#related-projects.
Edit bgmi config file to setup the url of danmaku api.
[bgmi_http]
danmaku_api_url = "https://api.prprpr.me/dplayer/" # This api is provided by dplayer official
...restart your bgmi_http and enjoy :D
macOS launchctl service controller
see issue #77
Bangumi Script
Bangumi Script is a script which you can write the bangumi parser own. BGmi will load the script and call the method you write before the native functionality.
Bangumi Script Runner will catch the data you returned, update the database, and download the bangumi. You only just write the parser and return the data.
Bangumi Script is located at BGMI_PATH/script, inherited ScriptBase class.
examples: script_example.py
get_download_url
returns a dict as follows.
{
1: 'http://example.com/Bangumi/1/1.torrent',
2: 'http://example.com/Bangumi/1/2.torrent',
3: 'http://example.com/Bangumi/1/3.torrent'
}
The keys 1, 2, 3 is the episode, the value is the url of bangumi, make sure your download delegate support it..
BGmi Data Source
You can easily add your own BGmi data source by extending BGmi website base class and implement all the method.
from typing import List, Optional
from bgmi.website.base import BaseWebsite
from bgmi.website.model import WebsiteBangumi, Episode
class DataSource(BaseWebsite):
def search_by_keyword(
self, keyword: str, count: int
) -> List[Episode]: # pragma: no cover
"""
:param keyword: search key word
:param count: how many page to fetch from website
:return: list of episode search result
"""
raise NotImplementedError
def fetch_bangumi_calendar(self, ) -> List[WebsiteBangumi]: # pragma: no cover
"""
return a list of all bangumi and a list of all subtitle group
list of bangumi dict:
update time should be one of ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Unknown']
"""
raise NotImplementedError
def fetch_episode_of_bangumi(
self, bangumi_id: str, max_page: int, subtitle_list: Optional[List[str]] = None
) -> List[Episode]: # pragma: no cover
"""
get all episode by bangumi id
:param bangumi_id: bangumi_id
:param subtitle_list: list of subtitle group
:type subtitle_list: list
:param max_page: how many page you want to crawl if there is no subtitle list
:type max_page: int
:return: list of bangumi
"""
raise NotImplementedError
def fetch_single_bangumi(self, bangumi_id: str) -> WebsiteBangumi:
"""
fetch bangumi info when updating
:param bangumi_id: bangumi_id, or bangumi['keyword']
:type bangumi_id: str
:rtype: WebsiteBangumi
"""
# return WebsiteBangumi(keyword=bangumi_id) if website don't has a page contains episodes and info
Debug
Set env BGMI_LOG to debug, info, warning, error for different log level
log file will locate at {TMP_PATH}/bgmi.log
Uninstall
Scheduled task will not be delete automatically, you will have to remove them manually.
*nix
:
remove them from your crontab
windows
:
schtasks /Delete /TN 'bgmi updater'
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.