简体   繁体   中英

time.strftime not updating in while loop

I am trying to record live streams. I want to periodically check if the stream is live and then record with streamlink and save the file with a unique date/time.

from subprocess import call
import sys
import time

streamURL = str(sys.argv[1])
streamQuality = str(sys.argv[2])
streamName = str(sys.argv[3])


streamBuilder = []
streamBuilder.append("streamlink")
streamBuilder.append(streamURL)
streamBuilder.append(streamQuality)
streamBuilder.append("-o")
streamBuilder.append("/download/"+streamName+"-"+time.strftime("%Y%m%d%H%M%S")+".mkv")

while True:
    call(streamBuilder)
    time.sleep(60)

With the current code, the name does not change each time the stream is live.

I think that you need to change the laste value of the streamBuilder at each iteration

while True:
    call(streamBuilder)
    time.sleep(60)
    streamBuilder[-1] = "/download/"+streamName+"-"+time.strftime("%Y%m%d%H%M%S")+".mkv"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM