From 162f357febe58b5f94b4be6aa42778c14e1e5cb6 Mon Sep 17 00:00:00 2001
From: "Xuan (Sean) Hu" <i@huxuan.org>
Date: Thu, 20 May 2021 13:07:22 +0800
Subject: [PATCH] Fix group/channel filter bug. (#13)

---
 iptvtools/models.py | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/iptvtools/models.py b/iptvtools/models.py
index 7389a37..91ea4c4 100644
--- a/iptvtools/models.py
+++ b/iptvtools/models.py
@@ -96,30 +96,27 @@ def _parse(self, sources, is_template=False):
                     current_item = utils.unify_title_and_id(current_item)
                     current_id = current_item['id']
 
-                    if not skip and current_item.get('params') and \
-                            current_item['params'].get('group-title'):
-                        group = current_item['params']['group-title']
-                        if not skip and self.args.group_include:
-                            if re.search(self.args.group_include, group):
-                                logging.debug(f'Group to include: `{group}`.')
-                            else:
-                                skip = True
-                        if not skip and self.args.group_exclude and \
-                                re.search(self.args.group_exclude, group):
+                    group = current_item.get('params', {}).get('group-title')
+                    if not skip and self.args.group_include:
+                        if re.search(self.args.group_include, group):
+                            logging.debug(f'Group to include: `{group}`.')
+                        else:
                             skip = True
-                            logging.debug(f'Group to exclude: `{group}`.')
-
-                    if not skip and current_item.get('title'):
-                        title = current_item['title']
-                        if not skip and self.args.channel_include:
-                            if re.search(self.args.channel_include, title):
-                                logging.debug(f'Channel to include: `{title}`.')
-                            else:
-                                skip = True
-                        if not skip and self.args.channel_exclude and \
-                                re.search(self.args.channel_exclude, title):
+                    if not skip and self.args.group_exclude and \
+                            re.search(self.args.group_exclude, group):
+                        skip = True
+                        logging.debug(f'Group to exclude: `{group}`.')
+
+                    title = current_item.get('title')
+                    if not skip and self.args.channel_include:
+                        if re.search(self.args.channel_include, title):
+                            logging.debug(f'Channel to include: `{title}`.')
+                        else:
                             skip = True
-                            logging.debug(f'Channel to exclude: `{title}`.')
+                    if not skip and self.args.channel_exclude and \
+                            re.search(self.args.channel_exclude, title):
+                        skip = True
+                        logging.debug(f'Channel to exclude: `{title}`.')
 
                 else:
                     if is_template: