pyxtream 0.7.0__tar.gz → 0.7.2__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.
- {pyxtream-0.7.0/pyxtream.egg-info → pyxtream-0.7.2}/PKG-INFO +20 -10
- pyxtream-0.7.0/PKG-INFO → pyxtream-0.7.2/README.md +5 -23
- pyxtream-0.7.2/pyproject.toml +30 -0
- pyxtream-0.7.2/pyxtream/html/index.html +359 -0
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/pyxtream.py +187 -98
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/rest_api.py +3 -6
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/schemaValidator.py +1 -1
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/version.py +1 -1
- pyxtream-0.7.0/README.md +0 -124
- pyxtream-0.7.0/pyxtream.egg-info/SOURCES.txt +0 -14
- pyxtream-0.7.0/pyxtream.egg-info/dependency_links.txt +0 -1
- pyxtream-0.7.0/pyxtream.egg-info/requires.txt +0 -3
- pyxtream-0.7.0/pyxtream.egg-info/top_level.txt +0 -1
- pyxtream-0.7.0/setup.cfg +0 -4
- pyxtream-0.7.0/setup.py +0 -37
- {pyxtream-0.7.0 → pyxtream-0.7.2}/LICENSE +0 -0
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/__init__.py +0 -0
- {pyxtream-0.7.0 → pyxtream-0.7.2}/pyxtream/progress.py +0 -0
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyxtream
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: xtream IPTV loader
|
|
5
|
-
|
|
5
|
+
License: GPL3
|
|
6
6
|
Author: Claudio Olmi
|
|
7
7
|
Author-email: superolmo2@gmail.com
|
|
8
|
-
|
|
9
|
-
Platform: UNKNOWN
|
|
8
|
+
Requires-Python: >=3.9
|
|
10
9
|
Classifier: Development Status :: 4 - Beta
|
|
11
10
|
Classifier: Environment :: Console
|
|
12
11
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
12
|
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
15
|
-
Classifier:
|
|
13
|
+
Classifier: License :: Other/Proprietary License
|
|
16
14
|
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Requires-Dist: flask (>=2.2.2)
|
|
24
|
+
Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
|
|
25
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
17
26
|
Description-Content-Type: text/markdown
|
|
18
|
-
Provides-Extra: REST_API
|
|
19
|
-
License-File: LICENSE
|
|
20
27
|
|
|
21
28
|
# PyXtream - A Python Xtream Loader
|
|
22
29
|
|
|
@@ -74,7 +81,9 @@ python3 functional_test.py
|
|
|
74
81
|
|
|
75
82
|
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.
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
## Interesting Work by somebody else
|
|
85
|
+
|
|
86
|
+
- 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.
|
|
78
87
|
|
|
79
88
|
So far there is no ready to use Transport Stream library for playing live stream.
|
|
80
89
|
|
|
@@ -132,6 +141,8 @@ xTream.movies[{},{},...]
|
|
|
132
141
|
|
|
133
142
|
| Date | Version | Description |
|
|
134
143
|
| ----------- | -----| ----------- |
|
|
144
|
+
| 2024-09-02 | 0.7.2 | - Added missing request package to setup.py<br>- Refactored the search stream function and now, it can search for a specific stream type<br>- Refactored the download stream function<br>- Refactored the _get_request function and removed the call to the sleep function<br>- Added functional test to get series json output from a series_id<br>- Added functional test to get EPG for a specific stream ID<br>- Added xtream account expiration date printed on the console during authentication<br>- Improved results with the Flask HTML page and differentiating between movies and series<br>- Improved code readability|
|
|
145
|
+
| 2024-05-21 | 0.7.1 | - Fixed missing jsonschema package<br>- Fixed provider name in functional_test<br>- Improved print out of connection attempts<br>- Added method to read latest changes in functional_test
|
|
135
146
|
| 2023-11-08 | 0.7.0 | - Added Schema Validator<br>- Added Channel Age<br>- Added list of movies added in the last 30 and 7 days<br>- Updated code based on PyLint<br>- Fixed Flask package to be optional [richard-de-vos](https://github.com/richard-de-vos)|
|
|
136
147
|
| 2023-02-06 | 0.6.0 | - Added methods to change connection header, to turn off reload timer, and to enable/disable Flask debug mode<br>- Added a loop when attempting to connect to the provider <br>- Cleaned up some print lines|
|
|
137
148
|
| 2021-08-19 | 0.5.0 | - Added method to gracefully handle connection errors<br>- Added setting to not load adult content<br>- Added sorting by stream name<br>- Changed the handling of special characters in streams<br>- Changed print formatting<br>- Changed index.html webpage to HTML5 and Bootstrap 5|
|
|
@@ -143,4 +154,3 @@ xTream.movies[{},{},...]
|
|
|
143
154
|
| 2021-06-04 | 0.1.1 | - Updated README.md |
|
|
144
155
|
| 2021-06-04 | 0.1.0 | - Initial Release |
|
|
145
156
|
|
|
146
|
-
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: pyxtream
|
|
3
|
-
Version: 0.7.0
|
|
4
|
-
Summary: xtream IPTV loader
|
|
5
|
-
Home-page: https://github.com/superolmo/pyxtream
|
|
6
|
-
Author: Claudio Olmi
|
|
7
|
-
Author-email: superolmo2@gmail.com
|
|
8
|
-
License: GPL3
|
|
9
|
-
Platform: UNKNOWN
|
|
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
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
Provides-Extra: REST_API
|
|
19
|
-
License-File: LICENSE
|
|
20
|
-
|
|
21
1
|
# PyXtream - A Python Xtream Loader
|
|
22
2
|
|
|
23
3
|
PyXtream loads the xtream IPTV content from a provider server. Groups, Channels, Series are all organized in dictionaries. Season and Episodes are retrieved as needed. It includes functions for searching streams and downloading.
|
|
@@ -74,7 +54,9 @@ python3 functional_test.py
|
|
|
74
54
|
|
|
75
55
|
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.
|
|
76
56
|
|
|
77
|
-
|
|
57
|
+
## Interesting Work by somebody else
|
|
58
|
+
|
|
59
|
+
- 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.
|
|
78
60
|
|
|
79
61
|
So far there is no ready to use Transport Stream library for playing live stream.
|
|
80
62
|
|
|
@@ -132,6 +114,8 @@ xTream.movies[{},{},...]
|
|
|
132
114
|
|
|
133
115
|
| Date | Version | Description |
|
|
134
116
|
| ----------- | -----| ----------- |
|
|
117
|
+
| 2024-09-02 | 0.7.2 | - Added missing request package to setup.py<br>- Refactored the search stream function and now, it can search for a specific stream type<br>- Refactored the download stream function<br>- Refactored the _get_request function and removed the call to the sleep function<br>- Added functional test to get series json output from a series_id<br>- Added functional test to get EPG for a specific stream ID<br>- Added xtream account expiration date printed on the console during authentication<br>- Improved results with the Flask HTML page and differentiating between movies and series<br>- Improved code readability|
|
|
118
|
+
| 2024-05-21 | 0.7.1 | - Fixed missing jsonschema package<br>- Fixed provider name in functional_test<br>- Improved print out of connection attempts<br>- Added method to read latest changes in functional_test
|
|
135
119
|
| 2023-11-08 | 0.7.0 | - Added Schema Validator<br>- Added Channel Age<br>- Added list of movies added in the last 30 and 7 days<br>- Updated code based on PyLint<br>- Fixed Flask package to be optional [richard-de-vos](https://github.com/richard-de-vos)|
|
|
136
120
|
| 2023-02-06 | 0.6.0 | - Added methods to change connection header, to turn off reload timer, and to enable/disable Flask debug mode<br>- Added a loop when attempting to connect to the provider <br>- Cleaned up some print lines|
|
|
137
121
|
| 2021-08-19 | 0.5.0 | - Added method to gracefully handle connection errors<br>- Added setting to not load adult content<br>- Added sorting by stream name<br>- Changed the handling of special characters in streams<br>- Changed print formatting<br>- Changed index.html webpage to HTML5 and Bootstrap 5|
|
|
@@ -142,5 +126,3 @@ xTream.movies[{},{},...]
|
|
|
142
126
|
| 2021-06-05 | 0.1.2 | - Fixed Server Name |
|
|
143
127
|
| 2021-06-04 | 0.1.1 | - Updated README.md |
|
|
144
128
|
| 2021-06-04 | 0.1.0 | - Initial Release |
|
|
145
|
-
|
|
146
|
-
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "pyxtream"
|
|
3
|
+
version = "0.7.2"
|
|
4
|
+
description = "xtream IPTV loader"
|
|
5
|
+
authors = ["Claudio Olmi <superolmo2@gmail.com>"]
|
|
6
|
+
license = "GPL3"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
classifiers=[
|
|
9
|
+
"Development Status :: 4 - Beta",
|
|
10
|
+
"Environment :: Console",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
13
|
+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
"Natural Language :: English"
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[tool.poetry.dependencies]
|
|
19
|
+
python = ">=3.9"
|
|
20
|
+
flask = ">=2.2.2"
|
|
21
|
+
requests = "^2.32.3"
|
|
22
|
+
jsonschema = "^4.23.0"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
[tool.poetry.group.dev.dependencies]
|
|
26
|
+
pdoc = "^15.0.1"
|
|
27
|
+
|
|
28
|
+
[build-system]
|
|
29
|
+
requires = ["poetry-core"]
|
|
30
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<!-- Required meta tags -->
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
8
|
+
<title>PyXtream Viewer</title>
|
|
9
|
+
<!-- Add icon library -->
|
|
10
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
12
|
+
<link href="https://unpkg.com/video.js@7/dist/video-js.min.css" rel="stylesheet" />
|
|
13
|
+
<link href="https://unpkg.com/@videojs/themes@1/dist/city/index.css" rel="stylesheet" />
|
|
14
|
+
<script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
|
|
15
|
+
<style>
|
|
16
|
+
.card {
|
|
17
|
+
width: 200px;
|
|
18
|
+
margin: 10px;
|
|
19
|
+
padding: 10px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.card-img-top {
|
|
23
|
+
height: 150px;
|
|
24
|
+
width: 100%;
|
|
25
|
+
object-fit: cover;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.card-title {
|
|
29
|
+
font-size: 1rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.card-text {
|
|
33
|
+
font-size: 0.8rem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.play_movie {
|
|
37
|
+
font-size: 0.8rem;
|
|
38
|
+
padding: 5px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.open_series {
|
|
42
|
+
font-size: 0.8rem;
|
|
43
|
+
padding: 5px;
|
|
44
|
+
}
|
|
45
|
+
</style>
|
|
46
|
+
</head>
|
|
47
|
+
|
|
48
|
+
<body>
|
|
49
|
+
<nav class="navbar navbar-expand navbar-dark sticky-top bg-dark">
|
|
50
|
+
<div class="container">
|
|
51
|
+
<a class="navbar-brand" href="#">PyXtream</a>
|
|
52
|
+
<div class="dropdown">
|
|
53
|
+
<button class="btn btn-secondary dropdown-toggle" type="button" id="countryDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
54
|
+
All Countries
|
|
55
|
+
</button>
|
|
56
|
+
<ul class="dropdown-menu" aria-labelledby="countryDropdown">
|
|
57
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('All Countries')">All Countries</a></li>
|
|
58
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Arabic')">Arabic</a></li>
|
|
59
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Brazil')">Brazil</a></li>
|
|
60
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('English')">English</a></li>
|
|
61
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('French')">French</a></li>
|
|
62
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('India')">India</a></li>
|
|
63
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Italy')">Italy</a></li>
|
|
64
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Japan')">Japan</a></li>
|
|
65
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Portugal')">Portugal</a></li>
|
|
66
|
+
<li><a class="dropdown-item" href="#" onclick="updateDropDownButtonLabel('Spain')">Spain</a></li>
|
|
67
|
+
</ul>
|
|
68
|
+
</div>
|
|
69
|
+
<div class="d-flex">
|
|
70
|
+
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" id="searchString_INPUT"
|
|
71
|
+
style="width: 150px;">
|
|
72
|
+
<button class="btn btn-outline-success" type="button" id="searchString_BTN">Search</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</nav>
|
|
76
|
+
<main>
|
|
77
|
+
<div class="album py-3">
|
|
78
|
+
<div class="container" id="search_results">
|
|
79
|
+
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
<div class="modal" id="myModal" tabindex="-1">
|
|
83
|
+
<div class="modal-dialog modal-dialog-centered">
|
|
84
|
+
<div class="modal-content">
|
|
85
|
+
<div class="modal-body">
|
|
86
|
+
<video id="video_player_id" class="video-js"></video>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</main>
|
|
92
|
+
</body>
|
|
93
|
+
|
|
94
|
+
</html>
|
|
95
|
+
<script>
|
|
96
|
+
var html_card = `
|
|
97
|
+
<div class="card">
|
|
98
|
+
<div class="face front">
|
|
99
|
+
<div class="embed-responsive">
|
|
100
|
+
<img class="card-img-top" src="" alt="Stream Poster">
|
|
101
|
+
</div>
|
|
102
|
+
<div class="card-body text-center">
|
|
103
|
+
<h5 class="card-title" id="stream_title"></h5>
|
|
104
|
+
<p class="card-text"></p>
|
|
105
|
+
</div>
|
|
106
|
+
<div class="card-footer text-center">
|
|
107
|
+
<button class="btn btn-dark btn-lg btn-block text-nowrap play_movie"
|
|
108
|
+
id="play_video_btn" data-bs-toggle="tooltip" title="">
|
|
109
|
+
<i class="bi bi-play-circle"></i> Play Movie
|
|
110
|
+
</button>
|
|
111
|
+
<button class="btn btn-lg btn-block text-nowrap open_series"
|
|
112
|
+
id="open_series_btn" data-bs-toggle="tooltip" title="">
|
|
113
|
+
<i class="bi bi-play-circle"></i> Open Series
|
|
114
|
+
</button>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Changes a abbreviated name of a country or region and returns the longer
|
|
122
|
+
* version
|
|
123
|
+
* @param {string} short Abbreviated name of a country or region
|
|
124
|
+
* @returns Long name of the country or region
|
|
125
|
+
*/
|
|
126
|
+
function shortToLongLanguage(short) {
|
|
127
|
+
ret_value = "";
|
|
128
|
+
switch (short) {
|
|
129
|
+
case "AR": ret_value = "Arabic"; break;
|
|
130
|
+
case "BR": ret_value = "Brazil"; break;
|
|
131
|
+
case "EN": ret_value = "English"; break;
|
|
132
|
+
case "FR": ret_value = "French"; break;
|
|
133
|
+
case "IN": ret_value = "India"; break;
|
|
134
|
+
case "IT": ret_value = "Italian"; break;
|
|
135
|
+
case "JP": ret_value = "Japan"; break;
|
|
136
|
+
case "PT": ret_value = "Portugal"; break;
|
|
137
|
+
case "ES": ret_value = "Spain"; break;
|
|
138
|
+
default:
|
|
139
|
+
ret_value = short;
|
|
140
|
+
}
|
|
141
|
+
return ret_value;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Cleans up an HTML card
|
|
146
|
+
* TODO: Delete this
|
|
147
|
+
* @param {string} html Card in HTML format
|
|
148
|
+
* @returns String
|
|
149
|
+
*/
|
|
150
|
+
function htmlToElement(html) {
|
|
151
|
+
var template = document.createElement('template');
|
|
152
|
+
template.innerHTML = html.trim();
|
|
153
|
+
return template.content; //.firstChild;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
* @param {string} item JSON string contining the data for one stream
|
|
159
|
+
* @returns string with the formatted HTML card for the stream
|
|
160
|
+
*/
|
|
161
|
+
function buildMovieCard(item)
|
|
162
|
+
{
|
|
163
|
+
var page_country = document.getElementById("countryDropdown").value;
|
|
164
|
+
|
|
165
|
+
var card = htmlToElement(html_card);
|
|
166
|
+
var card_front = card.querySelector('.front');
|
|
167
|
+
var card_back = card.querySelector('.back');
|
|
168
|
+
var card_info = "";
|
|
169
|
+
/*** Get all the card content from item object ***/
|
|
170
|
+
switch (item.stream_type) {
|
|
171
|
+
case "movie":
|
|
172
|
+
case "live":
|
|
173
|
+
case "created_live":
|
|
174
|
+
var stream_id = item.stream_id;
|
|
175
|
+
var stream_icon = item.stream_icon;
|
|
176
|
+
var is_adult = (item.is_adult == "1");
|
|
177
|
+
var stream_extension = item.container_extension;
|
|
178
|
+
var stream_url = item.url;
|
|
179
|
+
var stream_type = item.stream_type;
|
|
180
|
+
break;
|
|
181
|
+
case undefined:
|
|
182
|
+
// If stream_id is undefined, it is not a Movie, it is a Series
|
|
183
|
+
var stream_id = item.series_id;
|
|
184
|
+
var stream_icon = item.cover;
|
|
185
|
+
var stream_type = "series";
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
// Not sure if we ever go into here
|
|
189
|
+
console.log("Unknown");
|
|
190
|
+
console.log(item);
|
|
191
|
+
var stream_type = "";
|
|
192
|
+
}
|
|
193
|
+
var stream_name = item.name.split("|");
|
|
194
|
+
if (stream_name.length > 1) {
|
|
195
|
+
var stream_title = stream_name[1].trim();
|
|
196
|
+
var stream_country = shortToLongLanguage(stream_name[0].trim());
|
|
197
|
+
} else {
|
|
198
|
+
var stream_title = stream_name[0].trim();
|
|
199
|
+
var stream_country = ""
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (stream_icon == null)
|
|
203
|
+
stream_icon = "";
|
|
204
|
+
|
|
205
|
+
/* Set the card content */
|
|
206
|
+
if (stream_icon != "") {
|
|
207
|
+
card_front.querySelector('.card-img-top').setAttribute("src", stream_icon);
|
|
208
|
+
} else {
|
|
209
|
+
card_front.querySelector('.embed-responsive').innerHTML = "";
|
|
210
|
+
}
|
|
211
|
+
card_front.querySelector("#stream_title").innerHTML = stream_title;
|
|
212
|
+
|
|
213
|
+
if ((stream_type == "series") || (stream_type == undefined)) {
|
|
214
|
+
card_front.querySelector("#open_series_btn").style.visibility = 'visible';
|
|
215
|
+
card_front.querySelector("#play_video_btn").style.visibility = 'hidden';
|
|
216
|
+
} else {
|
|
217
|
+
card_front.querySelector("#play_video_btn").style.visibility = 'visible';
|
|
218
|
+
card_front.querySelector("#open_series_btn").style.visibility = 'hidden';
|
|
219
|
+
card_front.querySelector('.play_movie').setAttribute("movie_url", stream_url);
|
|
220
|
+
card_front.querySelector('.play_movie').setAttribute("movie_extension", stream_extension);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
card_info = "[" + stream_type + "]-ID:[" + stream_id + "]";
|
|
224
|
+
if (stream_country != "")
|
|
225
|
+
{
|
|
226
|
+
card_info = "[" + stream_country + "]-" + card_info;
|
|
227
|
+
}
|
|
228
|
+
card_front.querySelector('.card-text').innerHTML = card_info
|
|
229
|
+
|
|
230
|
+
if (is_adult)
|
|
231
|
+
{
|
|
232
|
+
card_front.classList.add("border-danger");
|
|
233
|
+
card_front.querySelector(".card-body").classList.add("text-danger");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (page_country == undefined)
|
|
237
|
+
return card;
|
|
238
|
+
|
|
239
|
+
if ((page_country == stream_country) || (page_country == "All Countries") || (page_country == ""))
|
|
240
|
+
return card;
|
|
241
|
+
|
|
242
|
+
return "";
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Send search string to server, get the result, and prepare output in search_result element
|
|
247
|
+
* @param {string} search_string String to find in the stream
|
|
248
|
+
*/
|
|
249
|
+
async function fetchSearchResults(search_string)
|
|
250
|
+
{
|
|
251
|
+
const response = await fetch("http://localhost:5000/stream_search/" + document.getElementById("searchString_INPUT").value);
|
|
252
|
+
const data = await response.json();
|
|
253
|
+
|
|
254
|
+
var searchResults = document.getElementById("search_results");
|
|
255
|
+
searchResults.innerHTML = "<div class='row row-cols-1 row-cols-md-2 g-4'></div>"
|
|
256
|
+
var searchResultsRow = searchResults.firstChild;
|
|
257
|
+
|
|
258
|
+
const numberOfRecords = data.length;
|
|
259
|
+
let currentRecordIndex = 0;
|
|
260
|
+
|
|
261
|
+
console.log(`Found ${numberOfRecords} streams. Showing only ${maximumRecordsToDisplay} records`);
|
|
262
|
+
|
|
263
|
+
/* For every result stream, prepare and add a card to the search result div*/
|
|
264
|
+
data.every(item => {
|
|
265
|
+
if (currentRecordIndex >= maximumRecordsToDisplay) return false;
|
|
266
|
+
|
|
267
|
+
const newCard = buildMovieCard(item);
|
|
268
|
+
if (newCard) {
|
|
269
|
+
searchResultsRow.appendChild(newCard);
|
|
270
|
+
}
|
|
271
|
+
currentRecordIndex++;
|
|
272
|
+
return true;
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
/* After adding cards, I can attached the play movie event to all the cards */
|
|
276
|
+
search_results.addEventListener('click', play_video);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Detects keycode ENTER for running search
|
|
281
|
+
* @param {event} e Element Event
|
|
282
|
+
*/
|
|
283
|
+
function logKey(event) {
|
|
284
|
+
var keycode = (event.keyCode ? event.keyCode : event.which);
|
|
285
|
+
if (keycode == '13') {
|
|
286
|
+
document.getElementById("searchString_BTN").click();
|
|
287
|
+
}
|
|
288
|
+
event.stopImmediatePropagation();
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Get the stream URL from element and pass it to video player
|
|
293
|
+
* @param {event} event Element event
|
|
294
|
+
*/
|
|
295
|
+
function play_video(event) {
|
|
296
|
+
|
|
297
|
+
if (event.target.nodeName == 'BUTTON')
|
|
298
|
+
{
|
|
299
|
+
switch (event.target.id) {
|
|
300
|
+
case "play_video_btn":
|
|
301
|
+
var movie_url = event.target.attributes.movie_url.value;
|
|
302
|
+
var movie_extension = event.target.attributes.movie_extension.value;
|
|
303
|
+
var allowed_extensions = ["mp4", "mkv"];
|
|
304
|
+
|
|
305
|
+
if (allowed_extensions.includes(movie_extension))
|
|
306
|
+
{
|
|
307
|
+
var myPlayer = videojs('video_player_id', {liveui: true, controls: true, autoplay: true});
|
|
308
|
+
myPlayer.aspectRatio('16:9');
|
|
309
|
+
myPlayer.fluid(true);
|
|
310
|
+
|
|
311
|
+
if (movie_extension == "mp4") {
|
|
312
|
+
mime_type = "video/mp4";
|
|
313
|
+
}
|
|
314
|
+
else if (movie_extension == "mkv") {
|
|
315
|
+
mime_type = "video/webm";
|
|
316
|
+
}
|
|
317
|
+
myPlayer.src({ type: mime_type, src: movie_url });
|
|
318
|
+
document.getElementById('myModal').addEventListener('hidden.bs.modal', function (event) {
|
|
319
|
+
videojs.players.video_player_id.pause()
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
var myVideoModal = new bootstrap.Modal(document.getElementById('myModal'));
|
|
323
|
+
myVideoModal.show();
|
|
324
|
+
}
|
|
325
|
+
else
|
|
326
|
+
{
|
|
327
|
+
console.log("Video type not supported `" + movie_extension + '`');
|
|
328
|
+
console.log("Video URL: `" + movie_url + "`")
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
case "open_series_btn":
|
|
332
|
+
//TODO: Add code to open the series
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
else
|
|
337
|
+
{
|
|
338
|
+
node = event.target
|
|
339
|
+
// Search for parent card
|
|
340
|
+
while(!node.classList.contains('card'))
|
|
341
|
+
{
|
|
342
|
+
node = node.parentNode;
|
|
343
|
+
}
|
|
344
|
+
// TODO: above will exit only when the card is found, not good
|
|
345
|
+
node.classList.toggle('is-flipped');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function updateDropDownButtonLabel(txt)
|
|
350
|
+
{
|
|
351
|
+
var dropdownButton = document.querySelector('#countryDropdown');
|
|
352
|
+
dropdownButton.innerHTML = txt;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/* Setup event handlers */
|
|
356
|
+
document.getElementById("searchString_INPUT").addEventListener('keypress', logKey);
|
|
357
|
+
document.getElementById("searchString_BTN").addEventListener('click', fetchSearchResults);
|
|
358
|
+
maximumRecordsToDisplay = 100;
|
|
359
|
+
</script>
|
|
@@ -19,13 +19,14 @@ import json
|
|
|
19
19
|
# used for URL validation
|
|
20
20
|
import re
|
|
21
21
|
import time
|
|
22
|
+
import sys
|
|
22
23
|
from os import makedirs
|
|
23
24
|
from os import path as osp
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
# Timing xtream json downloads
|
|
26
27
|
from timeit import default_timer as timer
|
|
27
|
-
from typing import
|
|
28
|
-
from datetime import datetime
|
|
28
|
+
from typing import Tuple, Optional
|
|
29
|
+
from datetime import datetime, timedelta
|
|
29
30
|
import requests
|
|
30
31
|
|
|
31
32
|
from pyxtream.schemaValidator import SchemaType, schemaValidator
|
|
@@ -90,6 +91,8 @@ class Channel:
|
|
|
90
91
|
if "category_id" in stream_info.keys():
|
|
91
92
|
self.group_id = int(stream_info["category_id"])
|
|
92
93
|
|
|
94
|
+
stream_extension = ""
|
|
95
|
+
|
|
93
96
|
if stream_type == "live":
|
|
94
97
|
stream_extension = "ts"
|
|
95
98
|
|
|
@@ -107,7 +110,9 @@ class Channel:
|
|
|
107
110
|
self.is_adult = int(stream_info["is_adult"])
|
|
108
111
|
|
|
109
112
|
self.added = int(stream_info["added"])
|
|
110
|
-
self.age_days_from_added = abs(
|
|
113
|
+
self.age_days_from_added = abs(
|
|
114
|
+
datetime.utcfromtimestamp(self.added) - self.date_now
|
|
115
|
+
).days
|
|
111
116
|
|
|
112
117
|
# Required by Hypnotix
|
|
113
118
|
self.url = f"{xtream.server}/{stream_type}/{xtream.authorization['username']}/" \
|
|
@@ -286,6 +291,12 @@ class XTream:
|
|
|
286
291
|
secure_server = ""
|
|
287
292
|
username = ""
|
|
288
293
|
password = ""
|
|
294
|
+
base_url = ""
|
|
295
|
+
base_url_ssl = ""
|
|
296
|
+
|
|
297
|
+
cache_path = ""
|
|
298
|
+
|
|
299
|
+
account_expiration: timedelta
|
|
289
300
|
|
|
290
301
|
live_type = "Live"
|
|
291
302
|
vod_type = "VOD"
|
|
@@ -320,6 +331,8 @@ class XTream:
|
|
|
320
331
|
# JSON dictionary from the provider
|
|
321
332
|
threshold_time_sec = -1
|
|
322
333
|
|
|
334
|
+
validate_json: bool = True
|
|
335
|
+
|
|
323
336
|
def __init__(
|
|
324
337
|
self,
|
|
325
338
|
provider_name: str,
|
|
@@ -342,8 +355,10 @@ class XTream:
|
|
|
342
355
|
provider_url (str): URL of the IPTV provider
|
|
343
356
|
headers (dict): Requests Headers
|
|
344
357
|
hide_adult_content(bool, optional): When `True` hide stream that are marked for adult
|
|
345
|
-
cache_path (str, optional): Location where to save loaded files.
|
|
346
|
-
|
|
358
|
+
cache_path (str, optional): Location where to save loaded files.
|
|
359
|
+
Defaults to empty string.
|
|
360
|
+
reload_time_sec (int, optional): Number of seconds before automatic reloading
|
|
361
|
+
(-1 to turn it OFF)
|
|
347
362
|
debug_flask (bool, optional): Enable the debug mode in Flask
|
|
348
363
|
validate_json (bool, optional): Check Xtream API provided JSON for validity
|
|
349
364
|
|
|
@@ -352,8 +367,9 @@ class XTream:
|
|
|
352
367
|
- Note 1: If it fails to authorize with provided username and password,
|
|
353
368
|
auth_data will be an empty dictionary.
|
|
354
369
|
- Note 2: The JSON validation option will take considerable amount of time and it should be
|
|
355
|
-
used only as a debug tool. The Xtream API JSON from the provider passes through a
|
|
356
|
-
that represent the best available understanding of how the Xtream API
|
|
370
|
+
used only as a debug tool. The Xtream API JSON from the provider passes through a
|
|
371
|
+
schema that represent the best available understanding of how the Xtream API
|
|
372
|
+
works.
|
|
357
373
|
"""
|
|
358
374
|
self.server = provider_url
|
|
359
375
|
self.username = provider_username
|
|
@@ -375,7 +391,7 @@ class XTream:
|
|
|
375
391
|
# If the cache_path is not a directory, clear it
|
|
376
392
|
if not osp.isdir(self.cache_path):
|
|
377
393
|
print(" - Cache Path is not a directory, using default '~/.xtream-cache/'")
|
|
378
|
-
self.cache_path
|
|
394
|
+
self.cache_path = ""
|
|
379
395
|
|
|
380
396
|
# If the cache_path is still empty, use default
|
|
381
397
|
if self.cache_path == "":
|
|
@@ -398,47 +414,51 @@ class XTream:
|
|
|
398
414
|
|
|
399
415
|
if self.state['authenticated']:
|
|
400
416
|
if USE_FLASK:
|
|
401
|
-
self.flaskapp = FlaskWrap(
|
|
417
|
+
self.flaskapp = FlaskWrap(
|
|
418
|
+
'pyxtream', self, self.html_template_folder, debug=debug_flask
|
|
419
|
+
)
|
|
402
420
|
self.flaskapp.start()
|
|
403
421
|
|
|
404
|
-
def search_stream(self, keyword: str,
|
|
422
|
+
def search_stream(self, keyword: str,
|
|
423
|
+
ignore_case: bool = True,
|
|
424
|
+
return_type: str = "LIST",
|
|
425
|
+
stream_type: list = ("series", "movies", "channels")) -> list:
|
|
405
426
|
"""Search for streams
|
|
406
427
|
|
|
407
428
|
Args:
|
|
408
429
|
keyword (str): Keyword to search for. Supports REGEX
|
|
409
430
|
ignore_case (bool, optional): True to ignore case during search. Defaults to "True".
|
|
410
431
|
return_type (str, optional): Output format, 'LIST' or 'JSON'. Defaults to "LIST".
|
|
432
|
+
stream_type (list, optional): Search within specific stream type.
|
|
411
433
|
|
|
412
434
|
Returns:
|
|
413
|
-
|
|
435
|
+
list: List with all the results, it could be empty.
|
|
414
436
|
"""
|
|
415
437
|
|
|
416
438
|
search_result = []
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if re.match(regex, stream.name) is not None:
|
|
436
|
-
search_result.append(stream.export_json())
|
|
439
|
+
regex_flags = re.IGNORECASE if ignore_case else 0
|
|
440
|
+
regex = re.compile(keyword, regex_flags)
|
|
441
|
+
|
|
442
|
+
stream_collections = {
|
|
443
|
+
"movies": self.movies,
|
|
444
|
+
"channels": self.channels,
|
|
445
|
+
"series": self.series
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
for stream_type_name in stream_type:
|
|
449
|
+
if stream_type_name in stream_collections:
|
|
450
|
+
collection = stream_collections[stream_type_name]
|
|
451
|
+
print(f"Checking {len(collection)} {stream_type_name}")
|
|
452
|
+
for stream in collection:
|
|
453
|
+
if re.match(regex, stream.name) is not None:
|
|
454
|
+
search_result.append(stream.export_json())
|
|
455
|
+
else:
|
|
456
|
+
print(f"`{stream_type_name}` not found in collection")
|
|
437
457
|
|
|
438
458
|
if return_type == "JSON":
|
|
439
|
-
if search_result is not None:
|
|
440
|
-
|
|
441
|
-
|
|
459
|
+
# if search_result is not None:
|
|
460
|
+
print(f"Found {len(search_result)} results `{keyword}`")
|
|
461
|
+
return json.dumps(search_result, ensure_ascii=False)
|
|
442
462
|
|
|
443
463
|
return search_result
|
|
444
464
|
|
|
@@ -461,9 +481,8 @@ class XTream:
|
|
|
461
481
|
|
|
462
482
|
# If the url was correctly built and file does not exists, start downloading
|
|
463
483
|
if url != "":
|
|
464
|
-
if not
|
|
465
|
-
|
|
466
|
-
return "Error"
|
|
484
|
+
if not self._download_video_impl(url,filename):
|
|
485
|
+
return "Error"
|
|
467
486
|
|
|
468
487
|
return filename
|
|
469
488
|
|
|
@@ -481,11 +500,27 @@ class XTream:
|
|
|
481
500
|
mb_size = 1024*1024
|
|
482
501
|
try:
|
|
483
502
|
print(f"Downloading from URL `{url}` and saving at `{fullpath_filename}`")
|
|
484
|
-
|
|
503
|
+
|
|
504
|
+
# Check if the file already exists
|
|
505
|
+
if osp.exists(fullpath_filename):
|
|
506
|
+
# If the file exists, resume the download from where it left off
|
|
507
|
+
file_size = osp.getsize(fullpath_filename)
|
|
508
|
+
self.connection_headers['Range'] = f'bytes={file_size}-'
|
|
509
|
+
mode = 'ab' # Append to the existing file
|
|
510
|
+
print(f"Resuming from {file_size:_} bytes")
|
|
511
|
+
else:
|
|
512
|
+
# If the file does not exist, start a new download
|
|
513
|
+
mode = 'wb' # Write a new file
|
|
514
|
+
|
|
485
515
|
# Make the request to download
|
|
486
|
-
response = requests.get(
|
|
516
|
+
response = requests.get(
|
|
517
|
+
url, timeout=(10),
|
|
518
|
+
stream=True,
|
|
519
|
+
allow_redirects=True,
|
|
520
|
+
headers=self.connection_headers
|
|
521
|
+
)
|
|
487
522
|
# If there is an answer from the remote server
|
|
488
|
-
if response.status_code
|
|
523
|
+
if response.status_code in (200, 206):
|
|
489
524
|
# Get content type Binary or Text
|
|
490
525
|
content_type = response.headers.get('content-type',None)
|
|
491
526
|
|
|
@@ -499,23 +534,25 @@ class XTream:
|
|
|
499
534
|
# Set stream blocks
|
|
500
535
|
block_bytes = int(4*mb_size) # 4 MB
|
|
501
536
|
|
|
502
|
-
print(
|
|
537
|
+
print(
|
|
538
|
+
f"Ready to download {total_content_size_mb:.1f} MB file ({total_content_size})"
|
|
539
|
+
)
|
|
503
540
|
if content_type.split('/')[0] != "text":
|
|
504
|
-
with open(fullpath_filename,
|
|
541
|
+
with open(fullpath_filename, mode) as file:
|
|
505
542
|
|
|
506
543
|
# Grab data by block_bytes
|
|
507
544
|
for data in response.iter_content(block_bytes,decode_unicode=False):
|
|
508
545
|
downloaded_bytes += block_bytes
|
|
509
546
|
progress(downloaded_bytes,total_content_size,"Downloading")
|
|
510
547
|
file.write(data)
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
548
|
+
|
|
549
|
+
ret_code = True
|
|
550
|
+
|
|
551
|
+
# Delete Range if it was added
|
|
552
|
+
try:
|
|
553
|
+
del self.connection_headers['Range']
|
|
554
|
+
except KeyError:
|
|
555
|
+
pass
|
|
519
556
|
else:
|
|
520
557
|
print(f"URL has a file with unexpected content-type {content_type}")
|
|
521
558
|
else:
|
|
@@ -583,6 +620,7 @@ class XTream:
|
|
|
583
620
|
r = None
|
|
584
621
|
# Prepare the authentication url
|
|
585
622
|
url = f"{self.server}/player_api.php?username={self.username}&password={self.password}"
|
|
623
|
+
print("Attempting connection... ", end='')
|
|
586
624
|
while i < 30:
|
|
587
625
|
try:
|
|
588
626
|
# Request authentication, wait 4 seconds maximum
|
|
@@ -590,17 +628,24 @@ class XTream:
|
|
|
590
628
|
i = 31
|
|
591
629
|
except requests.exceptions.ConnectionError:
|
|
592
630
|
time.sleep(1)
|
|
593
|
-
print(i)
|
|
631
|
+
print(f"{i} ", end='',flush=True)
|
|
594
632
|
i += 1
|
|
595
633
|
|
|
596
634
|
if r is not None:
|
|
597
635
|
# If the answer is ok, process data and change state
|
|
598
636
|
if r.ok:
|
|
637
|
+
print("Connected")
|
|
599
638
|
self.auth_data = r.json()
|
|
600
639
|
self.authorization = {
|
|
601
640
|
"username": self.auth_data["user_info"]["username"],
|
|
602
641
|
"password": self.auth_data["user_info"]["password"]
|
|
603
642
|
}
|
|
643
|
+
# Account expiration date
|
|
644
|
+
self.account_expiration = timedelta(
|
|
645
|
+
seconds=(
|
|
646
|
+
int(self.auth_data["user_info"]["exp_date"])-datetime.now().timestamp()
|
|
647
|
+
)
|
|
648
|
+
)
|
|
604
649
|
# Mark connection authorized
|
|
605
650
|
self.state["authenticated"] = True
|
|
606
651
|
# Construct the base url for all requests
|
|
@@ -609,10 +654,11 @@ class XTream:
|
|
|
609
654
|
if "https_port" in self.auth_data["server_info"]:
|
|
610
655
|
self.base_url_ssl = f"https://{self.auth_data['server_info']['url']}:{self.auth_data['server_info']['https_port']}" \
|
|
611
656
|
f"/player_api.php?username={self.username}&password={self.password}"
|
|
657
|
+
print(f"Account expires in {str(self.account_expiration)}")
|
|
612
658
|
else:
|
|
613
659
|
print(f"Provider `{self.name}` could not be loaded. Reason: `{r.status_code} {r.reason}`")
|
|
614
660
|
else:
|
|
615
|
-
print(f"{self.name}: Provider refused the connection")
|
|
661
|
+
print(f"\n{self.name}: Provider refused the connection")
|
|
616
662
|
|
|
617
663
|
def _load_from_file(self, filename) -> dict:
|
|
618
664
|
"""Try to load the dictionary from file
|
|
@@ -661,21 +707,16 @@ class XTream:
|
|
|
661
707
|
Returns:
|
|
662
708
|
bool: True if successfull, False if error
|
|
663
709
|
"""
|
|
664
|
-
if data_list is
|
|
665
|
-
|
|
666
|
-
#Build the full path
|
|
667
|
-
full_filename = osp.join(self.cache_path, f"{self._slugify(self.name)}-{filename}")
|
|
668
|
-
# If the path makes sense, save the file
|
|
669
|
-
json_data = json.dumps(data_list, ensure_ascii=False)
|
|
670
|
-
try:
|
|
671
|
-
with open(full_filename, mode="wt", encoding="utf-8") as myfile:
|
|
672
|
-
myfile.write(json_data)
|
|
673
|
-
except Exception as e:
|
|
674
|
-
print(f" - Could not save to file `{full_filename}`: e=`{e}`")
|
|
675
|
-
return False
|
|
710
|
+
if data_list is None:
|
|
711
|
+
return False
|
|
676
712
|
|
|
713
|
+
full_filename = osp.join(self.cache_path, f"{self._slugify(self.name)}-{filename}")
|
|
714
|
+
try:
|
|
715
|
+
with open(full_filename, mode="wt", encoding="utf-8") as file:
|
|
716
|
+
json.dump(data_list, file, ensure_ascii=False)
|
|
677
717
|
return True
|
|
678
|
-
|
|
718
|
+
except Exception as e:
|
|
719
|
+
print(f" - Could not save to file `{full_filename}`: e=`{e}`")
|
|
679
720
|
return False
|
|
680
721
|
|
|
681
722
|
def load_iptv(self) -> bool:
|
|
@@ -702,6 +743,15 @@ class XTream:
|
|
|
702
743
|
print("Warning, data has already been loaded.")
|
|
703
744
|
return True
|
|
704
745
|
|
|
746
|
+
# Delete skipped channels from cache
|
|
747
|
+
full_filename = osp.join(self.cache_path, "skipped_streams.json")
|
|
748
|
+
try:
|
|
749
|
+
f = open(full_filename, mode="r+", encoding="utf-8")
|
|
750
|
+
f.truncate(0)
|
|
751
|
+
f.close()
|
|
752
|
+
except FileNotFoundError:
|
|
753
|
+
pass
|
|
754
|
+
|
|
705
755
|
for loading_stream_type in (self.live_type, self.vod_type, self.series_type):
|
|
706
756
|
## Get GROUPS
|
|
707
757
|
|
|
@@ -761,10 +811,7 @@ class XTream:
|
|
|
761
811
|
|
|
762
812
|
# If we got the STREAMS data, show the statistics and load Streams
|
|
763
813
|
if all_streams is not None:
|
|
764
|
-
print(
|
|
765
|
-
f"{self.name}: Loaded {len(all_streams)} {loading_stream_type} Streams " \
|
|
766
|
-
f"in {dt:.3f} seconds"
|
|
767
|
-
)
|
|
814
|
+
print(f"{self.name}: Loaded {len(all_streams)} {loading_stream_type} Streams in {dt:.3f} seconds")
|
|
768
815
|
## Add Streams to dictionaries
|
|
769
816
|
|
|
770
817
|
skipped_adult_content = 0
|
|
@@ -819,7 +866,7 @@ class XTream:
|
|
|
819
866
|
if not skip_stream:
|
|
820
867
|
# Some channels have no group,
|
|
821
868
|
# so let's add them to the catch all group
|
|
822
|
-
if stream_channel["category_id"]
|
|
869
|
+
if stream_channel["category_id"] == "":
|
|
823
870
|
stream_channel["category_id"] = "9999"
|
|
824
871
|
elif stream_channel["category_id"] != "1":
|
|
825
872
|
pass
|
|
@@ -890,7 +937,8 @@ class XTream:
|
|
|
890
937
|
if self.hide_adult_content:
|
|
891
938
|
print(f" - Skipped {skipped_adult_content} adult {loading_stream_type} streams")
|
|
892
939
|
if skipped_no_name_content > 0:
|
|
893
|
-
print(f" - Skipped {skipped_no_name_content}
|
|
940
|
+
print(f" - Skipped {skipped_no_name_content} "
|
|
941
|
+
"unprintable {loading_stream_type} streams")
|
|
894
942
|
else:
|
|
895
943
|
print(f" - Could not load {loading_stream_type} Streams")
|
|
896
944
|
|
|
@@ -906,6 +954,7 @@ class XTream:
|
|
|
906
954
|
try:
|
|
907
955
|
with open(full_filename, mode="a", encoding="utf-8") as myfile:
|
|
908
956
|
myfile.writelines(json_data)
|
|
957
|
+
myfile.write('\n')
|
|
909
958
|
return True
|
|
910
959
|
except Exception as e:
|
|
911
960
|
print(f" - Could not save to skipped stream file `{full_filename}`: e=`{e}`")
|
|
@@ -921,7 +970,9 @@ class XTream:
|
|
|
921
970
|
series_seasons = self._load_series_info_by_id_from_provider(get_series.series_id)
|
|
922
971
|
|
|
923
972
|
if series_seasons["seasons"] is None:
|
|
924
|
-
series_seasons["seasons"] = [
|
|
973
|
+
series_seasons["seasons"] = [
|
|
974
|
+
{"name": "Season 1", "cover": series_seasons["info"]["cover"]}
|
|
975
|
+
]
|
|
925
976
|
|
|
926
977
|
for series_info in series_seasons["seasons"]:
|
|
927
978
|
season_name = series_info["name"]
|
|
@@ -936,39 +987,77 @@ class XTream:
|
|
|
936
987
|
)
|
|
937
988
|
season.episodes[episode_info["title"]] = new_episode_channel
|
|
938
989
|
|
|
939
|
-
def
|
|
990
|
+
def _handle_request_exception(self, exception: requests.exceptions.RequestException):
|
|
991
|
+
"""Handle different types of request exceptions."""
|
|
992
|
+
if isinstance(exception, requests.exceptions.ConnectionError):
|
|
993
|
+
print(" - Connection Error: Possible network problem \
|
|
994
|
+
(e.g. DNS failure, refused connection, etc)")
|
|
995
|
+
elif isinstance(exception, requests.exceptions.HTTPError):
|
|
996
|
+
print(" - HTTP Error")
|
|
997
|
+
elif isinstance(exception, requests.exceptions.TooManyRedirects):
|
|
998
|
+
print(" - TooManyRedirects")
|
|
999
|
+
elif isinstance(exception, requests.exceptions.ReadTimeout):
|
|
1000
|
+
print(" - Timeout while loading data")
|
|
1001
|
+
else:
|
|
1002
|
+
print(f" - An unexpected error occurred: {exception}")
|
|
1003
|
+
|
|
1004
|
+
def _get_request(self, url: str, timeout: Tuple[int, int] = (2, 15)) -> Optional[dict]:
|
|
940
1005
|
"""Generic GET Request with Error handling
|
|
941
1006
|
|
|
942
1007
|
Args:
|
|
943
1008
|
URL (str): The URL where to GET content
|
|
944
|
-
timeout (Tuple, optional): Connection and Downloading Timeout.
|
|
1009
|
+
timeout (Tuple[int, int], optional): Connection and Downloading Timeout.
|
|
1010
|
+
Defaults to (2,15).
|
|
945
1011
|
|
|
946
1012
|
Returns:
|
|
947
|
-
[
|
|
1013
|
+
Optional[dict]: JSON dictionary of the loaded data, or None
|
|
948
1014
|
"""
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1015
|
+
|
|
1016
|
+
kb_size = 1024
|
|
1017
|
+
all_data = []
|
|
1018
|
+
down_stats = {"bytes": 0, "kbytes": 0, "mbytes": 0, "start": 0.0, "delta_sec": 0.0}
|
|
1019
|
+
|
|
1020
|
+
for attempt in range(10):
|
|
952
1021
|
try:
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
except requests.exceptions.
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1022
|
+
response = requests.get(
|
|
1023
|
+
url,
|
|
1024
|
+
stream=True,
|
|
1025
|
+
timeout=timeout,
|
|
1026
|
+
headers=self.connection_headers
|
|
1027
|
+
)
|
|
1028
|
+
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
|
|
1029
|
+
break
|
|
1030
|
+
except requests.exceptions.RequestException as e:
|
|
1031
|
+
self._handle_request_exception(e)
|
|
1032
|
+
return None
|
|
1033
|
+
|
|
1034
|
+
# If there is an answer from the remote server
|
|
1035
|
+
if response.status_code in (200, 206):
|
|
1036
|
+
down_stats["start"] = time.perf_counter()
|
|
1037
|
+
|
|
1038
|
+
# Set downloaded size
|
|
1039
|
+
down_stats["bytes"] = 0
|
|
1040
|
+
|
|
1041
|
+
# Set stream blocks
|
|
1042
|
+
block_bytes = int(1*kb_size*kb_size) # 4 MB
|
|
1043
|
+
|
|
1044
|
+
# Grab data by block_bytes
|
|
1045
|
+
for data in response.iter_content(block_bytes, decode_unicode=False):
|
|
1046
|
+
down_stats["bytes"] += len(data)
|
|
1047
|
+
down_stats["kbytes"] = down_stats["bytes"]/kb_size
|
|
1048
|
+
down_stats["mbytes"] = down_stats["bytes"]/kb_size/kb_size
|
|
1049
|
+
down_stats["delta_sec"] = time.perf_counter() - down_stats["start"]
|
|
1050
|
+
download_speed_average = down_stats["kbytes"]//down_stats["delta_sec"]
|
|
1051
|
+
sys.stdout.write(
|
|
1052
|
+
f'\rDownloading {down_stats["kbytes"]:.1f} MB at {download_speed_average:.0f} kB/s'
|
|
1053
|
+
)
|
|
1054
|
+
sys.stdout.flush()
|
|
1055
|
+
all_data.append(data)
|
|
1056
|
+
print(" - Done")
|
|
1057
|
+
full_content = b''.join(all_data)
|
|
1058
|
+
return json.loads(full_content)
|
|
1059
|
+
|
|
1060
|
+
print(f"HTTP error {response.status_code} while retrieving from {url}")
|
|
972
1061
|
|
|
973
1062
|
return None
|
|
974
1063
|
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
# Import Flask to control IPTV via REST API
|
|
3
3
|
from threading import Thread
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
from flask import request as FlaskRequest
|
|
9
|
-
except ImportError:
|
|
10
|
-
pass
|
|
5
|
+
from flask import Flask
|
|
6
|
+
from flask import Response as FlaskResponse
|
|
7
|
+
from flask import request as FlaskRequest
|
|
11
8
|
import logging
|
|
12
9
|
from os import path
|
|
13
10
|
|
pyxtream-0.7.0/README.md
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# PyXtream - A Python Xtream Loader
|
|
2
|
-
|
|
3
|
-
PyXtream loads the xtream IPTV content from a provider server. Groups, Channels, Series are all organized in dictionaries. Season and Episodes are retrieved as needed. It includes functions for searching streams and downloading.
|
|
4
|
-
|
|
5
|
-
This library was originally designed to work with Hypnotix at https://github.com/linuxmint/hypnotix
|
|
6
|
-
|
|
7
|
-
# Installing
|
|
8
|
-
|
|
9
|
-
Installing pyxtream is done using pip3.
|
|
10
|
-
|
|
11
|
-
```shell
|
|
12
|
-
pip3 install pyxtream
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Optionally, to use the REST Api service, install also Flask via the following command or manually.
|
|
16
|
-
|
|
17
|
-
```shell
|
|
18
|
-
pip3 install pyxtream[REST_API]
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# Quick Start
|
|
23
|
-
|
|
24
|
-
## Your own application
|
|
25
|
-
|
|
26
|
-
Integrating in your application is simple. Initialization and loading of IPTV channels and groups is done with the following code.
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
from pyxtream import XTream
|
|
30
|
-
xt = XTream(servername, username, password, url)
|
|
31
|
-
if xt.authData != {}:
|
|
32
|
-
xt.load_iptv()
|
|
33
|
-
else:
|
|
34
|
-
print("Could not connect")
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
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.
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
xt.get_series_info_by_id(series_obj)
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
At this point, the series_obj will have both Seasons and Episodes populated.
|
|
44
|
-
|
|
45
|
-
If you have installed Flask, the REST Api will be turned ON automatically. At this point, there is no method to turn it off. Maybe in a future version.
|
|
46
|
-
|
|
47
|
-
## Functional Test
|
|
48
|
-
|
|
49
|
-
Please modify the functional_test.py file with your provider information, then start the application.
|
|
50
|
-
|
|
51
|
-
```shell
|
|
52
|
-
python3 functional_test.py
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
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.
|
|
56
|
-
|
|
57
|
-
### Interesting Work by somebody else
|
|
58
|
-
|
|
59
|
-
So far there is no ready to use Transport Stream library for playing live stream.
|
|
60
|
-
|
|
61
|
-
- This is the library to convert TS to MP4
|
|
62
|
-
- https://github.com/videojs/mux.js/
|
|
63
|
-
|
|
64
|
-
- More on above, but same problem. XMLHttpRequest waits until the whole TS file is completely loaded. It does not work for live video streams
|
|
65
|
-
- https://developpaper.com/play-ts-video-directly-on-the-web/
|
|
66
|
-
|
|
67
|
-
- This below will allow me to process chunks of data
|
|
68
|
-
- https://stackoverflow.com/questions/37402716/handle-xmlhttprequest-response-with-large-data
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# API
|
|
72
|
-
|
|
73
|
-
## Classes:
|
|
74
|
-
|
|
75
|
-
Below are the classes used in the module. They are heavily influenced by the application Hypnotix.
|
|
76
|
-
|
|
77
|
-
- XTream.Channels
|
|
78
|
-
- XTream.Groups
|
|
79
|
-
- XTream.Episode
|
|
80
|
-
- XTream.Series
|
|
81
|
-
- XTream.Season
|
|
82
|
-
|
|
83
|
-
## Dictionaries (Array of dictionaries):
|
|
84
|
-
|
|
85
|
-
xTream.groups[{},{},...]
|
|
86
|
-
|
|
87
|
-
xTream.channels[{},{},...]
|
|
88
|
-
|
|
89
|
-
xTream.series[{},{},...]
|
|
90
|
-
|
|
91
|
-
xTream.movies[{},{},...]
|
|
92
|
-
|
|
93
|
-
## Functions:
|
|
94
|
-
|
|
95
|
-
- xTream.authenticate()
|
|
96
|
-
- xTream.load_iptv()
|
|
97
|
-
- XTream.get_series_info_by_id(get_series: dict)
|
|
98
|
-
- xTream.search_stream(keyword: str, ignore_case: bool = True, return_type: str = "LIST")
|
|
99
|
-
- xTream.download_video(stream_id: int)
|
|
100
|
-
- xTream.vodInfoByID(vod_id)
|
|
101
|
-
- xTream.liveEpgByStream(stream_id)
|
|
102
|
-
- xTream.liveEpgByStreamAndLimit(stream_id, limit)
|
|
103
|
-
- xTream.allLiveEpgByStream(stream_id)
|
|
104
|
-
- xTream.allEpg()
|
|
105
|
-
|
|
106
|
-
# Versioning
|
|
107
|
-
- Increment the MAJOR version when you make incompatible API changes.
|
|
108
|
-
- Increment the MINOR version when you add functionality in a backwards-compatible manner.
|
|
109
|
-
- Increment the PATCH version when you make backwards-compatible bug fixes.
|
|
110
|
-
|
|
111
|
-
# Change Log
|
|
112
|
-
|
|
113
|
-
| Date | Version | Description |
|
|
114
|
-
| ----------- | -----| ----------- |
|
|
115
|
-
| 2023-11-08 | 0.7.0 | - Added Schema Validator<br>- Added Channel Age<br>- Added list of movies added in the last 30 and 7 days<br>- Updated code based on PyLint<br>- Fixed Flask package to be optional [richard-de-vos](https://github.com/richard-de-vos)|
|
|
116
|
-
| 2023-02-06 | 0.6.0 | - Added methods to change connection header, to turn off reload timer, and to enable/disable Flask debug mode<br>- Added a loop when attempting to connect to the provider <br>- Cleaned up some print lines|
|
|
117
|
-
| 2021-08-19 | 0.5.0 | - Added method to gracefully handle connection errors<br>- Added setting to not load adult content<br>- Added sorting by stream name<br>- Changed the handling of special characters in streams<br>- Changed print formatting<br>- Changed index.html webpage to HTML5 and Bootstrap 5|
|
|
118
|
-
| 2021-06-19 | 0.4.0 | - Updated to follow PEP8<br>- Updated Docstrings |
|
|
119
|
-
| 2021-06-19 | 0.3.0 | - Added enhanced Home Page with Search Button and Player<br>- Added case insensitive search<br>- Improved handling of provider missing fields |
|
|
120
|
-
| 2021-06-11 | 0.2.1 | - Fixed bug in the way it reload from cache |
|
|
121
|
-
| 2021-06-08 | 0.2.0 | - Added searching<br>- Added video download<br>- Added REST Api<br>- Fixed cache-path issue |
|
|
122
|
-
| 2021-06-05 | 0.1.2 | - Fixed Server Name |
|
|
123
|
-
| 2021-06-04 | 0.1.1 | - Updated README.md |
|
|
124
|
-
| 2021-06-04 | 0.1.0 | - Initial Release |
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
setup.py
|
|
4
|
-
pyxtream/__init__.py
|
|
5
|
-
pyxtream/progress.py
|
|
6
|
-
pyxtream/pyxtream.py
|
|
7
|
-
pyxtream/rest_api.py
|
|
8
|
-
pyxtream/schemaValidator.py
|
|
9
|
-
pyxtream/version.py
|
|
10
|
-
pyxtream.egg-info/PKG-INFO
|
|
11
|
-
pyxtream.egg-info/SOURCES.txt
|
|
12
|
-
pyxtream.egg-info/dependency_links.txt
|
|
13
|
-
pyxtream.egg-info/requires.txt
|
|
14
|
-
pyxtream.egg-info/top_level.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pyxtream
|
pyxtream-0.7.0/setup.cfg
DELETED
pyxtream-0.7.0/setup.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
from setuptools import setup, find_packages
|
|
3
|
-
from distutils.util import convert_path
|
|
4
|
-
|
|
5
|
-
with open("README.md", "r") as fh:
|
|
6
|
-
long_description = fh.read()
|
|
7
|
-
|
|
8
|
-
main_ns = {}
|
|
9
|
-
ver_path = convert_path('pyxtream/version.py')
|
|
10
|
-
with open(ver_path) as ver_file:
|
|
11
|
-
exec(ver_file.read(), main_ns)
|
|
12
|
-
|
|
13
|
-
setup(
|
|
14
|
-
name='pyxtream',
|
|
15
|
-
version=main_ns['__version__'],
|
|
16
|
-
author=main_ns['__author__'],
|
|
17
|
-
author_email=main_ns['__author_email__'],
|
|
18
|
-
description="xtream IPTV loader",
|
|
19
|
-
long_description=long_description,
|
|
20
|
-
long_description_content_type="text/markdown",
|
|
21
|
-
url="https://github.com/superolmo/pyxtream",
|
|
22
|
-
packages=find_packages(),
|
|
23
|
-
license="GPL3",
|
|
24
|
-
classifiers=[
|
|
25
|
-
"Development Status :: 4 - Beta",
|
|
26
|
-
"Environment :: Console",
|
|
27
|
-
"Intended Audience :: Developers",
|
|
28
|
-
"Programming Language :: Python :: 3 :: Only",
|
|
29
|
-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
|
30
|
-
"Operating System :: OS Independent",
|
|
31
|
-
"Natural Language :: English"
|
|
32
|
-
],
|
|
33
|
-
extras_require={
|
|
34
|
-
"REST_API": ["Flask>=1.1.2",],
|
|
35
|
-
}
|
|
36
|
-
)
|
|
37
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|