Skip to content

Instantly share code, notes, and snippets.

@xybydy
Created August 26, 2017 16:05
Show Gist options
  • Save xybydy/285564a10081e65a7ff65d7d2e7a62b8 to your computer and use it in GitHub Desktop.
Save xybydy/285564a10081e65a7ff65d7d2e7a62b8 to your computer and use it in GitHub Desktop.
To convert simple iptv m3u8 files to livestreamspro xml files with f4mtester support
import codecs
import re
channels = dict()
tags = dict()
name = re.compile('tvg-name="(.+?)"')
thumbnail = re.compile('tvg-logo="(http.+?)"')
url = re.compile('url=(.+)')
parsed_file = []
def readm3u(infile):
cleaned_text = ''
instream = codecs.open(infile+'.m3u8', "Ur", encoding='utf-8')
for line in instream.readlines():
if line.startswith("#EXTINF:"):
line = line.replace('\n', ' url=')
cleaned_text += line
for line in cleaned_text.split('\n'):
if line.startswith("#EXTINF:"):
parsed_file.append({'title': name.search(line)[1], 'url': url.search(line)[1],
'thumbnail': thumbnail.search(line)[1] if thumbnail.search(line) else ''})
def xml_out(outfile):
with open(outfile + '.xml', 'w') as f:
f.write('<streamingInfos>\n')
for i in parsed_file:
f.write('<item>\n')
f.write(f'<title>{i["title"]}</title>\n')
f.write(f'<link>plugin://plugin.video.f4mTester/?streamtype=TSDOWNLOADER&amp;url={i["url"]}</link>\n')
f.write(f'<thumbnail>{i["thumbnail"]}</thumbnail>\n')
f.write('</item>\n')
def convert(filename):
readm3u(filename)
xml_out(filename)
convert('input')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment