#!/usr/bin/env python3 from http.server import HTTPServer, BaseHTTPRequestHandler import socketserver as SocketServer import sys import requests import logging PORT = 8000 final_m3u="" class RequestHandler(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header("Content-type", "plain/text") self.end_headers() def _html(self, message): return message.encode("utf8") # NOTE: must return a bytes object! def do_GET(self): self._set_headers() self.wfile.write(self._html(final_m3u)) def do_HEAD(self): self._set_headers() def do_POST(self): # Doesn't do anything with posted data self._set_headers() self.wfile.write(self._html(final_m3u)) import argparse if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "-u", "--url", help="url to get original m3u list from", default="https://raw.githubusercontent.com/dersnyke/satipplaylists/main/satip_astra192e.m3u", ) parser.add_argument( "-f", "--favorites", help="the favorite file to read the favorites from" ) args = parser.parse_args() r = requests.get(args.url) print("Status Code:") print(r.status_code) if r.status_code != 200: sys.exit() senders = {} favorites = [] sender = "" name = "" new_m3u=["'#EXTM3U'"] # print (r.text) lines = r.text.split("\n") for line in lines: line = line.strip() if line[:1] == "#": #print(line) elements = line.split(",", 1) if len(elements) < 2: continue name = elements[1].strip() sender = line else: url=line url = url.replace("rtsp:", "http:") url = url.replace("sat.ip", "exip418") senders[sender] = {"name": name.lower(), "url": url} if args.favorites: with open(args.farvorites, encoding="utf8") as fin: favorites = fin.read().lower() for sender, data in senders.items(): if not favorites or data["name"] in favorites: #new_m3u.append(f"{sender}\n{data["url"]}") new_m3u += [ "#KODIPROP:inputstreamclass=inputstream.ffmpegdirect", "#KODIPROP:inputstream.ffmpegdirect.mime_type=video/mp2t", sender, data["url"] ] final_m3u="\n".join(new_m3u) print(final_m3u) Handler = RequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) httpd.serve_forever()