Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6c01bd0
Author: huxuan <[email protected]>
Date:   Fri Jan 3 14:12:57 2020 +0800

    More robust udpxy.

commit 438f849
Author: huxuan <[email protected]>
Date:   Fri Jan 3 14:10:21 2020 +0800

    Better version.

commit 123de08
Author: huxuan <[email protected]>
Date:   Fri Jan 3 13:33:58 2020 +0800

    Change filter to unify.
  • Loading branch information
huxuan committed Jan 3, 2020
1 parent f2c4de1 commit 3d36e9d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id_filters": {
"id_unifiers": {
"-": "",
"IPTV": "",
"BTV冬奥纪实": "北京纪实",
Expand All @@ -11,7 +11,7 @@
"CETV4": "中国教育4台",
"纪实频道": "上海纪实"
},
"title_filters": {
"title_unifiers": {
"高清": "",
"HD": "",
"+": "+"
Expand Down
9 changes: 9 additions & 0 deletions iptvtools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
File: __init__.py
Author: huxuan
Email: i(at)huxuan.org
Description: iptvtools package.
"""
__version__ = '0.1.2'
2 changes: 1 addition & 1 deletion iptvtools/constants/helps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import defaults

CONFIG = (
f'Configuration file with title and id filter information, defaults to '
f'Configuration file to unify title and id information, defaults to '
f'`{defaults.CONFIG}`'
)
INPUT = (
Expand Down
3 changes: 3 additions & 0 deletions iptvtools/iptv_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import argparse

from . import __version__
from .config import Config
from .constants import defaults
from .constants import helps
Expand All @@ -31,6 +32,8 @@ def parse_args():
help=helps.TIMEOUT)
parser.add_argument('-u', '--udpxy', default=defaults.UDPXY,
help=helps.UDPXY)
parser.add_argument('-v', '--version', action='version',
version=__version__)
return parser.parse_args()


Expand Down
2 changes: 1 addition & 1 deletion iptvtools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def parse(self, content, udpxy=None, is_template=False):
continue
if line.startswith(tags.INF):
current_item = parsers.parse_tag_inf(line)
current_item = utils.filter_title_and_id(current_item)
current_item = utils.unify_title_and_id(current_item)
else:
if is_template:
self.template[current_item['id']] = current_item
Expand Down
32 changes: 19 additions & 13 deletions iptvtools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@
'-of json=c=1 -v quiet'
)

ACCEPT_SCHEME = (
'udp',
'rtp'
)


def convert_url_with_udpxy(orig_url, udpxy):
"""Convert url with udpxy."""
orig_url = orig_url.replace('///', '//') # Hack to some abnormal urls.
orig_url = orig_url.replace('///', '//') # Hack for some abnormal urls.
parsed_url = urlparse(orig_url)
new_url = f'{udpxy}/{parsed_url.scheme}/{parsed_url.netloc}'
return new_url
if parsed_url.scheme in ACCEPT_SCHEME:
return f'{udpxy}/{parsed_url.scheme}/{parsed_url.netloc}'
return orig_url


def filter_title_and_id(item):
"""Filter title and id."""
for title_filter in sorted(Config().title_filters):
if title_filter in item['title']:
def unify_title_and_id(item):
"""Unify title and id."""
for title_unifier in sorted(Config().title_unifiers):
if title_unifier in item['title']:
item['title'] = item['title'].replace(
title_filter,
Config().title_filters[title_filter])
title_unifier,
Config().title_unifiers[title_unifier])

if 'tvg-name' in item.get('params'):
item['id'] = item['params']['tvg-name']
else:
item['id'] = item['title']

for id_filter in sorted(Config().id_filters):
if id_filter in item['id']:
for id_unifier in sorted(Config().id_unifiers):
if id_unifier in item['id']:
item['id'] = item['id'].replace(
id_filter,
Config().id_filters[id_filter])
id_unifier,
Config().id_unifiers[id_unifier])

return item

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from setuptools import find_packages
from setuptools import setup

import iptvtools

DESCRIPTION = (
'A set of scripts that help to better IPTV experience.'
)
Expand Down Expand Up @@ -43,7 +45,7 @@ def readme():


setup(name='iptvtools',
version='0.1.1',
version=iptvtools.__version__,
description=DESCRIPTION,
long_description=readme(),
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 3d36e9d

Please sign in to comment.