Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active November 11, 2017 16:11
Show Gist options
  • Save artemklevtsov/4f92a0569a8b30f87895 to your computer and use it in GitHub Desktop.
Save artemklevtsov/4f92a0569a8b30f87895 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import errno
from argparse import ArgumentParser
from os.path import isfile, expanduser
from urllib.request import urlopen
if __name__ == "__main__":
parser = ArgumentParser(description = "Convert Good Line IPTV playlist for the SMplayer.")
parser.add_argument(
"-u", "--url", dest = "url",
default = "http://bolshoe.tv/playlist/m3u",
help = "playlist URL (default: http://bolshoe.tv/playlist/m3u)")
parser.add_argument(
"-o", "--output", dest = "file",
default = "~/.config/smplayer/tv.m3u8",
help = "output filename (default: ~/.config/smplayer/tv.m3u8)")
parser.add_argument(
"-f", "--force", dest = "force", action = "store_true",
help = "force to overwrite an output file")
parser.add_argument(
"--udpxy", dest = "udpxy", action = "store_true",
help = "convert playlist for the udpxy")
udpxy = parser.add_argument_group("udpxy options")
udpxy.add_argument(
"--host", dest = "host",
default = "192.168.1.1",
help = "udpxy host (default: 192.168.1.1)")
udpxy.add_argument(
"--port", dest = "port",
default = "4022",
help = "udpxy port (default: 4022)")
args = parser.parse_args()
if args.file.startswith("~"):
args.file = expanduser(args.file)
if isfile(args.file) and not args.force:
print("An output file already exists. Use '--force' to overwrite it.")
sys.exit(errno.EEXIST)
else:
response = urlopen(args.url)
content = response.read().decode("utf-8")
content = content.strip().replace("\nudp", ",,0\nudp")
if args.udpxy:
addr = "http://{}:{}/udp/".format(args.host, args.port)
content = content.replace("udp://@", addr)
if not content.endswith("\n"):
content += "\n"
with open(args.file, "w+") as file:
file.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment