>编辑
我的问题现在已经解决了(见下文),每个人都可以使用这个脚本下载 m3u8 流,比如苹果的 bipbop
奥里格问题
我创建了这个漂亮的脚本来下载Apple的BipBop示例HLS流。但是我没能玩。如果你帮我解决这个问题,我们都可以享受这个脚本:
#!/bin/bash
unset PROMPT_COMMAND
set -x
URL=https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8
MANIFESTNAME=$(basename $URL)
LOCAL_MANIFEST=$MANIFESTNAME
URLPREF=$(dirname $URL)
wget $URL -O $LOCAL_MANIFEST
cat $LOCAL_MANIFEST | grep "#EXT-X-STREAM-INF:" -A1 | grep m3u8 > all_playlists.txt
cat $LOCAL_MANIFEST | grep "#EXT-X-MEDIA.*URI" | sed -e 's_.*URI="(.*)".*_1_' >> all_playlists.txt
#this will yield files which we already downloaded, but we want the index file itself
cat $LOCAL_MANIFEST | grep "#EXT-X-I-FRAME-STREAM-INF.*URI" | sed -e 's_.*URI="(.*)".*_1_' >> all_playlists.txt
while read playList; do
FOLDER=$(dirname $playList)
PL_NAME=$(basename $playList)
LOCAL_PL=$FOLDER/$PL_NAME
mkdir -p $FOLDER 2> /dev/null
PL_URL=$URLPREF/$playList
echo "PL_URL=$PL_URL"
TSL=${FOLDER}_TSList.txt
wget $PL_URL -O $LOCAL_PL
echo "LOCAL_PL=$LOCAL_PL"
cat $LOCAL_PL | grep -v "^#" | uniq > $TSL
echo "====== media list ======="
cat $TSL
echo "========================="
#TS is actually any media file
while read ts; do
TS_NAME=$URLPREF/$FOLDER/$ts
LOCAL_TS=$FOLDER/$ts
echo $TS_NAME
if [ -s $LOCAL_TS ]; then
echo "Already exists. skiping."
else
wget $TS_NAME -O $LOCAL_TS
fi
done < $TSL
rm $TSL
done < all_playlists.txt
rm all_playlists.txt
find . -name Thumbs.db -exec rm {} ;
当流准备好时,我使用 Python 的 http 服务器运行一个 http 服务器:
http-server -p 8090
然后尝试使用以下命令播放:
open http://localhost:8090/bipbop_16x9_variant.m3u8 -a Safari
http 服务器显示正常请求:
[12:24:51] "GET /bipbop_16x9_variant.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:51] "GET /gear1/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear1/main.ts" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/fileSequence0.webvtt" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear0/prog_index.m3u8" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /gear0/main.aac" "Mozilla/5.0 (Macintosh..."
[12:24:52] "GET /subtitles/eng_forced/fileSequence1.webvtt" "Mozilla/5.0 (Macintosh..."
但是 Safari 无法播放流,显示"缺少插件"消息......
任何想法请???我们需要这个流进行 iOS 开发......
因此,多亏了@libertyernie的评论,这个问题现在已经解决了。实际上,我自己也怀疑过这个问题:Python 的 http-server 模块不是提供 m3u8 流的正确工具,因为它无法针对正确的内容类型进行配置。
一个更好的工具是Lighttpd。
安装方式:
brew install lighttpd
现在创建一个配置文件lighttpd.conf:
server.document-root = "<full-path-no-~>/bipbop"
server.port = 8090
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png",
".m3u8" => "application/vnd.apple.mpegurl",
".ts" => "video/MP2T"
)
最后两行对我们的成功至关重要。现在我们可以运行我们的流服务器:
lighttpd -D -f lighttpd.conf
现在我们可以打开 http://localhost:8090/bipbop_16x9_variant.m3u8 并观看直播。