Created
December 27, 2024 22:17
-
-
Save trentwiles/219bc51fa4acad7993a7738a811f933f to your computer and use it in GitHub Desktop.
Simple script to combine multiple m3u playlists into one
This file contains hidden or 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
######################################################### | |
# # | |
# 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