A bilibili API library
Project description
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
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.
Source Distribution
bgetlib-1.0.0.tar.gz
(9.1 kB
view details)
Built Distribution
bgetlib-1.0.0-py3-none-any.whl
(10.7 kB
view details)
File details
Details for the file bgetlib-1.0.0.tar.gz
.
File metadata
- Download URL: bgetlib-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d9bc8e81972f989c1c22ea93c2309607826c5f16a56ef76d46c1012b8a07c73 |
|
MD5 | a1ccb67d699bdb8bcf16eb4b6b60bcb3 |
|
BLAKE2b-256 | 9cb75e409023f6a77e836fd375dc2844f132bacefc52b33df4c6280b11a84155 |
File details
Details for the file bgetlib-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: bgetlib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06d7c20f5847f4b9ddad40050be74ff160dbab539a44eb82d46e59fddf3b4ee4 |
|
MD5 | 4eb739b1089812285b0cc18fd09ca73e |
|
BLAKE2b-256 | 3c1d33f72c5c8fcceba399d0bda3e1e608ccc73f8ff68d85fe17d632953c2b5f |