如何使用微博直播来转播LIVE流

  1. 登录微博
  2. 打开微博直播管理后台
  3. 点击右上角的"创建直播" 创建直播步骤1 创建直播步骤2
  4. 按F12,在Network里筛选flv
  5. 推流地址则为网页给出的RTMP地址、观看地址则为筛选出来的FLV地址 获取推流地址
  6. (tips)flv地址可以直接更改为m3u8进行观看,以解决ios无法观看flv流的问题
    如:https://plwb00.live.weibo.com/alicdn/5175622064409598_wb720avc.flv ----> https://plwb00.live.weibo.com/alicdn/5175622064409598_wb720avc.m3u8
  7. (tips)相信你发现了,为什么观看地址中有720avc呢?我们尝试移除这段后发现,新链接可以看到推流原画(大概是未被压缩的)直播流
    如:https://plwb00.live.weibo.com/alicdn/5175622064409598_wb720avc.flv ----> https://plwb00.live.weibo.com/alicdn/5175622064409598.m3u8

大功告成!!!


Linux直播管理工具

使用Gemini + Trae + Claude编写,支持LoveLive(eplus无DRM)、Asobistage M3U8、U-NEXT(需有m3u8及hls-aes128-key)、Spwn(需有账号密码)、Zaiko(需有Cookie)

#!/bin/bash

# ==================== 全局配置 ====================
# 全局变量
PID_FILE="/tmp/live_streams.pid"
LOG_DIR="/tmp/live_logs"

# Bilibili Cookie (方便在此处修改)
BILIBILI_COOKIE="XXXXX"
# ================================================

# 创建日志目录 (如果不存在)
mkdir -p "$LOG_DIR"

# 函数:检查cookies文件是否存在且不为空
check_cookies() {
    local cookies_file=$1
    if [[ ! -f "$cookies_file" ]] || [[ ! -s "$cookies_file" ]]; then
        echo "错误: Cookies文件 $cookies_file 丢失或为空。"
        return 1
    fi
}

# 函数:记录进程信息
log_process() {
    local target=$1
    local pid=$2
    echo "$target:$pid" >> "$PID_FILE"
    echo "[$(date)] 已启动流: $target (PID: $pid)"
}

# 函数:启动流 (拉流并推流)
start_stream_with_push() {
    local source_url=$1
    local push_url=$2
    local target=$3
    local background=${4:-false}
    local hls_key=$5

    echo "正在启动流: $source_url -> $push_url"
    
    local cmd=""
    
    # 优先检查HLS KEY
    if [[ -n "$hls_key" ]] && [[ ${#hls_key} -eq 32 ]]; then
        echo "检测到HLS key,使用streamlink的 --hls-key 模式。"
        # 尝试激活虚拟环境后运行streamlink
        cmd="source .venv/bin/activate && streamlink "$source_url" best --hls-key "$hls_key" --plugin-dir '/root/.local/share/streamlink/plugins' -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
    else
        # 如果没有有效的HLS key,则根据URL特征进行站点特化处理
        if [[ -n "$hls_key" ]]; then
            echo "警告: HLS key已提供但非32位,将忽略该key并进行常规检测。"
        fi
        
        echo "正在根据URL特征选择处理方式..."
        if [[ "$source_url" == *".m3u8"* ]] || [[ "$source_url" == *cloudfront.net* ]]; then
            echo "检测到直接m3u8链接,使用ffmpeg处理"
            cmd="ffmpeg -re -i "$source_url" -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        elif [[ "$source_url" == *youtube.com* ]] || [[ "$source_url" == *youtu.be* ]]; then
            if check_cookies '/root/youtube_cookies.txt'; then
                echo "使用yt-dlp处理YouTube源"
                cmd="ffmpeg -re -i $(yt-dlp --cookies '/root/youtube_cookies.txt' -g "$source_url") -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
            else
                echo "因缺少YouTube cookies文件,跳过 $target"
                return 1
            fi
        elif [[ "$source_url" == *.bilibili.com* ]]; then
            echo "使用streamlink处理Bilibili源"
            cmd="streamlink "$source_url" best --http-cookie "$BILIBILI_COOKIE" -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        elif [[ "$source_url" == *twitch.tv* ]]; then
            echo "使用streamlink处理Twitch源"
            cmd="streamlink "$source_url" best --twitch-low-latency -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        elif [[ "$source_url" == *eplus.jp* ]]; then
            echo "使用streamlink处理eplus源"
            cmd="streamlink "$source_url" best --plugin-dir '/root/.local/share/streamlink/plugins' --eplus-allow-relogin -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        elif [[ "$source_url" == *spwn.jp* ]]; then
            echo "使用streamlink处理SPWN源"
            cmd="streamlink "$source_url" best --spwn-email '810903342@qq.com' --spwn-password 'pxt12818257' -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        elif [[ "$source_url" == *zaiko.io* ]]; then
            if check_cookies '/root/zaiko_cookies.txt'; then
                echo "使用yt-dlp处理Zaiko源"
                cmd="ffmpeg -re -i $(yt-dlp --cookies '/root/zaiko_cookies.txt' -g "$source_url") -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
            else
                echo "因缺少Zaiko cookies文件,跳过 $target"
                return 1
            fi
        else
            echo "使用通用的streamlink方式处理"
            cmd="streamlink "$source_url" best -O | ffmpeg -re -i pipe:0 -c copy -bsf:a aac_adtstoasc -f flv "$push_url""
        fi
    fi
    
    echo "即将执行: $cmd"
    
    if [[ "$background" == "true" ]]; then
        eval "$cmd" > "$LOG_DIR/$target.log" 2>&1 &
        local pid=$!
        log_process "$target" "$pid"
    else
        eval "$cmd"
    fi
}