Skip to content

Commit

Permalink
Support sorting by template order. (#21)
Browse files Browse the repository at this point in the history
* 新的排序方式 template-order

* 新的排序方式 template-order

* Update models.py
  • Loading branch information
Sowevo authored Feb 8, 2022
1 parent c13578c commit 94ab7b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion iptvtools/constants/helps.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
)
SORT_KEYS = (
'List of keys to sort the channels. Valid options currently supported '
'are `group-title`, `tvg-id`, `height` and `title`.'
'are `group-title`, `tvg-id`, `template-order`, `height` and `title`.'
)
TEMPLATES = (
'Template m3u files/urls with well-maintained channel information to '
Expand Down
7 changes: 6 additions & 1 deletion iptvtools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def parse(self):

def _parse(self, sources, is_template=False):
"""Parse playlist sources."""
template_order = 0
for source in sources:
source_name = os.path.splitext(os.path.basename(source))[0]
current_item = {}
Expand Down Expand Up @@ -120,8 +121,10 @@ def _parse(self, sources, is_template=False):

else:
if is_template:
template_order = template_order + 1
for url in self.id_url.get(current_id, []):
current_params = current_item['params']
current_params['template-order'] = template_order
self.data[url]['params'].update(current_params)
self.data[url]['title'] = current_item['title']
else:
Expand Down Expand Up @@ -158,7 +161,7 @@ def filter(self):
pbar.write(f'{url}, {status}!')

def __custom_sort(self, url):
"""Sort by tvg-id, resolution and title."""
"""Sort by tvg-id, resolution, template-order and title."""
res = []
for key in self.args.sort_keys:
entry = self.data[url]
Expand All @@ -168,6 +171,8 @@ def __custom_sort(self, url):
res.append(entry.get(key, ''))
elif key == 'tvg-id':
res.append(int(entry['params'].get(key) or sys.maxsize))
elif key == 'template-order':
res.append(int(entry['params'].get(key) or sys.maxsize))
elif key == 'group-title':
res.append(entry['params'].get(key) or '')
return res

0 comments on commit 94ab7b7

Please sign in to comment.