abstract-webtools 0.1.6.89__py3-none-any.whl → 0.1.6.90__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.
- abstract_webtools/managers/videoDownloader.py +111 -0
- {abstract_webtools-0.1.6.89.dist-info → abstract_webtools-0.1.6.90.dist-info}/METADATA +1 -1
- {abstract_webtools-0.1.6.89.dist-info → abstract_webtools-0.1.6.90.dist-info}/RECORD +5 -5
- {abstract_webtools-0.1.6.89.dist-info → abstract_webtools-0.1.6.90.dist-info}/WHEEL +0 -0
- {abstract_webtools-0.1.6.89.dist-info → abstract_webtools-0.1.6.90.dist-info}/top_level.txt +0 -0
@@ -136,6 +136,117 @@ class VideoDownloader:
|
|
136
136
|
def stop(self):
|
137
137
|
self.monitoring = False
|
138
138
|
self.pause_event.set()
|
139
|
+
def download_image(url, save_path=None):
|
140
|
+
"""
|
141
|
+
Downloads an image from a URL and saves it to the specified path.
|
142
|
+
|
143
|
+
Args:
|
144
|
+
url (str): The URL of the image to download
|
145
|
+
save_path (str, optional): Path to save the image. If None, uses the filename from URL
|
146
|
+
|
147
|
+
Returns:
|
148
|
+
str: Path where the image was saved, or None if download failed
|
149
|
+
"""
|
150
|
+
try:
|
151
|
+
# Send GET request to the URL
|
152
|
+
response = requests.get(url, stream=True)
|
153
|
+
|
154
|
+
# Check if the request was successful
|
155
|
+
if response.status_code == 200:
|
156
|
+
# Set decode_content=True to automatically handle Content-Encoding
|
157
|
+
response.raw.decode_content = True
|
158
|
+
|
159
|
+
# If no save_path provided, extract filename from URL
|
160
|
+
if save_path is None:
|
161
|
+
# Get filename from URL
|
162
|
+
filename = url.split('/')[-1]
|
163
|
+
save_path = filename
|
164
|
+
|
165
|
+
# Ensure the directory exists
|
166
|
+
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
167
|
+
|
168
|
+
# Write the image content to file
|
169
|
+
with open(save_path, 'wb') as f:
|
170
|
+
f.write(response.content)
|
171
|
+
|
172
|
+
print(f"Image successfully downloaded to {save_path}")
|
173
|
+
return save_path
|
174
|
+
else:
|
175
|
+
print(f"Failed to download image. Status code: {response.status_code}")
|
176
|
+
return None
|
177
|
+
|
178
|
+
except requests.exceptions.RequestException as e:
|
179
|
+
print(f"Error downloading image: {str(e)}")
|
180
|
+
return None
|
181
|
+
except Exception as e:
|
182
|
+
print(f"An unexpected error occurred: {str(e)}")
|
183
|
+
return None
|
184
|
+
def get_thumbnails(directory,info):
|
185
|
+
thumbnails_dir = os.path.join(directory,'thumbnails')
|
186
|
+
os.makedirs(thumbnails_dir, exist_ok=True)
|
187
|
+
thumbnails = info.get('thumbnails',[])
|
188
|
+
for i,thumbnail_info in enumerate(thumbnails):
|
189
|
+
thumbnail_url = thumbnail_info.get('url')
|
190
|
+
thumbnail_base_url = thumbnail_url.split('?')[0]
|
191
|
+
baseName = os.path.basename(thumbnail_base_url)
|
192
|
+
fileName,ext = os.path.splitext(baseName)
|
193
|
+
baseName = f"{fileName}{ext}"
|
194
|
+
resolution = info['thumbnails'][i].get('resolution')
|
195
|
+
if resolution:
|
196
|
+
baseName = f"{resolution}_{baseName}"
|
197
|
+
img_id = info['thumbnails'][i].get('id')
|
198
|
+
if img_id:
|
199
|
+
baseName = f"{img_id}_{baseName}"
|
200
|
+
thumbnail_path = os.path.join(thumbnails_dir,baseName)
|
201
|
+
info['thumbnails'][i]['path']=thumbnail_path
|
202
|
+
download_image(thumbnail_url, save_path=thumbnail_path)
|
203
|
+
return info
|
204
|
+
def optimize_video_for_safari(input_file, reencode=False):
|
205
|
+
"""
|
206
|
+
Optimizes an MP4 file for Safari by moving the 'moov' atom to the beginning.
|
207
|
+
Optionally, re-encodes the video for maximum compatibility.
|
208
|
+
|
209
|
+
Args:
|
210
|
+
input_file (str): Path to the original MP4 file.
|
211
|
+
reencode (bool): If True, re-encode the video for Safari compatibility.
|
212
|
+
|
213
|
+
Returns:
|
214
|
+
str: Path to the optimized MP4 file.
|
215
|
+
"""
|
216
|
+
tmp_dir = tempfile.mkdtemp()
|
217
|
+
try:
|
218
|
+
local_input = os.path.join(tmp_dir, os.path.basename(input_file))
|
219
|
+
shutil.copy2(input_file, local_input)
|
220
|
+
|
221
|
+
base, ext = os.path.splitext(local_input)
|
222
|
+
local_output = f"{base}_optimized{ext}"
|
223
|
+
|
224
|
+
if reencode:
|
225
|
+
# Re-encoding command for maximum Safari compatibility
|
226
|
+
command = [
|
227
|
+
"ffmpeg", "-i", local_input,
|
228
|
+
"-c:v", "libx264", "-profile:v", "baseline", "-level", "3.0", "-pix_fmt", "yuv420p",
|
229
|
+
"-c:a", "aac", "-b:a", "128k",
|
230
|
+
"-movflags", "faststart",
|
231
|
+
local_output
|
232
|
+
]
|
233
|
+
else:
|
234
|
+
# Simple faststart with stream copy
|
235
|
+
command = [
|
236
|
+
"ffmpeg", "-i", local_input,
|
237
|
+
"-c", "copy", "-movflags", "faststart",
|
238
|
+
local_output
|
239
|
+
]
|
240
|
+
|
241
|
+
try:
|
242
|
+
subprocess.run(command, check=True)
|
243
|
+
shutil.copy2(local_output, input_file)
|
244
|
+
print(f"Optimized video saved as {input_file}")
|
245
|
+
except subprocess.CalledProcessError as e:
|
246
|
+
print(f"Error during optimization: {e}")
|
247
|
+
return input_file
|
248
|
+
finally:
|
249
|
+
shutil.rmtree(tmp_dir)
|
139
250
|
def bool_or_default(obj,default=True):
|
140
251
|
if obj == None:
|
141
252
|
obj = default
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: abstract_webtools
|
3
|
-
Version: 0.1.6.
|
3
|
+
Version: 0.1.6.90
|
4
4
|
Summary: Abstract Web Tools is a Python package that provides various utility functions for web scraping tasks. It is built on top of popular libraries such as `requests`, `BeautifulSoup`, and `urllib3` to simplify the process of fetching and parsing web content.
|
5
5
|
Home-page: https://github.com/AbstractEndeavors/abstract_essentials/tree/main/abstract_webtools
|
6
6
|
Author: putkoff
|
@@ -26,7 +26,7 @@ abstract_webtools/managers/sslManager.py,sha256=C-QgQw9CW84uOE5kx2MPjC3RsLbE2JQq
|
|
26
26
|
abstract_webtools/managers/tlsAdapter.py,sha256=XZSMZz9EUOhv-h3_Waf6mjV1dA3oN_M_oWuoo4VZ_HE,1454
|
27
27
|
abstract_webtools/managers/urlManager.py,sha256=Dvf-TiSo5j_YjZS2Eq6lFfbhveneD6NA_wEE0xUXy_E,8858
|
28
28
|
abstract_webtools/managers/userAgentManager.py,sha256=cUaOlcCTzftVBCp9ZHwMXR9IB1wAE-03YSVwUBaIFLM,2514
|
29
|
-
abstract_webtools/managers/videoDownloader.py,sha256=
|
29
|
+
abstract_webtools/managers/videoDownloader.py,sha256=oY9qiyV6tWKKNMlQgqkkeYo3wm8F6yD8XqsBZbp5yWQ,15375
|
30
30
|
abstract_webtools/managers/videoDownloader2.py,sha256=v3H6akdhvVWGrB-r35m3cp_-aKkNWadpfCiMylOnv6w,12748
|
31
31
|
abstract_webtools/managers/linkManager/__init__.py,sha256=NpfWNzvTLSfsIWSeLYIxPzeLHADk_grSx5rfgCeWERw,27
|
32
32
|
abstract_webtools/managers/linkManager/linkManager.py,sha256=roxOzOELca0rOlcMaJkTQHN3S0XF7dJihZmMq-uIXPQ,12184
|
@@ -38,7 +38,7 @@ abstract_webtools/managers/soupManager/soupManager.py,sha256=U3_o189-OWoBRaSCe2s
|
|
38
38
|
abstract_webtools/managers/urlManager/__init__.py,sha256=gaJCHeK91Z-eYsBnxgdhbIUten1-gbx-zqx70R6ag-Y,26
|
39
39
|
abstract_webtools/managers/urlManager/urlManager.py,sha256=vCFuLADmv3h7icaaoAsImGqb_49VizPY_ZvMl-C7PYk,7756
|
40
40
|
abstract_webtools/managers/videos/Heather brooke swallo from condom.mp4,sha256=h-bKFLAHt7pGLGu4EcMvSSox7BPRK0Nga3u813iMVKQ,8335544
|
41
|
-
abstract_webtools-0.1.6.
|
42
|
-
abstract_webtools-0.1.6.
|
43
|
-
abstract_webtools-0.1.6.
|
44
|
-
abstract_webtools-0.1.6.
|
41
|
+
abstract_webtools-0.1.6.90.dist-info/METADATA,sha256=9KBoZzDcF1imzfdgBeOglz185TT5kGvkdtbDRNqlQrw,16029
|
42
|
+
abstract_webtools-0.1.6.90.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
43
|
+
abstract_webtools-0.1.6.90.dist-info/top_level.txt,sha256=2DMJ7RmjTcjCsa-uwAV0K6eXXlIIkFDEjBLg_uyCmCI,18
|
44
|
+
abstract_webtools-0.1.6.90.dist-info/RECORD,,
|
File without changes
|
File without changes
|