Install
pip install bgetlib
Usage
import bgetlib as BGet;
agent = BGet.BilibiliAgent();
agent.LoginWithCookies("cookies.txt");
favs = agent.GetFavorites(12345678);
first_video = GetVideoInfo(favs[0].avid);
danmaku = GetRecentDanmaku(first_video.avid);
cover_pic_bytes = GetVideoCover(first_video.avid).data;
References
class BilibiliAgent:
def BilibiliAgent()
def LoginWithCookies(cookieFileName:str, ignoreDiscard:bool = True, ignoreExpires:bool = True) -> None
def GetFavoritesPaged(collectionId:int, pageNumber:int = 1) -> list[FavoritesData]
def GetFavorites(collectionId:int) -> list[FavoritesData]
def GetFavoritesNotBefore(collectionId:int, notBeforeTimestamp:int) -> list[FavoritesData]
def GetVideoInfo(avid:int) -> list[Video]
def GetRecentDanmaku(cid:int) -> Danmaku
def GetVideoCover(avid:int) -> VideoCoverPicture
class DownloadAgent:
def DownloadAgent(cookiesFile:str, cookiesIgnoreDiscard = True, cookiesIgnoreExpires = True, userAgent:str = "bili-hd2/3100010 Cronet/81.4044.156 Darwin/20.2.0")
def GetDownloadUrl(avid:int, cid:int, forceCdn:Union[bool, CDNList] = False) -> Tuple[str, str]
def GetDownloader(url:str) -> requests.Response
def GetSizeBytes(requestsInstance:requests.Response) -> int
def GetContentBinary(url:str) -> bytes
def GetContentIterated(self, url:str, stateUpdateFunc:Callable[[bool, Any, bytes, Tuple[float, float, float]], None], passthroughData:Any = None, chunkSize:int = 1024) -> None
stateUpdateFunc(isEnded:bool, passthroughData:Any, (timeUsedSecond, downloadedSizeByte, downloadSpeedBytePerSecond))
def SaveToFileByUrl(self, url:str, destFilename:str, stateUpdateFunc:Union[None, Callable[[float, float, float], None]] = None, chunkSize:int = 1024) -> None
stateUpdateFunc(timeUsedSecond, downloadedSizeByte, downloadSpeedBytePerSecond)
class ConvertAgent:
def ConvertAgent(ffmpegLocation:str = "ffmpeg", logFile:Union[str, None] = None, downloadedVideoExtName = "m4sv", downloadedAudioExtName = "m4sa")
def MergeDash(downloadPathWithoutExt:str, destPathWithoutExt:str, destForamt = "mp4") -> subprocess.CompletedProcess
def AudioToMp3(srcPath:str, destPath:str, bitRateKbps:int = 320) -> subprocess.CompletedProcess
def AudioToFlac(srcPath:str, destPath:str) -> subprocess.CompletedProcess
def AudioToAiff(srcPath:str, destPath:str) -> subprocess.CompletedProcess
class Mappers:
def "static" DictKeysCamelCaseToTomlStyleSnakeCase(srcDictReference:dict) -> dict
class CDNList(Enum):
SuzhouTencent = "upos-sz-mirrorcos.bilivideo.com"
SuzhouQiniu = "upos-sz-mirrorkodo.bilivideo.com"
SuzhouKingsoft = "upos-sz-mirrorks3.bilivideo.com"
SuzhouHuawei = "upos-sz-mirrorhw.bilivideo.com"
SuzhouAkamai = "upos-sz-mirrorakam.akamaized.net"
# Data
class BaseDataClass(xyz.josephcz.dict2class.DictStdClass):
def ToDict()
class FavoritesData(BaseDataClass):
avid:int, bvid:str, title:str, favoritedAt:int[timestamp]
class Video(BaseDataClass):
avid:int, bvid:str, title:str, category:str,
createdAt:int[timestamp], publishedAt:int[timestamp], descBase64:str,
uploader:VideoUploader,
staff:list[VideoStaff],
parts:list[VideoParts],
snapshot:VideoSnapshot
class VideoUploader(BaseDataClass):
uid:int, name:str
class VideoStaff(BaseDataClass):
uid:int, name:str, title:str
class VideoParts(BaseDataClass):
cid:int, name:str, length:int, resolution:str[regex("^\d+x\d+$")]
class VideoSnapshot(BaseDataClass):
snapshotBy:str,
snapshotedAt:int[timestamp],
playsCount:int,
danmakusCount:int,
likesCount:int,
ikesCount:int
class VideoCoverPicture(BaseDataClass):
avid:str, sourceUrl:str, data:bytes
class Danmaku:
cid:str
def AsStr(self) -> str
def AsStrFormatted(self, indent=" "*4) -> str
def AsXml(self)
# Errors:
class OperationNotAllowedError(Exception)
class NetworkError(Exception):
class HTTPError(NetworkError):
status:int, url:str
class ExternalCallError(Exception):
cmd:str, exitcode:str, stdout:str, stderr:str
License
MIT
Metadata
Release files for bgetlib 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bgetlib-1.0.0.tar.gz | 9.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bgetlib-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / bgetlib-1.0.0.tar.gz
| Download URL | bgetlib-1.0.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d9bc8e81972f989c1c22ea93c2309607826c5f16a56ef76d46c1012b8a07c73
|
|
BLAKE2b-256 checksum How to use checksums |
9cb75e409023f6a77e836fd375dc2844f132bacefc52b33df4c6280b11a84155
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0
|
Release files / bgetlib-1.0.0-py3-none-any.whl
| Download URL | bgetlib-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06d7c20f5847f4b9ddad40050be74ff160dbab539a44eb82d46e59fddf3b4ee4
|
|
BLAKE2b-256 checksum How to use checksums |
3c1d33f72c5c8fcceba399d0bda3e1e608ccc73f8ff68d85fe17d632953c2b5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0
|
Security for bgetlib 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.