我试图在没有Shell=true的情况下运行Shell=true,但不知道如何格式化我的列表。对于无效的url或403,它总是会失败。就像它没有设置曲奇或标题一样。
示例url
https://vodus-i-video-xxx.xxx.net/vodus/1d9cfcbc-8469-4c9f-b44a-6412091b733d/NoADs_IND_SEA_720_pre1.ism/QualityLevels(4740905)/Manifest(video,format=m3u8-aapl-v3,audiotrack=aac_UND_2_127,filter=chromecast)?hdnea=st=1535729260~exp=1535729440~acl=/*~hmac=977cba9e480bcdb7b89033488f37679b4a6906f8f7a981a055b88a0802012c71&hdcore=2.11.3|Connection=keep-alive&User-Agent=Firefox|Connection=keep-alive&User-Agent=Firefox我解析url以获得cookie::
"hdnea=st=1535729260~exp=1535729440~acl=/*~hmac=977cba9e480bcdb7b89033488f37679b4a6906f8f7a981a055b88a0802012c71&hdcore=2.11.3;path=/; domain=livemain-i-video-xxx.xxx.net;86400s"将与Shell=true一起工作的最终字符串
streamlink --player-external-http --player-external-http-port 10000 --http-header "User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0" --http-cookie "hdnea=st=1535729260~exp=1535729440~acl=/*~hmac=977cba9e480bcdb7b89033488f37679b4a6906f8f7a981a055b88a0802012c71&hdcore=2.11.3;path=/; domain=livemain-i-video-xxx.xxx.net;86400s" "hlsvariant://https://vodus-i-video-xxx.xxx.net/vodus/1d9cfcbc-8469-4c9f-b44a-6412091b733d/NoADs_IND_SEA_720_pre1.ism/QualityLevels(4740905)/Manifest(video,format=m3u8-aapl-v3,audiotrack=aac_UND_2_127,filter=chromecast)?hdnea=st=1535729260~exp=1535729440~acl=/*~hmac=977cba9e480bcdb7b89033488f37679b4a6906f8f7a981a055b88a0802012c71&hdcore=2.11.3|Connection=keep-alive&User-Agent=Firefox|Connection=keep-alive&User-Agent=Firefox" best这就是我试图格式化的方式,但似乎不能正确地完成它。
stream_url="https://vodus-i-video-nfl.akamaized.net/vodus/1d9cfcbc-8469-4c9f-b44a-6412091b733d/NoADs_IND_SEA_720_pre1.ism/QualityLevels(4740905)/Manifest(video,format=m3u8-aapl-v3,audiotrack=aac_UND_2_127,filter=chromecast)?hdnea=st=1535729260~exp=1535729440~acl=/*~hmac=977cba9e480bcdb7b89033488f37679b4a6906f8f7a981a055b88a0802012c71&hdcore=2.11.3|Connection=keep-alive&User-Agent=Firefox|Connection=keep-alive&User-Agent=Firefox"
urlsplit = stream_url.split('?')
getcookie = urlsplit[1].split('|')
cookie = getcookie[0]
cmd = [
"streamlink",
"--player-external-http",
"--player-external-http-port",
"%s" %(port),
"--http-header",
"\"User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0\"",
"--http-cookie",
"\"%s" %(cookie) + ";path=/;domain=livemain-i-video-nfl.akamaized.net;86400s\"",
"%s" %(streamtest),
"best"
]
logger.info("Running cmd: %s" % " ".join(cmd))
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = proc.communicate()
logging.info(output)我得到的输出是:
信息:root:Running: streamlink -player-外部-player-外部-http-port 15000 --http-header "User-Agent=Mozilla/5.0 (Windows 10.0;Win64;x64;rv:61.0) Gecko/20100101 Firefox/61.0“-http-cookie- 信息:根:cli流链接正在以root的形式运行!注意!cli为Unable ://https://livemain-i-video-xxx.xxx.net/ch16/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd.ism/QualityLevels(2200000)/Manifest(video,format=m3u8-aapl-v3,audiotrack=audio,filter=chromecast-live)错误找到匹配的插件hls :无法打开https://livemain-i-video-xxx.xxx.net/ch16/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd.ism/QualityLevels(2200000)/Manifest(video,format=m3u8-aapl-v3,audiotrack=audio,filter=chromecast-live) (403个客户端错误: URL:https://livemain-i-video-xxx.xxx.net/ch16/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd/7fd8a3f6-5dee-4ed1-b23f-7398684ff5bd.ism/QualityLevels(2200000)/Manifest(video,format=m3u8-aapl-v3,audiotrack=audio,filter=chromecast-live)被禁止)
连接看起来是正确的,但似乎不太正确。我确实认为我需要双引号的曲奇和url,因为特殊的字符。我只是希望得到一个输出,而在Shell=True中,直到输出完成后才会得到输出。
发布于 2018-08-31 16:31:52
用户代理头和cookie周围的文字引号看起来可疑。我猜你想
cmd = [
"streamlink",
"--player-external-http",
"--player-external-http-port",
str(port),
"--http-header",
"User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0",
"--http-cookie",
"%s;path=/;domain=livemain-i-video-nfl.akamaized.net;86400s"%(cookie),
streamtest,
"best"
]还请注意,我们如何避免使用%字符串格式将某些内容转换为已经是字符串的字符串。
https://stackoverflow.com/questions/52119241
复制相似问题