Created
December 6, 2020 13:45
-
-
Save Enoch2090/74f4ca2cd61bfea06e6535997710cf05 to your computer and use it in GitHub Desktop.
从BV号生成 Bilibili iframe 播放器代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# $ python3 bid.py [BID] | |
# e.g. | |
# $ python3 bid.py BV1yt4y1a7FN | |
import requests | |
import sys | |
import platform | |
import os | |
if len(sys.argv) < 2: | |
raise RuntimeError('Missing argument bid.') | |
bvid = str(sys.argv[1]) | |
cid_link = "https://api.bilibili.com/x/player/pagelist?bvid=%s" % bvid | |
cid = requests.get(cid_link).json()["data"][0]["cid"] | |
aid_link = "https://api.bilibili.com/x/web-interface/view?cid=%s&bvid=%s" % ( | |
cid, bvid) | |
aid = requests.get(aid_link).json()["data"]["aid"] | |
html_code = '''<div style="position: relative; width: 100%; height: 0; padding-bottom: 75%;"> | |
<iframe src="//player.bilibili.com/player.html?aid='''+str(aid)+'&cid='+str(cid)+'''&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true" style="position: absolute; width: 100%; height: 100%; left: 0; top: 0;"></iframe> | |
</div>''' | |
sysstr = platform.system() | |
if (sysstr == "Darwin"): | |
os.system("echo '%s' | pbcopy" % html_code) | |
elif (sysstr == "Windows"): | |
os.system("echo %s | clip" % html_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment