This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
openclaw-skills/scripts/bilibili-short-to-long.sh
T
OpenClaw Agent f41f945fe0 添加B站链接转换和浏览器安装脚本
- bilibili-short-to-long.sh: B站短链接转长链接工具
  - 支持短链接、BV号、AV号多种格式
  - 自动清理URL中的tracking参数
  - 友好的输出格式

- install-browser-for-openclaw.sh: OpenClaw浏览器环境一键安装脚本
  - 支持Ubuntu/Debian/CentOS
  - 自动安装Chromium浏览器
  - 配置OpenClaw Gateway
2026-02-07 09:07:42 +08:00

92 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# B站短链接转长链接脚本
# ============================================================================
# 用途:将B站短链接(b23.tv)转换为完整视频链接
# 支持:短链接、BV号、AV号
# ============================================================================
set -e
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 获取长链接(核心逻辑)
get_long_url() {
local input=$1
# 如果是BV号格式(BV开头),直接返回完整URL
if [[ $input =~ ^BV[a-zA-Z0-9]+$ ]]; then
echo "https://www.bilibili.com/video/$input"
return 0
fi
# 构造短链接URL
if [[ $input =~ ^https?:// ]]; then
local short_url="$input"
elif [[ $input =~ ^b23\.tv/ ]]; then
local short_url="https://$input"
else
local short_url="https://b23.tv/$input"
fi
# 获取重定向地址
local redirect=$(curl -sLI "$short_url" 2>/dev/null | grep -i '^location:' | head -1 | sed 's/location: //I' | tr -d '\r' || echo "")
if [ -z "$redirect" ]; then
echo "错误:无法获取重定向地址" >&2
return 1
fi
# 清理URL(移除tracking参数)
echo "$redirect" | sed 's/\?.*//' | sed 's/&/\&/g'
}
# 提取BV号
extract_bv() {
local url=$1
echo "$url" | grep -oP 'BV[a-zA-Z0-9]+' | head -1
}
# 主函数
main() {
if [ $# -eq 0 ]; then
echo "用法: $0 <短链接或BV号>"
echo ""
echo "示例:"
echo " $0 https://b23.tv/lid6E0m"
echo " $0 b23.tv/lid6E0m"
echo " $0 BV11t64BJEDZ"
echo " $0 lid6E0m"
exit 1
fi
local input=$1
local long_url=$(get_long_url "$input")
if [ $? -ne 0 ]; then
exit 1
fi
local bv=$(extract_bv "$long_url")
# 输出结果
echo "=================================="
echo -e "${GREEN}B站链接转换结果${NC}"
echo "=================================="
echo "输入: $input"
echo "长链接: $long_url"
echo "BV号: ${bv:-未找到}"
echo "=================================="
# 单独输出长链接(便于脚本调用)
echo ""
echo "$long_url"
}
main "$@"