Ok.... I found the solution
M3UPATH= '/tmp/IPTV'
LastScanned= 'userbouquet.LastScanned.tv'
WGET='wget --no-check-certificate'
BOUQUETSPATH='/etc/enigma2/bouquets.tv'
E2SETTINGSPATH='/etc/enigma2'
##################################################################
import os
def convert(m3ufile,BFNAME):
with open('%s/%s' % (E2SETTINGSPATH, BFNAME), 'w') as outfile:
desk_tmp = ''
outfile.write('#NAME %s
' % m3ubase)
if os.path.isfile(m3ufile):
for line in open(m3ufile):
if line.startswith('http://'):
outfile.write('#SERVICE 4097:0:1:0:0:0:0:0:0:0:%s' % line.replace(':', '%3a'))
outfile.write('#DESCRIPTION %s' % desk_tmp)
elif line.startswith('#EXTINF'):
desk_tmp = '%s' % line.split(',list.alliptvlinks.com ')[-1]
elif '<stream_url><![CDATA' in line:
outfile.write('#SERVICE 4097:0:1:0:0:0:0:0:0:0:%s
' % line.split('[')[-1].split(']')[0].replace(':', '%3a'))
outfile.write('#DESCRIPTION %s
' % desk_tmp)
elif '<title>' in line:
if '<![CDATA[' in line:
desk_tmp = '%s
' % line.split('[')[-1].split(']')[0]
else:
desk_tmp = '%s
' % line.split('<')[1].split('>')[1]
outfile.write('
')
outfile.close()
if os.path.isfile(BOUQUETSPATH):
for line in open(BOUQUETSPATH):
if BFNAME in line:
if os.path.isfile('%s/%s' % (E2SETTINGSPATH, BFNAME)) and os.path.isfile(BOUQUETSPATH):
remove_line(BOUQUETSPATH, BFNAME)
with open(BOUQUETSPATH, 'a') as outfile:
outfile.write('#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "%s" ORDER BY bouquet
' % BFNAME)
outfile.close()
if LastScanned in line:
remove_line(BOUQUETSPATH, LastScanned)
with open(BOUQUETSPATH, 'a') as outfile:
outfile.write('#SERVICE 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "%s" ORDER BY bouquet
' % LastScanned)
outfile.close()
os.system('wget -q -O - http://root%[email protected]/web/servicelistreload?mode=0 > /dev/null 2>&1 && sleep 2')
return
else:
print("File missing %s" % M3UPATH)
counter=0
for subdir, dirs, files in os.walk(M3UPATH):
for file in files:
if file.endswith(".m3u"):
counter=counter+1
m3ufile=os.path.join(subdir, file)
print "m3ufile",m3ufile
m3ubase=file[:-4]
print "m3ubase",m3ubase
BFNAME= 'userbouquet.%s.tv'%m3ubase
print "m3ubase",m3ubase
convert(m3ufile,BFNAME)
print "%s m3ufiles converted to bouquets"%str(counter)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…