Skip to content

Commit

Permalink
feat: support multiple channel list file
Browse files Browse the repository at this point in the history
  • Loading branch information
JinnLynn committed Aug 22, 2024
1 parent aa42b02 commit aac2c30
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions iptv.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,31 @@ def whitelist(self):
return self._whitelist

def load_channels(self):
current = ''
with open(IPTV_CHANNEL) as fp:
for line in fp.readlines():
line = line.strip()
if not line or line.startswith('#'):
continue
if line.startswith('CATE:'):
current = line[5:].strip()
self.channel_cates.setdefault(current, OrderedSet())
else:
if current:
self.channel_cates[current].add(line)
self.channels.setdefault(line, [])
for f in IPTV_CHANNEL.split(','):
current = ''
with open(f) as fp:
for line in fp.readlines():
line = line.strip()
if not line or line.startswith('#'):
continue
if line.startswith('CATE:'):
current = line[5:].strip()
self.channel_cates.setdefault(current, OrderedSet())
else:
if not current:
logging.warning(f'忽略没有指定分类的频道: {line}')
continue

if line.startswith('-'):
line = line[1:].strip()
if line in self.channel_cates[current]:
self.channel_cates[current].remove(line)
else:
self.channel_cates[current].add(line)

for v in self.channel_cates.values():
for c in v:
self.channels.setdefault(c, [])

def fetch(self, url):
headers = {'User-Agent': DEF_USER_AGENT}
Expand Down

0 comments on commit aac2c30

Please sign in to comment.