-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathiptv-list.py
113 lines (95 loc) · 3.26 KB
/
iptv-list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from sniff.web_live import web_live
from sniff.utils.m3u import m3u
from sniff.utils.tv import tv
import importlib
import argparse
import logging
import json
import sys
import os
def load_module(string):
module = importlib.import_module("sniff.plugins.%s"%(string))
return getattr(module, string)
def iptv_list(config, addr, path, logger):
tv_obj = tv.load(config, logger)
playlist = os.path.join(path, tv_obj.m3ulist)
m3ulist = m3u.loads("", logger)
print(tv_obj.source)
for source in tv_obj.source:
if not os.path.exists(source):
logger.error("%s is not existed!"%(source))
continue
with open(source) as file_obj:
tvlive = json.load(file_obj)
for info in tvlive:
active = info["active"]
if active == 0:
continue
headers = info["headers"]
referer = info["referer"]
extinfo = [
info["m3uinfo"]["tvg-id"],
info["m3uinfo"]["tvg-name"],
info["m3uinfo"]["tvg-logo"],
info["m3uinfo"]["group-title"],
info["m3uinfo"]["title"]
]
channel = extinfo
if addr:
link = "http://%s/channel?%s"%(addr, info["m3u8"])
else:
link = "http://%s:%s/channel?%s"%(tv_obj.server["ip"], tv_obj.server["port"], info["m3u8"])
channel.append(link)
channel.append(headers["Referer"] if referer == 1 else "")
m3ulist.update_channel(channel)
m3ulist.dump_m3u(playlist)
m3ulist.dump_txt(os.path.join(path, tv_obj.txtlist))
if __name__ == '__main__':
parser=argparse.ArgumentParser(
description='web tv playlist generate tool'
)
parser.add_argument(
"-v",
"--verbosity",
action="count",
default=0,
help="increase output verbosity"
)
parser.add_argument(
"-c",
"--config",
action="store",
default="tv.json",
required=False,
help="web sniff configure file"
)
parser.add_argument(
"-a",
"--addr",
action="store",
default="",
required=False,
help="iptv proxy server address (192.168.1.1:8080)"
)
parser.add_argument(
"-o",
"--output",
action="store",
default="playlist",
required=False,
help="m3u or txt playlist/m3u8 files store path"
)
args = parser.parse_args()
log_level = args.verbosity
if log_level == 0:
logging_level = logging.WARN
if log_level == 1:
logging_level = logging.INFO
if log_level >= 2:
logging_level = logging.DEBUG
logging.basicConfig(format="%(asctime)s %(name)s: %(levelname)s: %(message)s",
datefmt="%d-%M-%Y %H:%M:%S",
level=logging_level
)
logger = logging.getLogger("iptv list")
iptv_list(args.config, args.addr, args.output, logger)