Created
March 3, 2019 01:57
-
-
Save Domin8-IPTV/9b2839f7c113a2bf3f8986b0d65a6a17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import urllib2 | |
import codecs | |
from contextlib import closing | |
class Track: | |
def __init__(self, length, title, path): | |
self.length = length | |
self.title = title | |
self.path = path | |
def parse(uri): | |
with closing(urllib2.urlopen(uri) | |
if urllib2.splittype(uri)[0] | |
else codecs.open(uri, 'r')) as inf: | |
# initialize playlist variables before reading file | |
playlist = [] | |
song = Track(None, None, None) | |
for line_no, line in enumerate(inf): | |
try: | |
line = line.strip(codecs.BOM_UTF8).strip() | |
if line.startswith('#EXTINF:'): | |
# pull length and title from #EXTINF line | |
length, title = line.split('#EXTINF:')[1].split(',', 1) | |
song = Track(length, title, None) | |
elif line.startswith('#'): | |
# comment, #EXTM3U | |
pass | |
elif len(line) != 0: | |
# pull song path from all other, non-blank lines | |
song.path = line | |
playlist.append(song) | |
# reset the song variable so it doesn't use the same EXTINF more than once | |
song = Track(None, None, None) | |
except Exception, ex: | |
raise Exception("Can't parse line %d: %s" % (line_no, line), ex) | |
return playlist | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print 'Usage: %s /path/to/playlist.m3u' % str(sys.argv[0]) | |
print 'or: %s http://11.22.33.44/path/to/playlist.m3u' % str(sys.argv[0]) | |
sys.exit(1) | |
m3ufile = str(sys.argv[1]) | |
index=1 | |
playlist = parse(m3ufile) | |
for item in playlist: | |
path = item.path | |
if item.path.startswith("http://"): | |
if "m3u8" in item.path: | |
path = item.path.replace('http','hls',1) | |
else: | |
path = item.path.replace('http','tshttp',1) | |
title = item.title | |
if not item.title: | |
title = 'stream%i' % index | |
print ('stream %(name)s {\n url %(url)s;\n}' % {"name": title.replace(" ","_"), "url": path }) | |
index += 1 |
curl -u USERNAME:PASSWORD --data-binary "$(/opt/flussonic/bin/python2.7 m3u2flussonic.py example2.m3u)" http://FLUSSONIC:PORT/flussonic/api/config/stream_create
{"success":true}
Is it possible to detect more then one channels with same name and add to one service with multiple inputs?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget -O m3u2flussonic.py https://gist.githubusercontent.com/Domin8-IPTV/9b2839f7c113a2bf3f8986b0d65a6a17/raw/7c5dd2f49c5d2dd46ac3249a91a941a3c8c6bd9f/m3u2flussonic.py