Skip to content

Commit

Permalink
Better packaging for iptvtools.
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ce04005
Author: huxuan <i@huxuan.org>
Date:   Tue Mar 3 23:02:33 2020 +0800

    No relative import.

commit bfd878b
Author: huxuan <i@huxuan.org>
Date:   Tue Mar 3 22:59:14 2020 +0800

    Various packaging improvement.

commit 9bc059a
Author: huxuan <i@huxuan.org>
Date:   Mon Jan 20 12:27:41 2020 +0800

    Minor change.

commit 27d0e54
Author: huxuan <i@huxuan.org>
Date:   Sun Jan 19 22:34:51 2020 +0800

    Fix broken url in README.

commit ad68291
Author: huxuan <i@huxuan.org>
Date:   Tue Jan 14 15:31:51 2020 +0800

    Minor change in docs.
  • Loading branch information
huxuan committed Mar 3, 2020
1 parent 9d6478f commit 3148d65
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 71 deletions.
54 changes: 35 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
.PHONY: clean install dev lint pycodestyle pyflakes pylint dist upload docs
.PHONY: clean install dev flake8 pylint lint dist upload uploadtest test docs

PKG := $(shell basename $(CURDIR) | cut -d- -f1)
PIPRUN := $(shell command -v pipenv > /dev/null && echo pipenv run)

clean:
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -rf
find . -name '__pycache__' -print0 | xargs -0 rm -rf
-rm -rf build dist *.egg-info .eggs *.spec docs/_build
rm -rf build dist *.egg-info .eggs || true
rm -rf .tox .coverage cover || true
rm -rf docs/_build || true
rm -rf Pipfile.lock || true
rm -rf .vscode || true
command -v pipenv > /dev/null && \
pipenv --venv > /dev/null 2>&1 && \
pipenv --rm || true

install:
pip install .
command -v pipenv > /dev/null && \
pipenv install --skip-lock -e . || \
pip install -e .

dev:
pip install .[dev]

lint: pycodestyle pyflakes pylint

pycodestyle:
-pycodestyle setup.py iptvtools
command -v pipenv > /dev/null && \
pipenv install --skip-lock --dev || true

pyflakes:
-pyflakes setup.py iptvtools
flake8:
${PIPRUN} flake8 \
--import-order-style google \
--application-import-names ${PKG} \
setup.py tests ${PKG}

pylint:
-pylint setup.py iptvtools
${PIPRUN} pylint setup.py tests ${PKG}

dist: clean
python setup.py sdist bdist_wheel
lint: dev flake8 pylint

dist: clean install
${PIPRUN} python setup.py sdist bdist_wheel

upload:
twine upload dist/*
${PIPRUN} twine upload dist/*

uploadtest:
${PIPRUN} twine upload --repository-url https://test.pypi.org/legacy/ dist/*

docs: clean install
cd docs && make html
docs: install
cd docs && ${PIPRUN} make html

docsdeps:
pip install -r docs/requirements.txt
test: clean
tox
21 changes: 21 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "*"
flake8-commas = "*"
flake8-docstrings = "*"
flake8-import-order = "*"
pep8-naming = "*"
pylint = "*"
sphinx = "*"
sphinx-rtd-theme = "*"
sphinxcontrib-programoutput = "*"

[packages]
iptvtools = {editable = true,path = "."}

[requires]
python_version = "3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Scripts currently provided:

- [iptv-filter](https://github.com/huxuan/iptvtools/wiki/iptv%E2%80%90filter)
- [iptv-filter](https://iptvtools.readthedocs.io/en/latest/scripts/iptv-filter.html)
- Merge from different resources.
- Check the tcp/udp connectivity.
- Filter by custom criteria, e.g. resolution.
Expand Down
2 changes: 2 additions & 0 deletions docs/parameters.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Selected Parameters
===================

Here is some further explanation for those not so obvious parameters.

MIN_HEIGHT
----------

Expand Down
13 changes: 11 additions & 2 deletions iptvtools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Init for iptvtools.
File: __init__.py
Author: huxuan
Email: i(at)huxuan.org
Description: iptvtools package.
"""
__version__ = '0.1.6'
from pkg_resources import DistributionNotFound
from pkg_resources import get_distribution

__version__ = '0.0.0'
try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
# package is not installed
pass
4 changes: 3 additions & 1 deletion iptvtools/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Configuration for iptvtools.
File: config.py
Author: huxuan
Email: i(at)huxuan.org
Description: Configuration for iptvtools.
"""
import json
import os
Expand All @@ -13,6 +14,7 @@

class MetaConfig(type):
"""Configuration for iptvtools."""

config = {}

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions iptvtools/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Constants for iptvtools.
File: __init__.py
Author: huxuan
Email: i(at)huxuan.org
"""
3 changes: 2 additions & 1 deletion iptvtools/constants/defaults.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Defaults for iptvtools.
File: constants.py
Author: huxuan
Email: i(at)huxuan.org
Description: Defaults for iptvtools.
"""
CONFIG = 'config.json'
INPUT = 'https://iptv-org.github.io/iptv/index.m3u'
Expand Down
5 changes: 3 additions & 2 deletions iptvtools/constants/helps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Helps for iptvtools.
File: constants.py
Author: huxuan
Email: i(at)huxuan.org
Description: Helps for iptvtools.
"""
from . import defaults
from iptvtools.constants import defaults

CONFIG = (
f'Configuration file to unify title and id information, defaults to '
Expand Down
3 changes: 2 additions & 1 deletion iptvtools/constants/patterns.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Patterns for iptvtools.
File: constants.py
Author: huxuan
Email: i(at)huxuan.org
Description: Patterns for iptvtools.
"""
import re

Expand Down
3 changes: 2 additions & 1 deletion iptvtools/constants/tags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tags for iptvtools.
File: constants.py
Author: huxuan
Email: i(at)huxuan.org
Description: Tags for iptvtools.
"""
M3U = '#EXTM3U'
INF = '#EXTINF'
15 changes: 8 additions & 7 deletions iptvtools/iptv_filter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Filter IPTV m3u playlists according to customized criteria.
File: main.py
Author: huxuan
Email: i(at)huxuan.org
Description: Filter IPTV m3u playlists according to customized criteria.
"""
import argparse

from . import __version__
from .config import Config
from .constants import defaults
from .constants import helps
from .models import Playlist
from iptvtools import __version__
from iptvtools.config import Config
from iptvtools.constants import defaults
from iptvtools.constants import helps
from iptvtools.models import Playlist


def parse_args():
Expand Down Expand Up @@ -42,7 +43,7 @@ def parse_args():


def main():
"""Main process."""
"""Filter m3u playlists."""
args = parse_args()
if not args.input:
args.input = [defaults.INPUT]
Expand Down
16 changes: 9 additions & 7 deletions iptvtools/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Playlist which contains all the channels' information.
File: models.py
Author: huxuan
Email: i(at)huxuan.org
Description: Playlist which contains all the channels' information.
"""
import os.path
import random
Expand All @@ -13,14 +14,16 @@

from tqdm import tqdm

from . import parsers
from . import utils
from .constants import tags
from iptvtools import parsers
from iptvtools import utils
from iptvtools.constants import tags


class Playlist():
"""Playlist model."""

def __init__(self):
"""Init for Playlist."""
self.data = {}
self.template = {}
self.valid_urls = set()
Expand All @@ -46,8 +49,7 @@ def export(self, args):
params = ' '.join([f'{key}="{value}"'
for key, value in params_dict.items()])
res.append(
f'{tags.INF}:{entry["duration"]} {params},{entry["title"]}'
)
f'{tags.INF}:{entry["duration"]} {params},{entry["title"]}')
res.append(url)
return '\n'.join(res)

Expand All @@ -57,7 +59,7 @@ def parse(self, args):
self._parse(args.template, is_template=True)

def _parse(self, sources, udpxy=None, is_template=False):
"""Internal implementation of parsing."""
"""Parse playlist sources."""
for source in sources:
lines = parsers.parse_content_to_lines(source)
source_name = os.path.splitext(os.path.basename(source))[0]
Expand Down
7 changes: 4 additions & 3 deletions iptvtools/parsers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Simplified parser for m3u8 file.
File: parser.py
Author: huxuan
Email: i(at)huxuan.org
Description: Simplified parser for m3u8 file.
"""
from urllib.request import urlopen
import os.path
from urllib.request import urlopen

from .constants import patterns
from iptvtools.constants import patterns


def parse_content_to_lines(content):
Expand Down
9 changes: 5 additions & 4 deletions iptvtools/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Relevant Utilities.
File: utils.py
Author: huxuan
Email: i(at)huxuan.org
Description: Relevant Utilities.
"""
import json
import socket
import struct
from subprocess import PIPE
from subprocess import Popen
from subprocess import TimeoutExpired
from urllib.parse import urlparse
import json

import requests

from .config import Config
from iptvtools.config import Config

PROBE_COMMAND = (
'ffprobe -hide_banner -show_streams -select_streams v '
Expand All @@ -25,7 +26,7 @@

UDP_SCHEME = (
'udp',
'rtp'
'rtp',
)


Expand Down
Loading

0 comments on commit 3148d65

Please sign in to comment.