eaf-base-api 1.0__tar.gz → 1.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.
- {eaf_base_api-1.0 → eaf_base_api-1.2}/PKG-INFO +1 -1
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/base.py +52 -9
- eaf_base_api-1.2/base_api/modules/consts.py +1 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/eaf_base_api.egg-info/PKG-INFO +1 -1
- {eaf_base_api-1.0 → eaf_base_api-1.2}/eaf_base_api.egg-info/SOURCES.txt +1 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/setup.py +1 -1
- {eaf_base_api-1.0 → eaf_base_api-1.2}/README.md +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/__init__.py +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/modules/__init__.py +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/modules/download.py +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/modules/progress_bars.py +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/base_api/modules/quality.py +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/eaf_base_api.egg-info/dependency_links.txt +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/eaf_base_api.egg-info/requires.txt +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/eaf_base_api.egg-info/top_level.txt +0 -0
- {eaf_base_api-1.0 → eaf_base_api-1.2}/setup.cfg +0 -0
|
@@ -5,6 +5,8 @@ import time
|
|
|
5
5
|
from base_api.modules.quality import Quality
|
|
6
6
|
from base_api.modules.progress_bars import Callback
|
|
7
7
|
from base_api.modules.download import default, threaded, FFMPEG
|
|
8
|
+
from base_api.modules.consts import MAX_RETRIES
|
|
9
|
+
from pathlib import Path
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
def setup_api(do_logging=False):
|
|
@@ -21,8 +23,8 @@ base_qualities = ["250p", "360p", "480p", "720p", "1080p", "1440p", "2160p"]
|
|
|
21
23
|
|
|
22
24
|
class Core:
|
|
23
25
|
@classmethod
|
|
24
|
-
def get_content(cls, url, headers=None, cookies=None
|
|
25
|
-
for i in range(
|
|
26
|
+
def get_content(cls, url, headers=None, cookies=None):
|
|
27
|
+
for i in range(MAX_RETRIES):
|
|
26
28
|
try:
|
|
27
29
|
logging.debug(f"Trying to fetch {url} / Attempt: [{i+1}]")
|
|
28
30
|
response = requests.get(url, headers=headers, cookies=cookies)
|
|
@@ -33,9 +35,9 @@ class Core:
|
|
|
33
35
|
logging.warning(f"Failed to fetch {url} with status code {response.status_code} on attempt [{i+1}]")
|
|
34
36
|
except requests.exceptions.RequestException as e:
|
|
35
37
|
logging.error(f"Exception occurred when trying to fetch {url} on attempt [{i+1}]: {e}")
|
|
36
|
-
if i <
|
|
38
|
+
if i < MAX_RETRIES - 1: # Implement exponential backoff
|
|
37
39
|
time.sleep(2 ** i)
|
|
38
|
-
logging.error(f"Failed to fetch {url} after {
|
|
40
|
+
logging.error(f"Failed to fetch {url} after {MAX_RETRIES} attempts.")
|
|
39
41
|
logging.error("Returning None")
|
|
40
42
|
return None
|
|
41
43
|
|
|
@@ -86,12 +88,12 @@ class Core:
|
|
|
86
88
|
|
|
87
89
|
return self.quality_url_map.get(selected_quality)
|
|
88
90
|
|
|
89
|
-
def download(self, video, quality, downloader,
|
|
91
|
+
def download(self, video, quality, downloader, path, callback=None):
|
|
90
92
|
"""
|
|
91
93
|
:param callback:
|
|
92
94
|
:param downloader:
|
|
93
95
|
:param quality:
|
|
94
|
-
:param
|
|
96
|
+
:param path:
|
|
95
97
|
:return:
|
|
96
98
|
"""
|
|
97
99
|
quality = self.fix_quality(quality)
|
|
@@ -100,11 +102,52 @@ class Core:
|
|
|
100
102
|
callback = Callback.text_progress_bar
|
|
101
103
|
|
|
102
104
|
if downloader == default or str(downloader) == "default":
|
|
103
|
-
default(video=video, quality=quality, path=
|
|
105
|
+
default(video=video, quality=quality, path=path, callback=callback)
|
|
104
106
|
|
|
105
107
|
elif downloader == threaded or str(downloader) == "threaded":
|
|
106
108
|
threaded_download = threaded(max_workers=20, timeout=10)
|
|
107
|
-
threaded_download(video=video, quality=quality, path=
|
|
109
|
+
threaded_download(video=video, quality=quality, path=path, callback=callback)
|
|
108
110
|
|
|
109
111
|
elif downloader == FFMPEG or str(downloader) == "FFMPEG":
|
|
110
|
-
FFMPEG(video=video, quality=quality, path=
|
|
112
|
+
FFMPEG(video=video, quality=quality, path=path, callback=callback)
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def correct_path(cls, path):
|
|
116
|
+
return Path(path)
|
|
117
|
+
|
|
118
|
+
@classmethod
|
|
119
|
+
def get_segments(cls, quality, m3u8_base_url):
|
|
120
|
+
quality = Core().fix_quality(quality)
|
|
121
|
+
base_url = m3u8_base_url
|
|
122
|
+
new_segment = Core().get_m3u8_by_quality(quality, m3u8_base_url=base_url)
|
|
123
|
+
# Split the base URL into components
|
|
124
|
+
url_components = base_url.split('/')
|
|
125
|
+
|
|
126
|
+
# Replace the last component with the new segment
|
|
127
|
+
url_components[-1] = new_segment
|
|
128
|
+
|
|
129
|
+
# Rejoin the components into the new full URL
|
|
130
|
+
new_url = '/'.join(url_components)
|
|
131
|
+
master_src = Core().get_content(url=new_url).decode("utf-8")
|
|
132
|
+
|
|
133
|
+
urls = [l for l in master_src.splitlines()
|
|
134
|
+
if l and not l.startswith('#')]
|
|
135
|
+
|
|
136
|
+
segments = []
|
|
137
|
+
|
|
138
|
+
for url in urls:
|
|
139
|
+
url_components[-1] = url
|
|
140
|
+
new_url = '/'.join(url_components)
|
|
141
|
+
segments.append(new_url)
|
|
142
|
+
|
|
143
|
+
return segments
|
|
144
|
+
|
|
145
|
+
@classmethod
|
|
146
|
+
def strip_title(cls, title: str) -> str:
|
|
147
|
+
"""
|
|
148
|
+
:param title:
|
|
149
|
+
:return: str: strips out non UTF-8 chars of the title
|
|
150
|
+
"""
|
|
151
|
+
illegal_chars = '<>:"/\\|?*'
|
|
152
|
+
cleaned_title = ''.join([char for char in title if char in string.printable and char not in illegal_chars])
|
|
153
|
+
return cleaned_title
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MAX_RETRIES = 4
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|