import urllib2
urlInputFile = 'http://xxxx' # link to m3u file
outputFile = 'result.txt'
response = urllib2.urlopen(urlInputFile)
fileM3U = response.readlines()
streamIP = ''
for line in fileM3U:
if 'http' in line:
if not streamIP: streamIP = line.split('/')[2]
with open(outputFile,mode='r') as f:
lines = f.readlines()
with open(outputFile,mode='w') as f:
for line in lines:
f.write(line.replace(line.split('/')[2],streamIP))