Extracts original m3u8 links directly from multiple IPTV networks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
iptv-network-extract/iptv_network_extract.py

80 lines
1.9 KiB

#!/usr/bin/env python3
import sys
import json
import argparse
import requests
with open('channels.json', 'r') as myfile:
channelsDict = json.loads(myfile.read())
parser = argparse.ArgumentParser(
prog='IPTV Network Extract',
description='Extracts m3u8 links for multiple IPTVs'
)
parser.add_argument(
"-c", "--channel",
nargs=1,
choices=list(channelsDict.keys()),
required=True,
help="TV channel name"
)
parser.add_argument(
"--version",
action="version",
version="%(prog)s 0.1"
)
args = parser.parse_args()
channel = args.channel[0]
HEADERS: dict = {
"User-Agent": ("Mozilla/5.0 (Windows NT 10.0; rv:75.0) "
"Gecko/20100101 Firefox/75.0"),
"Accept-Language": "en-US;q=0.9,en;q=0.8,en-GB;q=0.7",
"X-Requested-With": "XMLHttpRequest",
"Connection": "keep-alive",
"Referer": str(channelsDict[channel]["data"]["referer"]),
"cb-enabled": "enabled",
"DNT": "1",
"Pragma": "no-cache",
"Cache-Control": "no-cache"
}
content = requests.get(
channelsDict[channel]["url"],
headers=HEADERS,
timeout=(3, 300)
)
content = {
"status_code": content.status_code,
"content": content.content,
"encoding": content.encoding,
"cookies": content.cookies,
"request": content.request,
"url": content.url,
"reason": content.reason,
"headers": content.headers,
"elapsed": content.elapsed,
"history": content.history
}
if content["status_code"] == 200:
uglyPayload = json.loads(content["content"].decode('unicode_escape')[1:-1])
print(
uglyPayload["data"]["attributes"]["streaming"]["hls"]["url"],
sep='',
end='',
file=sys.stdout,
flush=False
)
else:
print(
"[ERROR] Http status code: " + str(content["status_code"]),
sep='',
end='\n',
file=sys.stderr,
)
sys.exit(1)