2021-05-15, 19:22
I made a script to download a external video file, its working just fine, but i keep stuck in the screen till the download is done and i wanted to know how can i play this file while downloading it. Or if there is any addon that could do that for me it would work too, thanks in advance
python:def Download(url, ref=""):
Path = xbmc.translatePath( xbmcaddon.Addon().getAddonInfo('path') )
file = os.path.join( Path, "video.mp4")
req = Request(url)
if ref:
req.add_header('referer', ref)
prog=0
progress = xbmcgui.DialogProgressBG()
progress.create('Loading...')
sizechunk = 16 * 1024
totalsize = 0
resp = urlopen(req)
length = re.compile('ength\: ?(\d+)').findall(str(resp.headers))
with open(file, 'wb') as f:
while True:
progtotal = int( 100*totalsize/(int(length[0])) )
progress.update(progtotal, "")
prog+=1
chunk = resp.read(sizechunk)
if not chunk:
break
f.write(chunk)
totalsize+=sizechunk
progress.close()