Skip to content

Instantly share code, notes, and snippets.

@trentwiles
Created December 27, 2024 22:17
Show Gist options
  • Save trentwiles/219bc51fa4acad7993a7738a811f933f to your computer and use it in GitHub Desktop.
Save trentwiles/219bc51fa4acad7993a7738a811f933f to your computer and use it in GitHub Desktop.
Simple script to combine multiple m3u playlists into one
#########################################################
# #
# IPTV PLAYLIST MERGER #
# #
# by trent #
# #
# Usage: python3 iptv.py [FILE_NAME] #
# #
#########################################################
import requests
import sys
from datetime import datetime
try:
SAVE_TO = sys.argv[1]
except IndexError:
print("Error: missing output location (usage: python3 iptv.py [FILE_NAME])")
sys.exit()
# valid m3u URLs to combine
# all english speaking countries (plus south africa) for now
PLAYLISTS = [
"https://iptv-org.github.io/iptv/countries/us.m3u",
"https://iptv-org.github.io/iptv/countries/uk.m3u",
"https://iptv-org.github.io/iptv/countries/ca.m3u",
"https://iptv-org.github.io/iptv/countries/au.m3u",
"https://iptv-org.github.io/iptv/countries/nz.m3u",
"https://iptv-org.github.io/iptv/countries/za.m3u"
]
ts = str(datetime.now().strftime("%m/%d/%Y %I:%M %p"))
combined_playlist = "# Generated @ " + ts + "\n"
combined_playlist += "# github.com/trentwiles\n\n"
combined_playlist += "#EXTM3U\n"
for url in PLAYLISTS:
response = requests.get(url)
if response.status_code == 200:
combined_playlist += response.text.strip() + "\n"
else:
print("WARNING: Failed to download " + str(url) + ", non-200 status code")
with open(SAVE_TO, "w", encoding="utf-8") as file:
file.write(combined_playlist)
print("DEBUG: saved to " + str(SAVE_TO) + " at " + ts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment