StreamingCommunity 1.7.6__py3-none-any.whl → 1.8.0__py3-none-any.whl
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.
Potentially problematic release.
This version of StreamingCommunity might be problematic. Click here for more details.
- StreamingCommunity/Src/Api/Player/Helper/Vixcloud/js_parser.py +4 -1
- StreamingCommunity/Src/Api/Player/Helper/Vixcloud/util.py +166 -166
- StreamingCommunity/Src/Api/Player/ddl.py +89 -89
- StreamingCommunity/Src/Api/Player/maxstream.py +151 -151
- StreamingCommunity/Src/Api/Player/supervideo.py +193 -193
- StreamingCommunity/Src/Api/Player/vixcloud.py +224 -212
- StreamingCommunity/Src/Api/Site/1337xx/__init__.py +50 -50
- StreamingCommunity/Src/Api/Site/1337xx/costant.py +14 -14
- StreamingCommunity/Src/Api/Site/1337xx/site.py +83 -83
- StreamingCommunity/Src/Api/Site/1337xx/title.py +66 -66
- StreamingCommunity/Src/Api/Site/altadefinizione/__init__.py +50 -50
- StreamingCommunity/Src/Api/Site/altadefinizione/costant.py +14 -14
- StreamingCommunity/Src/Api/Site/altadefinizione/film.py +69 -69
- StreamingCommunity/Src/Api/Site/altadefinizione/site.py +86 -86
- StreamingCommunity/Src/Api/Site/animeunity/__init__.py +50 -50
- StreamingCommunity/Src/Api/Site/animeunity/costant.py +15 -15
- StreamingCommunity/Src/Api/Site/animeunity/film_serie.py +131 -131
- StreamingCommunity/Src/Api/Site/animeunity/site.py +164 -164
- StreamingCommunity/Src/Api/Site/bitsearch/__init__.py +51 -51
- StreamingCommunity/Src/Api/Site/bitsearch/costant.py +15 -15
- StreamingCommunity/Src/Api/Site/bitsearch/site.py +84 -84
- StreamingCommunity/Src/Api/Site/bitsearch/title.py +47 -47
- StreamingCommunity/Src/Api/Site/cb01new/__init__.py +51 -51
- StreamingCommunity/Src/Api/Site/cb01new/costant.py +15 -15
- StreamingCommunity/Src/Api/Site/cb01new/film.py +69 -69
- StreamingCommunity/Src/Api/Site/cb01new/site.py +74 -74
- StreamingCommunity/Src/Api/Site/ddlstreamitaly/__init__.py +57 -57
- StreamingCommunity/Src/Api/Site/ddlstreamitaly/costant.py +16 -16
- StreamingCommunity/Src/Api/Site/ddlstreamitaly/series.py +142 -142
- StreamingCommunity/Src/Api/Site/ddlstreamitaly/site.py +92 -92
- StreamingCommunity/Src/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +82 -82
- StreamingCommunity/Src/Api/Site/guardaserie/__init__.py +52 -52
- StreamingCommunity/Src/Api/Site/guardaserie/costant.py +15 -15
- StreamingCommunity/Src/Api/Site/guardaserie/series.py +195 -195
- StreamingCommunity/Src/Api/Site/guardaserie/site.py +84 -84
- StreamingCommunity/Src/Api/Site/guardaserie/util/ScrapeSerie.py +110 -110
- StreamingCommunity/Src/Api/Site/mostraguarda/__init__.py +48 -48
- StreamingCommunity/Src/Api/Site/mostraguarda/costant.py +14 -14
- StreamingCommunity/Src/Api/Site/mostraguarda/film.py +94 -94
- StreamingCommunity/Src/Api/Site/piratebays/__init__.py +50 -50
- StreamingCommunity/Src/Api/Site/piratebays/costant.py +14 -14
- StreamingCommunity/Src/Api/Site/piratebays/site.py +88 -88
- StreamingCommunity/Src/Api/Site/piratebays/title.py +45 -45
- StreamingCommunity/Src/Api/Site/streamingcommunity/__init__.py +55 -55
- StreamingCommunity/Src/Api/Site/streamingcommunity/costant.py +14 -14
- StreamingCommunity/Src/Api/Site/streamingcommunity/film.py +70 -70
- StreamingCommunity/Src/Api/Site/streamingcommunity/series.py +203 -203
- StreamingCommunity/Src/Api/Site/streamingcommunity/site.py +125 -125
- StreamingCommunity/Src/Api/Template/Class/SearchType.py +101 -101
- StreamingCommunity/Src/Api/Template/Util/__init__.py +4 -4
- StreamingCommunity/Src/Api/Template/Util/get_domain.py +137 -137
- StreamingCommunity/Src/Api/Template/Util/manage_ep.py +153 -153
- StreamingCommunity/Src/Api/Template/Util/recall_search.py +37 -37
- StreamingCommunity/Src/Api/Template/__init__.py +2 -2
- StreamingCommunity/Src/Api/Template/site.py +87 -87
- StreamingCommunity/Src/Lib/Downloader/HLS/downloader.py +968 -968
- StreamingCommunity/Src/Lib/Downloader/HLS/proxyes.py +110 -110
- StreamingCommunity/Src/Lib/Downloader/HLS/segments.py +540 -540
- StreamingCommunity/Src/Lib/Downloader/MP4/downloader.py +156 -156
- StreamingCommunity/Src/Lib/Downloader/TOR/downloader.py +222 -222
- StreamingCommunity/Src/Lib/Downloader/__init__.py +4 -4
- StreamingCommunity/Src/Lib/Driver/driver_1.py +76 -76
- StreamingCommunity/Src/Lib/FFmpeg/__init__.py +4 -4
- StreamingCommunity/Src/Lib/FFmpeg/capture.py +170 -170
- StreamingCommunity/Src/Lib/FFmpeg/command.py +292 -292
- StreamingCommunity/Src/Lib/FFmpeg/util.py +241 -241
- StreamingCommunity/Src/Lib/M3U8/__init__.py +5 -5
- StreamingCommunity/Src/Lib/M3U8/decryptor.py +128 -128
- StreamingCommunity/Src/Lib/M3U8/estimator.py +172 -172
- StreamingCommunity/Src/Lib/M3U8/parser.py +666 -666
- StreamingCommunity/Src/Lib/M3U8/url_fixer.py +51 -51
- StreamingCommunity/Src/Lib/TMBD/__init__.py +1 -1
- StreamingCommunity/Src/Lib/TMBD/obj_tmbd.py +39 -39
- StreamingCommunity/Src/Lib/TMBD/tmdb.py +345 -345
- StreamingCommunity/Src/Upload/update.py +64 -64
- StreamingCommunity/Src/Upload/version.py +5 -5
- StreamingCommunity/Src/Util/_jsonConfig.py +204 -204
- StreamingCommunity/Src/Util/call_stack.py +42 -42
- StreamingCommunity/Src/Util/color.py +20 -20
- StreamingCommunity/Src/Util/console.py +12 -12
- StreamingCommunity/Src/Util/headers.py +147 -147
- StreamingCommunity/Src/Util/logger.py +53 -53
- StreamingCommunity/Src/Util/message.py +46 -46
- StreamingCommunity/Src/Util/os.py +417 -417
- StreamingCommunity/Src/Util/table.py +163 -163
- StreamingCommunity/run.py +196 -196
- {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/METADATA +1 -1
- StreamingCommunity-1.8.0.dist-info/RECORD +97 -0
- StreamingCommunity-1.7.6.dist-info/RECORD +0 -97
- {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/LICENSE +0 -0
- {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/WHEEL +0 -0
- {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/entry_points.txt +0 -0
- {StreamingCommunity-1.7.6.dist-info → StreamingCommunity-1.8.0.dist-info}/top_level.txt +0 -0
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# 01.03.2023
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import time
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# Internal utilities
|
|
8
|
-
from .version import __version__, __author__, __title__
|
|
9
|
-
from StreamingCommunity.Src.Util.console import console
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# External library
|
|
13
|
-
import httpx
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# Variable
|
|
17
|
-
main = os.path.abspath(os.path.dirname(__file__))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def update():
|
|
21
|
-
"""
|
|
22
|
-
Check for updates on GitHub and display relevant information.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
console.print("[green]Checking GitHub version [white]...")
|
|
26
|
-
|
|
27
|
-
# Make the GitHub API requests and handle potential errors
|
|
28
|
-
try:
|
|
29
|
-
response_reposity = httpx.get(f"https://api.github.com/repos/{__author__}/{__title__}").json()
|
|
30
|
-
response_releases = httpx.get(f"https://api.github.com/repos/{__author__}/{__title__}/releases").json()
|
|
31
|
-
|
|
32
|
-
except Exception as e:
|
|
33
|
-
console.print(f"[red]Error accessing GitHub API: {e}")
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
# Get stargazers count from the repository
|
|
37
|
-
stargazers_count = response_reposity.get('stargazers_count', 0)
|
|
38
|
-
|
|
39
|
-
# Calculate total download count from all releases
|
|
40
|
-
total_download_count = sum(asset['download_count'] for release in response_releases for asset in release.get('assets', []))
|
|
41
|
-
|
|
42
|
-
# Get latest version name
|
|
43
|
-
if response_releases:
|
|
44
|
-
last_version = response_releases[0].get('name', 'Unknown')
|
|
45
|
-
else:
|
|
46
|
-
last_version = 'Unknown'
|
|
47
|
-
|
|
48
|
-
# Calculate percentual of stars based on download count
|
|
49
|
-
if total_download_count > 0 and stargazers_count > 0:
|
|
50
|
-
percentual_stars = round(stargazers_count / total_download_count * 100, 2)
|
|
51
|
-
else:
|
|
52
|
-
percentual_stars = 0
|
|
53
|
-
|
|
54
|
-
# Check installed version
|
|
55
|
-
if __version__ != last_version:
|
|
56
|
-
console.print(f"[red]New version available: [yellow]{last_version}")
|
|
57
|
-
else:
|
|
58
|
-
console.print(f"[red]Everything is up to date")
|
|
59
|
-
|
|
60
|
-
console.print("\n")
|
|
61
|
-
console.print(f"[red]{__title__} has been downloaded [yellow]{total_download_count} [red]times, but only [yellow]{percentual_stars}% [red]of users have starred it.\n\
|
|
62
|
-
[cyan]Help the repository grow today by leaving a [yellow]star [cyan]and [yellow]sharing [cyan]it with others online!")
|
|
63
|
-
|
|
64
|
-
time.sleep(3)
|
|
1
|
+
# 01.03.2023
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Internal utilities
|
|
8
|
+
from .version import __version__, __author__, __title__
|
|
9
|
+
from StreamingCommunity.Src.Util.console import console
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# External library
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Variable
|
|
17
|
+
main = os.path.abspath(os.path.dirname(__file__))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def update():
|
|
21
|
+
"""
|
|
22
|
+
Check for updates on GitHub and display relevant information.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
console.print("[green]Checking GitHub version [white]...")
|
|
26
|
+
|
|
27
|
+
# Make the GitHub API requests and handle potential errors
|
|
28
|
+
try:
|
|
29
|
+
response_reposity = httpx.get(f"https://api.github.com/repos/{__author__}/{__title__}").json()
|
|
30
|
+
response_releases = httpx.get(f"https://api.github.com/repos/{__author__}/{__title__}/releases").json()
|
|
31
|
+
|
|
32
|
+
except Exception as e:
|
|
33
|
+
console.print(f"[red]Error accessing GitHub API: {e}")
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
# Get stargazers count from the repository
|
|
37
|
+
stargazers_count = response_reposity.get('stargazers_count', 0)
|
|
38
|
+
|
|
39
|
+
# Calculate total download count from all releases
|
|
40
|
+
total_download_count = sum(asset['download_count'] for release in response_releases for asset in release.get('assets', []))
|
|
41
|
+
|
|
42
|
+
# Get latest version name
|
|
43
|
+
if response_releases:
|
|
44
|
+
last_version = response_releases[0].get('name', 'Unknown')
|
|
45
|
+
else:
|
|
46
|
+
last_version = 'Unknown'
|
|
47
|
+
|
|
48
|
+
# Calculate percentual of stars based on download count
|
|
49
|
+
if total_download_count > 0 and stargazers_count > 0:
|
|
50
|
+
percentual_stars = round(stargazers_count / total_download_count * 100, 2)
|
|
51
|
+
else:
|
|
52
|
+
percentual_stars = 0
|
|
53
|
+
|
|
54
|
+
# Check installed version
|
|
55
|
+
if __version__ != last_version:
|
|
56
|
+
console.print(f"[red]New version available: [yellow]{last_version}")
|
|
57
|
+
else:
|
|
58
|
+
console.print(f"[red]Everything is up to date")
|
|
59
|
+
|
|
60
|
+
console.print("\n")
|
|
61
|
+
console.print(f"[red]{__title__} has been downloaded [yellow]{total_download_count} [red]times, but only [yellow]{percentual_stars}% [red]of users have starred it.\n\
|
|
62
|
+
[cyan]Help the repository grow today by leaving a [yellow]star [cyan]and [yellow]sharing [cyan]it with others online!")
|
|
63
|
+
|
|
64
|
+
time.sleep(3)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
__title__ = 'StreamingCommunity'
|
|
2
|
-
__version__ = 'v1.
|
|
3
|
-
__author__ = 'Lovi-0'
|
|
4
|
-
__description__ = 'A command-line program to download film'
|
|
5
|
-
__copyright__ = 'Copyright 2024'
|
|
1
|
+
__title__ = 'StreamingCommunity'
|
|
2
|
+
__version__ = 'v1.8.0'
|
|
3
|
+
__author__ = 'Lovi-0'
|
|
4
|
+
__description__ = 'A command-line program to download film'
|
|
5
|
+
__copyright__ = 'Copyright 2024'
|
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
# 29.01.24
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import json
|
|
5
|
-
import httpx
|
|
6
|
-
import logging
|
|
7
|
-
from typing import Any, List
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ConfigManager:
|
|
11
|
-
def __init__(self, file_path: str = 'config.json') -> None:
|
|
12
|
-
"""Initialize the ConfigManager.
|
|
13
|
-
|
|
14
|
-
Parameters:
|
|
15
|
-
- file_path (str, optional): The path to the configuration file. Default is 'config.json'.
|
|
16
|
-
"""
|
|
17
|
-
self.file_path = file_path
|
|
18
|
-
self.config = {}
|
|
19
|
-
self.cache = {}
|
|
20
|
-
|
|
21
|
-
def read_config(self) -> None:
|
|
22
|
-
"""Read the configuration file."""
|
|
23
|
-
try:
|
|
24
|
-
logging.info(f"Reading file: {self.file_path}")
|
|
25
|
-
|
|
26
|
-
# Check if file exist
|
|
27
|
-
if os.path.exists(self.file_path):
|
|
28
|
-
with open(self.file_path, 'r') as f:
|
|
29
|
-
self.config = json.load(f)
|
|
30
|
-
logging.info("Configuration file loaded successfully.")
|
|
31
|
-
|
|
32
|
-
# Download config.json
|
|
33
|
-
else:
|
|
34
|
-
logging.info("Configuration file does not exist. Downloading...")
|
|
35
|
-
url = "https://raw.githubusercontent.com/Lovi-0/StreamingCommunity/refs/heads/main/config.json"
|
|
36
|
-
|
|
37
|
-
with httpx.Client() as client:
|
|
38
|
-
response = client.get(url)
|
|
39
|
-
|
|
40
|
-
if response.status_code == 200:
|
|
41
|
-
with open(self.file_path, 'w') as f:
|
|
42
|
-
f.write(response.text)
|
|
43
|
-
|
|
44
|
-
self.config = json.loads(response.text)
|
|
45
|
-
logging.info("Configuration file downloaded and saved.")
|
|
46
|
-
|
|
47
|
-
else:
|
|
48
|
-
logging.error(f"Failed to download configuration file. Status code: {response.status_code}")
|
|
49
|
-
|
|
50
|
-
except Exception as e:
|
|
51
|
-
logging.error(f"Error reading configuration file: {e}")
|
|
52
|
-
|
|
53
|
-
def read_key(self, section: str, key: str, data_type: type = str) -> Any:
|
|
54
|
-
"""Read a key from the configuration file.
|
|
55
|
-
|
|
56
|
-
Parameters:
|
|
57
|
-
- section (str): The section in the configuration file.
|
|
58
|
-
- key (str): The key to be read.
|
|
59
|
-
- data_type (type, optional): The expected data type of the key's value. Default is str.
|
|
60
|
-
|
|
61
|
-
Returns:
|
|
62
|
-
The value of the key converted to the specified data type.
|
|
63
|
-
"""
|
|
64
|
-
cache_key = f"{section}.{key}"
|
|
65
|
-
logging.info(f"Read key: {cache_key}")
|
|
66
|
-
|
|
67
|
-
if cache_key in self.cache:
|
|
68
|
-
return self.cache[cache_key]
|
|
69
|
-
|
|
70
|
-
if section in self.config and key in self.config[section]:
|
|
71
|
-
value = self.config[section][key]
|
|
72
|
-
else:
|
|
73
|
-
raise ValueError(f"Key '{key}' not found in section '{section}'")
|
|
74
|
-
|
|
75
|
-
value = self._convert_to_data_type(value, data_type)
|
|
76
|
-
self.cache[cache_key] = value
|
|
77
|
-
|
|
78
|
-
return value
|
|
79
|
-
|
|
80
|
-
def _convert_to_data_type(self, value: str, data_type: type) -> Any:
|
|
81
|
-
"""Convert the value to the specified data type.
|
|
82
|
-
|
|
83
|
-
Parameters:
|
|
84
|
-
- value (str): The value to be converted.
|
|
85
|
-
- data_type (type): The expected data type.
|
|
86
|
-
|
|
87
|
-
Returns:
|
|
88
|
-
The value converted to the specified data type.
|
|
89
|
-
"""
|
|
90
|
-
if data_type == int:
|
|
91
|
-
return int(value)
|
|
92
|
-
elif data_type == bool:
|
|
93
|
-
return bool(value)
|
|
94
|
-
elif data_type == list:
|
|
95
|
-
return value if isinstance(value, list) else [item.strip() for item in value.split(',')]
|
|
96
|
-
elif data_type == type(None):
|
|
97
|
-
return None
|
|
98
|
-
else:
|
|
99
|
-
return value
|
|
100
|
-
|
|
101
|
-
def get(self, section: str, key: str) -> Any:
|
|
102
|
-
"""Read a value from the configuration file.
|
|
103
|
-
|
|
104
|
-
Parameters:
|
|
105
|
-
- section (str): The section in the configuration file.
|
|
106
|
-
- key (str): The key to be read.
|
|
107
|
-
|
|
108
|
-
Returns:
|
|
109
|
-
The value associated with the key.
|
|
110
|
-
"""
|
|
111
|
-
return self.read_key(section, key)
|
|
112
|
-
|
|
113
|
-
def get_int(self, section: str, key: str) -> int:
|
|
114
|
-
"""Read an integer value from the configuration file.
|
|
115
|
-
|
|
116
|
-
Parameters:
|
|
117
|
-
- section (str): The section in the configuration file.
|
|
118
|
-
- key (str): The key to be read.
|
|
119
|
-
|
|
120
|
-
Returns:
|
|
121
|
-
int: The integer value.
|
|
122
|
-
"""
|
|
123
|
-
return self.read_key(section, key, int)
|
|
124
|
-
|
|
125
|
-
def get_float(self, section: str, key: str) -> int:
|
|
126
|
-
"""Read an float value from the configuration file.
|
|
127
|
-
|
|
128
|
-
Parameters:
|
|
129
|
-
- section (str): The section in the configuration file.
|
|
130
|
-
- key (str): The key to be read.
|
|
131
|
-
|
|
132
|
-
Returns:
|
|
133
|
-
float: The float value.
|
|
134
|
-
"""
|
|
135
|
-
return self.read_key(section, key, float)
|
|
136
|
-
|
|
137
|
-
def get_bool(self, section: str, key: str) -> bool:
|
|
138
|
-
"""Read a boolean value from the configuration file.
|
|
139
|
-
|
|
140
|
-
Parameters:
|
|
141
|
-
- section (str): The section in the configuration file.
|
|
142
|
-
- key (str): The key to be read.
|
|
143
|
-
|
|
144
|
-
Returns:
|
|
145
|
-
bool: The boolean value.
|
|
146
|
-
"""
|
|
147
|
-
return self.read_key(section, key, bool)
|
|
148
|
-
|
|
149
|
-
def get_list(self, section: str, key: str) -> List[str]:
|
|
150
|
-
"""Read a list value from the configuration file.
|
|
151
|
-
|
|
152
|
-
Parameters:
|
|
153
|
-
- section (str): The section in the configuration file.
|
|
154
|
-
- key (str): The key to be read.
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
list: The list value.
|
|
158
|
-
"""
|
|
159
|
-
return self.read_key(section, key, list)
|
|
160
|
-
|
|
161
|
-
def get_dict(self, section: str, key: str) -> dict:
|
|
162
|
-
"""Read a dictionary value from the configuration file.
|
|
163
|
-
|
|
164
|
-
Parameters:
|
|
165
|
-
- section (str): The section in the configuration file.
|
|
166
|
-
- key (str): The key to be read.
|
|
167
|
-
|
|
168
|
-
Returns:
|
|
169
|
-
dict: The dictionary value.
|
|
170
|
-
"""
|
|
171
|
-
return self.read_key(section, key, dict)
|
|
172
|
-
|
|
173
|
-
def set_key(self, section: str, key: str, value: Any) -> None:
|
|
174
|
-
"""Set a key in the configuration file.
|
|
175
|
-
|
|
176
|
-
Parameters:
|
|
177
|
-
- section (str): The section in the configuration file.
|
|
178
|
-
- key (str): The key to be set.
|
|
179
|
-
- value (Any): The value to be associated with the key.
|
|
180
|
-
"""
|
|
181
|
-
try:
|
|
182
|
-
if section not in self.config:
|
|
183
|
-
self.config[section] = {}
|
|
184
|
-
|
|
185
|
-
self.config[section][key] = value
|
|
186
|
-
cache_key = f"{section}.{key}"
|
|
187
|
-
self.cache[cache_key] = value
|
|
188
|
-
self.write_config()
|
|
189
|
-
|
|
190
|
-
except Exception as e:
|
|
191
|
-
print(f"Error setting key '{key}' in section '{section}': {e}")
|
|
192
|
-
|
|
193
|
-
def write_config(self) -> None:
|
|
194
|
-
"""Write the configuration to the file."""
|
|
195
|
-
try:
|
|
196
|
-
with open(self.file_path, 'w') as f:
|
|
197
|
-
json.dump(self.config, f, indent=4)
|
|
198
|
-
except Exception as e:
|
|
199
|
-
print(f"Error writing configuration file: {e}")
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
# Initialize
|
|
203
|
-
config_manager = ConfigManager()
|
|
204
|
-
config_manager.read_config()
|
|
1
|
+
# 29.01.24
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import json
|
|
5
|
+
import httpx
|
|
6
|
+
import logging
|
|
7
|
+
from typing import Any, List
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ConfigManager:
|
|
11
|
+
def __init__(self, file_path: str = 'config.json') -> None:
|
|
12
|
+
"""Initialize the ConfigManager.
|
|
13
|
+
|
|
14
|
+
Parameters:
|
|
15
|
+
- file_path (str, optional): The path to the configuration file. Default is 'config.json'.
|
|
16
|
+
"""
|
|
17
|
+
self.file_path = file_path
|
|
18
|
+
self.config = {}
|
|
19
|
+
self.cache = {}
|
|
20
|
+
|
|
21
|
+
def read_config(self) -> None:
|
|
22
|
+
"""Read the configuration file."""
|
|
23
|
+
try:
|
|
24
|
+
logging.info(f"Reading file: {self.file_path}")
|
|
25
|
+
|
|
26
|
+
# Check if file exist
|
|
27
|
+
if os.path.exists(self.file_path):
|
|
28
|
+
with open(self.file_path, 'r') as f:
|
|
29
|
+
self.config = json.load(f)
|
|
30
|
+
logging.info("Configuration file loaded successfully.")
|
|
31
|
+
|
|
32
|
+
# Download config.json
|
|
33
|
+
else:
|
|
34
|
+
logging.info("Configuration file does not exist. Downloading...")
|
|
35
|
+
url = "https://raw.githubusercontent.com/Lovi-0/StreamingCommunity/refs/heads/main/config.json"
|
|
36
|
+
|
|
37
|
+
with httpx.Client() as client:
|
|
38
|
+
response = client.get(url)
|
|
39
|
+
|
|
40
|
+
if response.status_code == 200:
|
|
41
|
+
with open(self.file_path, 'w') as f:
|
|
42
|
+
f.write(response.text)
|
|
43
|
+
|
|
44
|
+
self.config = json.loads(response.text)
|
|
45
|
+
logging.info("Configuration file downloaded and saved.")
|
|
46
|
+
|
|
47
|
+
else:
|
|
48
|
+
logging.error(f"Failed to download configuration file. Status code: {response.status_code}")
|
|
49
|
+
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logging.error(f"Error reading configuration file: {e}")
|
|
52
|
+
|
|
53
|
+
def read_key(self, section: str, key: str, data_type: type = str) -> Any:
|
|
54
|
+
"""Read a key from the configuration file.
|
|
55
|
+
|
|
56
|
+
Parameters:
|
|
57
|
+
- section (str): The section in the configuration file.
|
|
58
|
+
- key (str): The key to be read.
|
|
59
|
+
- data_type (type, optional): The expected data type of the key's value. Default is str.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
The value of the key converted to the specified data type.
|
|
63
|
+
"""
|
|
64
|
+
cache_key = f"{section}.{key}"
|
|
65
|
+
logging.info(f"Read key: {cache_key}")
|
|
66
|
+
|
|
67
|
+
if cache_key in self.cache:
|
|
68
|
+
return self.cache[cache_key]
|
|
69
|
+
|
|
70
|
+
if section in self.config and key in self.config[section]:
|
|
71
|
+
value = self.config[section][key]
|
|
72
|
+
else:
|
|
73
|
+
raise ValueError(f"Key '{key}' not found in section '{section}'")
|
|
74
|
+
|
|
75
|
+
value = self._convert_to_data_type(value, data_type)
|
|
76
|
+
self.cache[cache_key] = value
|
|
77
|
+
|
|
78
|
+
return value
|
|
79
|
+
|
|
80
|
+
def _convert_to_data_type(self, value: str, data_type: type) -> Any:
|
|
81
|
+
"""Convert the value to the specified data type.
|
|
82
|
+
|
|
83
|
+
Parameters:
|
|
84
|
+
- value (str): The value to be converted.
|
|
85
|
+
- data_type (type): The expected data type.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
The value converted to the specified data type.
|
|
89
|
+
"""
|
|
90
|
+
if data_type == int:
|
|
91
|
+
return int(value)
|
|
92
|
+
elif data_type == bool:
|
|
93
|
+
return bool(value)
|
|
94
|
+
elif data_type == list:
|
|
95
|
+
return value if isinstance(value, list) else [item.strip() for item in value.split(',')]
|
|
96
|
+
elif data_type == type(None):
|
|
97
|
+
return None
|
|
98
|
+
else:
|
|
99
|
+
return value
|
|
100
|
+
|
|
101
|
+
def get(self, section: str, key: str) -> Any:
|
|
102
|
+
"""Read a value from the configuration file.
|
|
103
|
+
|
|
104
|
+
Parameters:
|
|
105
|
+
- section (str): The section in the configuration file.
|
|
106
|
+
- key (str): The key to be read.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
The value associated with the key.
|
|
110
|
+
"""
|
|
111
|
+
return self.read_key(section, key)
|
|
112
|
+
|
|
113
|
+
def get_int(self, section: str, key: str) -> int:
|
|
114
|
+
"""Read an integer value from the configuration file.
|
|
115
|
+
|
|
116
|
+
Parameters:
|
|
117
|
+
- section (str): The section in the configuration file.
|
|
118
|
+
- key (str): The key to be read.
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
int: The integer value.
|
|
122
|
+
"""
|
|
123
|
+
return self.read_key(section, key, int)
|
|
124
|
+
|
|
125
|
+
def get_float(self, section: str, key: str) -> int:
|
|
126
|
+
"""Read an float value from the configuration file.
|
|
127
|
+
|
|
128
|
+
Parameters:
|
|
129
|
+
- section (str): The section in the configuration file.
|
|
130
|
+
- key (str): The key to be read.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
float: The float value.
|
|
134
|
+
"""
|
|
135
|
+
return self.read_key(section, key, float)
|
|
136
|
+
|
|
137
|
+
def get_bool(self, section: str, key: str) -> bool:
|
|
138
|
+
"""Read a boolean value from the configuration file.
|
|
139
|
+
|
|
140
|
+
Parameters:
|
|
141
|
+
- section (str): The section in the configuration file.
|
|
142
|
+
- key (str): The key to be read.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
bool: The boolean value.
|
|
146
|
+
"""
|
|
147
|
+
return self.read_key(section, key, bool)
|
|
148
|
+
|
|
149
|
+
def get_list(self, section: str, key: str) -> List[str]:
|
|
150
|
+
"""Read a list value from the configuration file.
|
|
151
|
+
|
|
152
|
+
Parameters:
|
|
153
|
+
- section (str): The section in the configuration file.
|
|
154
|
+
- key (str): The key to be read.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
list: The list value.
|
|
158
|
+
"""
|
|
159
|
+
return self.read_key(section, key, list)
|
|
160
|
+
|
|
161
|
+
def get_dict(self, section: str, key: str) -> dict:
|
|
162
|
+
"""Read a dictionary value from the configuration file.
|
|
163
|
+
|
|
164
|
+
Parameters:
|
|
165
|
+
- section (str): The section in the configuration file.
|
|
166
|
+
- key (str): The key to be read.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
dict: The dictionary value.
|
|
170
|
+
"""
|
|
171
|
+
return self.read_key(section, key, dict)
|
|
172
|
+
|
|
173
|
+
def set_key(self, section: str, key: str, value: Any) -> None:
|
|
174
|
+
"""Set a key in the configuration file.
|
|
175
|
+
|
|
176
|
+
Parameters:
|
|
177
|
+
- section (str): The section in the configuration file.
|
|
178
|
+
- key (str): The key to be set.
|
|
179
|
+
- value (Any): The value to be associated with the key.
|
|
180
|
+
"""
|
|
181
|
+
try:
|
|
182
|
+
if section not in self.config:
|
|
183
|
+
self.config[section] = {}
|
|
184
|
+
|
|
185
|
+
self.config[section][key] = value
|
|
186
|
+
cache_key = f"{section}.{key}"
|
|
187
|
+
self.cache[cache_key] = value
|
|
188
|
+
self.write_config()
|
|
189
|
+
|
|
190
|
+
except Exception as e:
|
|
191
|
+
print(f"Error setting key '{key}' in section '{section}': {e}")
|
|
192
|
+
|
|
193
|
+
def write_config(self) -> None:
|
|
194
|
+
"""Write the configuration to the file."""
|
|
195
|
+
try:
|
|
196
|
+
with open(self.file_path, 'w') as f:
|
|
197
|
+
json.dump(self.config, f, indent=4)
|
|
198
|
+
except Exception as e:
|
|
199
|
+
print(f"Error writing configuration file: {e}")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# Initialize
|
|
203
|
+
config_manager = ConfigManager()
|
|
204
|
+
config_manager.read_config()
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
# 21.06.24
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import inspect
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def get_call_stack():
|
|
8
|
-
"""
|
|
9
|
-
Retrieves the current call stack with details about each call.
|
|
10
|
-
|
|
11
|
-
This function inspects the current call stack and returns a list of dictionaries,
|
|
12
|
-
where each dictionary contains details about a function call in the stack.
|
|
13
|
-
|
|
14
|
-
Returns:
|
|
15
|
-
list: A list of dictionaries, each containing the following keys:
|
|
16
|
-
- function (str): The name of the function.
|
|
17
|
-
- folder (str): The directory path of the script containing the function.
|
|
18
|
-
- folder_base (str): The base name of the directory path.
|
|
19
|
-
- script (str): The name of the script file containing the function.
|
|
20
|
-
- line (int): The line number in the script where the function is defined.
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
stack = inspect.stack()
|
|
24
|
-
call_stack = []
|
|
25
|
-
|
|
26
|
-
for frame_info in stack:
|
|
27
|
-
function_name = frame_info.function
|
|
28
|
-
filename = frame_info.filename
|
|
29
|
-
lineno = frame_info.lineno
|
|
30
|
-
folder_name = os.path.dirname(filename)
|
|
31
|
-
folder_base = os.path.basename(folder_name)
|
|
32
|
-
script_name = os.path.basename(filename)
|
|
33
|
-
|
|
34
|
-
call_stack.append({
|
|
35
|
-
"function": function_name,
|
|
36
|
-
"folder": folder_name,
|
|
37
|
-
"folder_base": folder_base,
|
|
38
|
-
"script": script_name,
|
|
39
|
-
"line": lineno
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return call_stack
|
|
1
|
+
# 21.06.24
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import inspect
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_call_stack():
|
|
8
|
+
"""
|
|
9
|
+
Retrieves the current call stack with details about each call.
|
|
10
|
+
|
|
11
|
+
This function inspects the current call stack and returns a list of dictionaries,
|
|
12
|
+
where each dictionary contains details about a function call in the stack.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
list: A list of dictionaries, each containing the following keys:
|
|
16
|
+
- function (str): The name of the function.
|
|
17
|
+
- folder (str): The directory path of the script containing the function.
|
|
18
|
+
- folder_base (str): The base name of the directory path.
|
|
19
|
+
- script (str): The name of the script file containing the function.
|
|
20
|
+
- line (int): The line number in the script where the function is defined.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
stack = inspect.stack()
|
|
24
|
+
call_stack = []
|
|
25
|
+
|
|
26
|
+
for frame_info in stack:
|
|
27
|
+
function_name = frame_info.function
|
|
28
|
+
filename = frame_info.filename
|
|
29
|
+
lineno = frame_info.lineno
|
|
30
|
+
folder_name = os.path.dirname(filename)
|
|
31
|
+
folder_base = os.path.basename(folder_name)
|
|
32
|
+
script_name = os.path.basename(filename)
|
|
33
|
+
|
|
34
|
+
call_stack.append({
|
|
35
|
+
"function": function_name,
|
|
36
|
+
"folder": folder_name,
|
|
37
|
+
"folder_base": folder_base,
|
|
38
|
+
"script": script_name,
|
|
39
|
+
"line": lineno
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return call_stack
|