BGmi is a cli tool for subscribed bangumi.
- Remove python3.4 support as it has reached its end-of-life
- Remove Python2 support
- Transmission rpc authentication configuration
- New download delegate deluge-rpc
- You can filter search results by min and max episode
- Multi data sources supported: bangumi_moe, mikan_project or dmhy
- Use aria2, transmission or xunlei-lixian 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
Use 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
pip install bgmi -U
bgmi upgrade
Make sure to run bgmi upgrade
after you upgrade your bgmi
go to BGmi/bgmi-docker-all-in-one
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:
you can add --help
to all BGmi
sub command to show full options, some of them are not mentioned here.
All bangumi in database will be deleted when changing data source! but scripts won't be affected
video files will still store on the disk, but won't be shown on website.
bgmi source mikan_project
bgmi cal
bgmi add "Re:CREATORS" "夏目友人帐 陆" "进击的巨人 season 2"
bgmi add "樱花任务" --episode 0
bgmi delete --name "Re:CREATORS"
Update bangumi database which locates at ~/.bgmi/bangumi.db acquiescently:
bgmi update --download
bgmi update "从零开始的魔法书" --download 2 3
bgmi update "时钟机关之星" --download
Set up the bangumi subtitle group filter and fetch entries:
bgmi list
bgmi fetch "Re:CREATORS"
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"
bgmi search '为美好的世界献上祝福!' --regex-filter '.*动漫国字幕组.*为美好的世界献上祝福!].*720P.*'
# download
bgmi search '为美好的世界献上祝福!' --regex-filter '.*合集.*' --download
Modify bangumi episode:
bgmi list
bgmi mark "Re:CREATORS" 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
Show BGmi configure and modify it:
bgmi config
bgmi config ARIA2_RPC_TOKEN 'token:token233'
Fields of configure file:
BGmi configure:
BANGUMI_MOE_URL
: url of bangumi.moe mirrorBGMI_SAVE_PATH
: bangumi saving pathDOWNLOAD_DELEGATE
: the ways of downloading bangumi (aria2-rpc, transmission-rpc, xunlei)MAX_PAGE
: max page for fetching bangumi informationBGMI_TMP_PATH
: just a temporary pathDANMAKU_API_URL
: url of danmaku apiLANG
: language
Aria2-rpc configure:
ARIA2_RPC_URL
: aria2c daemon RPC url, not jsonrpc url.("http://localhost:6800/rpc" for localhost)ARIA2_RPC_TOKEN
: aria2c daemon RPC token("token:" for no token)
Xunlei configure:
XunleiLixian is deprecated, please choose aria2-rpc or transmission-rpc.
XUNLEI_LX_PATH
: path of xunlei-lixian binary
Transmission-rpc configure:
TRANSMISSION_RPC_URL
: transmission rpc hostTRANSMISSION_RPC_PORT
: transmission rpc portTRANSMISSION_RPC_USERNAME
: transmission rpc username (leave it default if you don't set rpc authentication)TRANSMISSION_RPC_PASSWORD
: transmission rpc password (leave it default if you don't set rpc authentication)
Deluge-rpc configure:
DELUGE_RPC_URL
: deluge rpc urlDELUGE_RPC_PASSWORD
: deluge rpc password
Download all bangumi cover:
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
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.
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
see issue #77
BGmi use DPlayer to play bangumi.
First, setup nginx to access bangumi files. Second, choose one danmaku backend at DPlayer#related-projects.
Use bgmi config
to setup the url of danmaku api.
bgmi config DANMAKU_API_URL https://api.prprpr.me/dplayer/ # This api is provided by dplayer official
...restart your bgmi_http
and enjoy :D
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.mp4',
2: 'http://example.com/Bangumi/1/2.mp4',
3: 'http://example.com/Bangumi/1/3.mp4'
}
The keys 1, 2, 3 is the episode, the value is the url of bangumi.
You can easily add your own BGmi data source by extending BGmi website base class and implement all the method.
class DataSource(bgmi.website.base.BaseWebsite):
cover_url=''
def search_by_keyword(self, keyword, count):
"""
return a list of dict with at least 4 key: download, name, title, episode
example:
```
[
{
'name':"路人女主的养成方法",
'download': 'magnet:?xt=urn:btih:what ever',
'title': "[澄空学园] 路人女主的养成方法 第12话 MP4 720p 完",
'episode': 12
},
]
:param keyword: search key word
:type keyword: str
:param count: how many page to fetch from website
:type count: int
:return: list of episode search result
:rtype: list[dict]
"""
raise NotImplementedError
def fetch_bangumi_calendar_and_subtitle_group(self):
"""
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']
example:
```
[
{
"status": 0,
"subtitle_group": [
"123",
"456"
],
"name": "名侦探柯南",
"keyword": "1234", #bangumi id
"update_time": "Sat",
"cover": "data/images/cover1.jpg"
},
]
```
when downloading cover images, BGmi will try to get `self.cover_url + bangumi['cover']`
list of subtitle group dict:
example:
```
[
{
'id': '233',
'name': 'bgmi字幕组'
}
]
```
:return: list of bangumi, list of subtitile group
:rtype: (list[dict], list[dict])
"""
raise NotImplementedError
def fetch_episode_of_bangumi(self, bangumi_id, subtitle_list=None, max_page=MAX_PAGE):
"""
get all episode by bangumi id
example
```
[
{
"download": "magnet:?xt=urn:btih:e43b3b6b53dd9fd6af1199e112d3c7ff15cab82c",
"subtitle_group": "58a9c1c9f5dc363606ab42ec",
"title": "【喵萌奶茶屋】★七月新番★[来自深渊/Made in Abyss][07][GB][720P]",
"episode": 0,
"time": 1503301292
},
]
```
: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
:rtype: list[dict]
"""
raise NotImplementedError
Set env BGMI_LOG
to debug
, info
, warning
, error
for different log level
log file will locate at {TMP_PATH}/bgmi.log
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'