pyxtream 0.7.3__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyxtream
3
+ Version: 0.9.0
4
+ Summary: xtream IPTV loader
5
+ License-Expression: GPL-3.0-or-later
6
+ License-File: LICENSE
7
+ Author: Claudio Olmi
8
+ Author-email: <superolmo2@gmail.com>
9
+ Requires-Python: >=3.9
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Natural Language :: English
17
+ Provides-Extra: flask
18
+ Requires-Dist: flask (>=3.1.0,<4.0.0) ; extra == "flask"
19
+ Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
20
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # 📺 PyXtream
24
+
25
+ [![PyPI version](https://img.shields.io/pypi/v/pyxtream.svg)](https://pypi.org/project/pyxtream/)
26
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
27
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
28
+
29
+ **PyXtream** is a high-performance, asynchronous-friendly Python library designed to interface with Xtream Codes IPTV panels. It handles authentication, data ingestion, caching, and stream management with a focus on precision and reliability.
30
+
31
+ Originally engineered to power [Hypnotix](https://github.com/linuxmint/hypnotix), PyXtream is optimized for applications requiring structured access to Live TV, VOD, and Series content.
32
+
33
+ ---
34
+
35
+ ## ✨ Key Features
36
+
37
+ - **🚀 Industrial Grade Ingestion**: Efficiently loads thousands of channels and groups into structured Python objects.
38
+ - **🔒 Full Instance Isolation**: Built for multi-provider environments. Every instance maintains its own groups, channels, and state without global side effects.
39
+ - **📁 Smart Caching & Offline Fallback**: Integrated file-based caching with configurable TTL (`reload_time_sec=-1` for persistence mode) and automatic fallback to local cache when the provider is unreachable.
40
+ - **🛡️ Schema Validation**: Uses `jsonschema` to validate provider responses, ensuring data integrity against non-standard API implementations.
41
+ - **🔍 Advanced Search**: Regex-powered searching across Live, VOD, and Series collections, with optional `added_after` date filtering.
42
+ - **📥 Stream Downloader**: Robust video downloading with built-in **resume support** (HTTP Range headers) and automatic stream type resolution.
43
+ - **🌐 REST API & Web UI**: Optional Flask-based microservice and Bootstrap 5 / Video.js viewer with lazy-loaded movie details, `.ts` Live TV/VOD playback (via `ffmpeg`), language filtering, and account expiration countdown.
44
+ - **📅 EPG Support**: Full access to XMLTV data and short-term EPG for live channels.
45
+
46
+ ---
47
+
48
+ ## 📦 Installation
49
+
50
+ Install the core library:
51
+
52
+ ```shell
53
+ pip install pyxtream
54
+ ```
55
+
56
+ Optionally, to use the REST API service and Web UI, install the `flask` extra (and have `ffmpeg` installed on `PATH` for `.ts` stream playback in the browser):
57
+
58
+ ```shell
59
+ pip install pyxtream[flask]
60
+ ```
61
+
62
+
63
+ # Quick Start
64
+
65
+ ## Your own application
66
+
67
+ Integrating in your application is simple. Initialization and loading of IPTV channels and groups is done with the following code.
68
+
69
+ ```python
70
+ from pyxtream import XTream
71
+ xt = XTream(servername, username, password, url)
72
+ if xt.auth_data != {}:
73
+ xt.load_iptv()
74
+ else:
75
+ print("Could not connect")
76
+ ```
77
+
78
+ Once completed, all the data can be found in `xTream.groups`, `xTream.channels`, `xTream.movies`, `xTream.series`. Series do not contains the information for all the Seasons and Episodes. Those are loaded separately when needed by calling the following function using a Series object from `xTream.series` array of dictionaries.
79
+
80
+ ```python
81
+ xt.get_series_info_by_id(series_obj)
82
+ ```
83
+
84
+ At this point, the `series_obj` will have both Seasons and Episodes populated.
85
+
86
+ ## Functional Test
87
+
88
+ To run the functional test, you can create a `.env` file in the project root with your provider credentials:
89
+
90
+ ```env
91
+ PROVIDER_NAME="My Provider"
92
+ PROVIDER_URL="http://example.com:8080"
93
+ PROVIDER_USERNAME="your_username"
94
+ PROVIDER_PASSWORD="your_password"
95
+ ```
96
+ Alternatively, you can modify the variables directly in `functional_test.py`. Start the application with:
97
+
98
+ ```shell
99
+ python3 functional_test.py
100
+ ```
101
+
102
+ The functional test will allow you to authenticate on startup, load and search streams. If Flask is installed, a simple website will be available at http://localhost:5000 to allow you to search and play streams.
103
+
104
+ ## 🧪 Testing
105
+
106
+ To run unit tests and generate an interactive HTML coverage report:
107
+
108
+ ```shell
109
+ python3 -m pytest --cov=pyxtream --cov-report=html test/test_pyxtream.py
110
+ ```
111
+
112
+ The report will be generated in the `htmlcov/` directory. Open `htmlcov/index.html` in your web browser to view the detailed results.
113
+
114
+ ## Applications using PyXtream
115
+
116
+ Applications using PyXtream PYPI package
117
+
118
+ - xtreamPOC - https://github.com/sght500/xtreamPOC - Project is a Proof of Concept (POC) that leverages pyxtream, MPV, and NiceGUI to demonstrate the use of Xtream Portal Codes.
119
+
120
+ Applications using PyXtream files
121
+
122
+ - Hypnotix - https://github.com/linuxmint/hypnotix - Hypnotix is an IPTV streaming application with support for live TV, movies and series.
123
+
124
+ # API
125
+
126
+ ## Classes:
127
+
128
+ Below are the domain classes exported by `pyxtream`. They are heavily influenced by the application Hypnotix.
129
+
130
+ - `Channel`
131
+ - `Group`
132
+ - `Episode`
133
+ - `Serie`
134
+ - `Season`
135
+
136
+ ## Instance Collections:
137
+
138
+ `xt.groups` (`list[Group]`)
139
+
140
+ `xt.channels` (`list[Channel]`)
141
+
142
+ `xt.series` (`list[Serie]`)
143
+
144
+ `xt.movies` (`list[Channel]`)
145
+
146
+ ## Functions:
147
+
148
+ - `xt.authenticate()`
149
+ - `xt.load_iptv()`
150
+ - `xt.get_series_info_by_id(get_series: Serie)`
151
+ - `xt.search_stream(keyword: str, ignore_case: bool = True, return_type: str = "LIST", stream_type: list = ("series", "movies", "channels"), added_after: datetime = None)`
152
+ - `xt.download_video(stream_id: int)`
153
+ - `xt.get_download_progress(stream_id: int = None)`
154
+ - `xt.get_last_7days()` / `xt.get_last_30days()`
155
+ - `xt.get_state()`
156
+ - `xt.vodInfoByID(vod_id, return_type: str = "DICT")`
157
+ - `xt.liveEpgByStream(stream_id)`
158
+ - `xt.liveEpgByStreamAndLimit(stream_id, limit)`
159
+ - `xt.allLiveEpgByStream(stream_id)`
160
+ - `xt.allEpg()`
161
+
162
+ # Versioning
163
+ Follows the Semantic Versioning from https://semver.org/
164
+ - Increment the MAJOR version when you make incompatible API changes.
165
+ - Increment the MINOR version when you add functionality in a backwards-compatible manner.
166
+ - Increment the PATCH version when you make backwards-compatible bug fixes.
167
+
168
+ Detailed history of changes can be found in the [CHANGELOG.md](CHANGELOG.md) file.
169
+
@@ -0,0 +1,146 @@
1
+ # 📺 PyXtream
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/pyxtream.svg)](https://pypi.org/project/pyxtream/)
4
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
5
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
6
+
7
+ **PyXtream** is a high-performance, asynchronous-friendly Python library designed to interface with Xtream Codes IPTV panels. It handles authentication, data ingestion, caching, and stream management with a focus on precision and reliability.
8
+
9
+ Originally engineered to power [Hypnotix](https://github.com/linuxmint/hypnotix), PyXtream is optimized for applications requiring structured access to Live TV, VOD, and Series content.
10
+
11
+ ---
12
+
13
+ ## ✨ Key Features
14
+
15
+ - **🚀 Industrial Grade Ingestion**: Efficiently loads thousands of channels and groups into structured Python objects.
16
+ - **🔒 Full Instance Isolation**: Built for multi-provider environments. Every instance maintains its own groups, channels, and state without global side effects.
17
+ - **📁 Smart Caching & Offline Fallback**: Integrated file-based caching with configurable TTL (`reload_time_sec=-1` for persistence mode) and automatic fallback to local cache when the provider is unreachable.
18
+ - **🛡️ Schema Validation**: Uses `jsonschema` to validate provider responses, ensuring data integrity against non-standard API implementations.
19
+ - **🔍 Advanced Search**: Regex-powered searching across Live, VOD, and Series collections, with optional `added_after` date filtering.
20
+ - **📥 Stream Downloader**: Robust video downloading with built-in **resume support** (HTTP Range headers) and automatic stream type resolution.
21
+ - **🌐 REST API & Web UI**: Optional Flask-based microservice and Bootstrap 5 / Video.js viewer with lazy-loaded movie details, `.ts` Live TV/VOD playback (via `ffmpeg`), language filtering, and account expiration countdown.
22
+ - **📅 EPG Support**: Full access to XMLTV data and short-term EPG for live channels.
23
+
24
+ ---
25
+
26
+ ## 📦 Installation
27
+
28
+ Install the core library:
29
+
30
+ ```shell
31
+ pip install pyxtream
32
+ ```
33
+
34
+ Optionally, to use the REST API service and Web UI, install the `flask` extra (and have `ffmpeg` installed on `PATH` for `.ts` stream playback in the browser):
35
+
36
+ ```shell
37
+ pip install pyxtream[flask]
38
+ ```
39
+
40
+
41
+ # Quick Start
42
+
43
+ ## Your own application
44
+
45
+ Integrating in your application is simple. Initialization and loading of IPTV channels and groups is done with the following code.
46
+
47
+ ```python
48
+ from pyxtream import XTream
49
+ xt = XTream(servername, username, password, url)
50
+ if xt.auth_data != {}:
51
+ xt.load_iptv()
52
+ else:
53
+ print("Could not connect")
54
+ ```
55
+
56
+ Once completed, all the data can be found in `xTream.groups`, `xTream.channels`, `xTream.movies`, `xTream.series`. Series do not contains the information for all the Seasons and Episodes. Those are loaded separately when needed by calling the following function using a Series object from `xTream.series` array of dictionaries.
57
+
58
+ ```python
59
+ xt.get_series_info_by_id(series_obj)
60
+ ```
61
+
62
+ At this point, the `series_obj` will have both Seasons and Episodes populated.
63
+
64
+ ## Functional Test
65
+
66
+ To run the functional test, you can create a `.env` file in the project root with your provider credentials:
67
+
68
+ ```env
69
+ PROVIDER_NAME="My Provider"
70
+ PROVIDER_URL="http://example.com:8080"
71
+ PROVIDER_USERNAME="your_username"
72
+ PROVIDER_PASSWORD="your_password"
73
+ ```
74
+ Alternatively, you can modify the variables directly in `functional_test.py`. Start the application with:
75
+
76
+ ```shell
77
+ python3 functional_test.py
78
+ ```
79
+
80
+ The functional test will allow you to authenticate on startup, load and search streams. If Flask is installed, a simple website will be available at http://localhost:5000 to allow you to search and play streams.
81
+
82
+ ## 🧪 Testing
83
+
84
+ To run unit tests and generate an interactive HTML coverage report:
85
+
86
+ ```shell
87
+ python3 -m pytest --cov=pyxtream --cov-report=html test/test_pyxtream.py
88
+ ```
89
+
90
+ The report will be generated in the `htmlcov/` directory. Open `htmlcov/index.html` in your web browser to view the detailed results.
91
+
92
+ ## Applications using PyXtream
93
+
94
+ Applications using PyXtream PYPI package
95
+
96
+ - xtreamPOC - https://github.com/sght500/xtreamPOC - Project is a Proof of Concept (POC) that leverages pyxtream, MPV, and NiceGUI to demonstrate the use of Xtream Portal Codes.
97
+
98
+ Applications using PyXtream files
99
+
100
+ - Hypnotix - https://github.com/linuxmint/hypnotix - Hypnotix is an IPTV streaming application with support for live TV, movies and series.
101
+
102
+ # API
103
+
104
+ ## Classes:
105
+
106
+ Below are the domain classes exported by `pyxtream`. They are heavily influenced by the application Hypnotix.
107
+
108
+ - `Channel`
109
+ - `Group`
110
+ - `Episode`
111
+ - `Serie`
112
+ - `Season`
113
+
114
+ ## Instance Collections:
115
+
116
+ `xt.groups` (`list[Group]`)
117
+
118
+ `xt.channels` (`list[Channel]`)
119
+
120
+ `xt.series` (`list[Serie]`)
121
+
122
+ `xt.movies` (`list[Channel]`)
123
+
124
+ ## Functions:
125
+
126
+ - `xt.authenticate()`
127
+ - `xt.load_iptv()`
128
+ - `xt.get_series_info_by_id(get_series: Serie)`
129
+ - `xt.search_stream(keyword: str, ignore_case: bool = True, return_type: str = "LIST", stream_type: list = ("series", "movies", "channels"), added_after: datetime = None)`
130
+ - `xt.download_video(stream_id: int)`
131
+ - `xt.get_download_progress(stream_id: int = None)`
132
+ - `xt.get_last_7days()` / `xt.get_last_30days()`
133
+ - `xt.get_state()`
134
+ - `xt.vodInfoByID(vod_id, return_type: str = "DICT")`
135
+ - `xt.liveEpgByStream(stream_id)`
136
+ - `xt.liveEpgByStreamAndLimit(stream_id, limit)`
137
+ - `xt.allLiveEpgByStream(stream_id)`
138
+ - `xt.allEpg()`
139
+
140
+ # Versioning
141
+ Follows the Semantic Versioning from https://semver.org/
142
+ - Increment the MAJOR version when you make incompatible API changes.
143
+ - Increment the MINOR version when you add functionality in a backwards-compatible manner.
144
+ - Increment the PATCH version when you make backwards-compatible bug fixes.
145
+
146
+ Detailed history of changes can be found in the [CHANGELOG.md](CHANGELOG.md) file.
@@ -1,10 +1,10 @@
1
1
  [project]
2
2
  name = "pyxtream"
3
- version = "0.7.3"
3
+ version = "0.9.0"
4
4
  requires-python = ">=3.9"
5
5
  description = "xtream IPTV loader"
6
6
  authors = [{name = "Claudio Olmi", email = "<superolmo2@gmail.com>"}]
7
- license = "GPL3"
7
+ license = "GPL-3.0-or-later"
8
8
  readme = "README.md"
9
9
  homepage = "https://github.com/superolmo/pyxtream"
10
10
  classifiers = [
@@ -28,6 +28,7 @@ flask = ["flask>=3.1.0,<4.0.0"]
28
28
  pdoc = "^15.0.1"
29
29
  pytest = "^8.3.4"
30
30
  pytest-cov = "^6.0.0"
31
+ python-dotenv = "^1.0.1"
31
32
 
32
33
  [build-system]
33
34
  requires = ["poetry-core"]
@@ -1,6 +1,5 @@
1
1
 
2
- from .progress import progress
3
- from .pyxtream import XTream, Channel, Group, Serie, Episode
2
+ from .pyxtream import Channel, Episode, Group, Season, Serie, XTream
4
3
 
5
4
  try:
6
5
  from .rest_api import FlaskWrap
@@ -0,0 +1,63 @@
1
+ """
2
+ API URL builders
3
+ """
4
+
5
+
6
+ def get_live_categories_URL(base: str) -> str:
7
+ return f"{base}&action=get_live_categories"
8
+
9
+
10
+ def get_live_streams_URL(base: str) -> str:
11
+ return f"{base}&action=get_live_streams"
12
+
13
+
14
+ def get_live_streams_URL_by_category(category_id, base: str) -> str:
15
+ return f"{base}&action=get_live_streams&category_id={category_id}"
16
+
17
+
18
+ def get_vod_cat_URL(base: str) -> str:
19
+ return f"{base}&action=get_vod_categories"
20
+
21
+
22
+ def get_vod_streams_URL(base: str) -> str:
23
+ return f"{base}&action=get_vod_streams"
24
+
25
+
26
+ def get_vod_streams_URL_by_category(category_id, base: str) -> str:
27
+ return f"{base}&action=get_vod_streams&category_id={category_id}"
28
+
29
+
30
+ def get_series_cat_URL(base: str) -> str:
31
+ return f"{base}&action=get_series_categories"
32
+
33
+
34
+ def get_series_URL(base: str) -> str:
35
+ return f"{base}&action=get_series"
36
+
37
+
38
+ def get_series_URL_by_category(category_id, base: str) -> str:
39
+ return f"{base}&action=get_series&category_id={category_id}"
40
+
41
+
42
+ def get_series_info_URL_by_ID(series_id, base: str) -> str:
43
+ return f"{base}&action=get_series_info&series_id={series_id}"
44
+
45
+
46
+ def get_VOD_info_URL_by_ID(vod_id, base: str) -> str:
47
+ return f"{base}&action=get_vod_info&vod_id={vod_id}"
48
+
49
+
50
+ def get_live_epg_URL_by_stream(stream_id, base: str) -> str:
51
+ return f"{base}&action=get_short_epg&stream_id={stream_id}"
52
+
53
+
54
+ def get_live_epg_URL_by_stream_and_limit(stream_id, limit, base: str) -> str:
55
+ return f"{base}&action=get_short_epg&stream_id={stream_id}&limit={limit}"
56
+
57
+
58
+ def get_all_live_epg_URL_by_stream(stream_id, base: str) -> str:
59
+ return f"{base}&action=get_simple_data_table&stream_id={stream_id}"
60
+
61
+
62
+ def get_all_epg_URL(base: str, username: str, password: str) -> str:
63
+ return f"{base}/xmltv.php?username={username}&password={password}"
@@ -0,0 +1,26 @@
1
+ """
2
+ Centralized constants for the pyxtream library
3
+ """
4
+
5
+ SSL_FIRST = True
6
+ SECONDS_IN_DAY = 86400
7
+ SECONDS_IN_YEAR = 31536000
8
+ DEFAULT_RELOAD_TIME_SEC = 28800 # 8 hours
9
+ DEFAULT_FLASK_PORT = 5000
10
+
11
+ AUTH_MAX_ATTEMPTS = 3
12
+ AUTH_TIMEOUT_SEC = 4
13
+ AUTH_LOOP_EXIT_VALUE = 31
14
+
15
+ REQUEST_MAX_ATTEMPTS = 10
16
+ REQUEST_DEFAULT_TIMEOUT = (2, 15)
17
+ DOWNLOAD_TIMEOUT_SEC = 10
18
+
19
+ KB_FACTOR = 1024
20
+ MB_FACTOR = 1024 * 1024
21
+ DOWNLOAD_BLOCK_SIZE = 4 * MB_FACTOR
22
+ REQUEST_BLOCK_SIZE = 1 * MB_FACTOR
23
+
24
+ CATCH_ALL_CATEGORY_ID = 9999
25
+ MOVIES_RECENT_30_DAYS_THRESHOLD = 31
26
+ MOVIES_RECENT_7_DAYS_THRESHOLD = 7