abstract-webtools 0.1.6.68__py3-none-any.whl → 0.1.6.70__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.
@@ -201,7 +201,34 @@ def get_thumbnails(directory,info):
201
201
  info['thumbnails'][i]['path']=thumbnail_path
202
202
  download_image(thumbnail_url, save_path=thumbnail_path)
203
203
  return info
204
- def downloadvideo(url,directory=False,rename_display=True,thumbnails=True,audio=False):
204
+ def optimize_video_for_safari(input_file):
205
+ """
206
+ Optimizes an MP4 file for Safari by moving the 'moov' atom to the beginning.
207
+ The optimized file will be saved as <original>_optimized.mp4.
208
+
209
+ Args:
210
+ input_file (str): Path to the original MP4 file.
211
+
212
+ Returns:
213
+ str: Path to the optimized MP4 file.
214
+ """
215
+ # Build the output file name
216
+ base, ext = os.path.splitext(input_file)
217
+ output_file = f"{base}_optimized{ext}"
218
+
219
+ # ffmpeg command to copy streams and reposition the moov atom
220
+ command = ["ffmpeg", "-i", input_file, "-c", "copy", "-movflags", "faststart", output_file]
221
+ try:
222
+ subprocess.run(command, check=True)
223
+ # Optionally, you could remove the original file or keep both.
224
+ os.remove(input_file)
225
+ os.rename(output_file, input_file)
226
+ print(f"Optimized video saved as {input_file}")
227
+ except subprocess.CalledProcessError as e:
228
+ print(f"Error during optimization: {e}")
229
+ return input_file
230
+
231
+ def downloadvideo(url, directory=False, rename_display=True, thumbnails=True, audio=False):
205
232
  directory = directory or os.getcwd()
206
233
  temp_id = re.sub(r'[^\w\d.-]', '_', url)[-20:]
207
234
  temp_filename = f"temp_{temp_id}.mp4"
@@ -213,9 +240,10 @@ def downloadvideo(url,directory=False,rename_display=True,thumbnails=True,audio=
213
240
  output_filename=temp_filename
214
241
  )
215
242
  info = video_mgr.info
216
- display_id= info.get('display_id') or info.get('id')
217
- directory =os.path.join(directory,display_id)
243
+ display_id = info.get('display_id') or info.get('id')
244
+ directory = os.path.join(directory, display_id)
218
245
  os.makedirs(directory, exist_ok=True)
246
+
219
247
  if rename_display and info and 'file_path' in info:
220
248
  # Rename using metadata
221
249
  video_id = info.get('id', temp_id)
@@ -226,15 +254,20 @@ def downloadvideo(url,directory=False,rename_display=True,thumbnails=True,audio=
226
254
  if os.path.exists(info['file_path']):
227
255
  os.rename(info['file_path'], new_path)
228
256
  info['file_path'] = new_path
229
- info_path = os.path.join(directory,'info.json')
257
+
258
+ # *** Here we call the optimization function ***
259
+ if new_path.lower().endswith('.mp4'):
260
+ info['file_path'] = optimize_video_for_safari(new_path)
261
+
262
+ info_path = os.path.join(directory, 'info.json')
230
263
  if thumbnails:
231
- info = get_thumbnails(directory,info)
264
+ info = get_thumbnails(directory, info)
232
265
  if audio:
233
266
  try:
234
267
  info = download_audio(directory, info)
235
268
  except:
236
- info['audio_path'] = audio_path
237
- info['json_path']=info_path
238
- safe_dump_to_file(info,info_path)
269
+ info['audio_path'] = None
270
+ info['json_path'] = info_path
271
+ safe_dump_to_file(info, info_path)
239
272
  return info
240
273
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_webtools
3
- Version: 0.1.6.68
3
+ Version: 0.1.6.70
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
@@ -25,7 +25,7 @@ abstract_webtools/managers/sslManager.py,sha256=C-QgQw9CW84uOE5kx2MPjC3RsLbE2JQq
25
25
  abstract_webtools/managers/tlsAdapter.py,sha256=XZSMZz9EUOhv-h3_Waf6mjV1dA3oN_M_oWuoo4VZ_HE,1454
26
26
  abstract_webtools/managers/urlManager.py,sha256=Dvf-TiSo5j_YjZS2Eq6lFfbhveneD6NA_wEE0xUXy_E,8858
27
27
  abstract_webtools/managers/userAgentManager.py,sha256=cUaOlcCTzftVBCp9ZHwMXR9IB1wAE-03YSVwUBaIFLM,2514
28
- abstract_webtools/managers/videoDownloader.py,sha256=eFk0yF6Eq9sywhNlnEC1HrnFe5zlcBXXS2UqWQN_2aE,10436
28
+ abstract_webtools/managers/videoDownloader.py,sha256=aH1Lu-pxdmzaHg6UDxZxxJ2riZc_NiJUJ_3k1Xes5bA,11653
29
29
  abstract_webtools/managers/videoDownloader2.py,sha256=v3H6akdhvVWGrB-r35m3cp_-aKkNWadpfCiMylOnv6w,12748
30
30
  abstract_webtools/managers/linkManager/__init__.py,sha256=NpfWNzvTLSfsIWSeLYIxPzeLHADk_grSx5rfgCeWERw,27
31
31
  abstract_webtools/managers/linkManager/linkManager.py,sha256=roxOzOELca0rOlcMaJkTQHN3S0XF7dJihZmMq-uIXPQ,12184
@@ -37,7 +37,7 @@ abstract_webtools/managers/soupManager/soupManager.py,sha256=U3_o189-OWoBRaSCe2s
37
37
  abstract_webtools/managers/urlManager/__init__.py,sha256=gaJCHeK91Z-eYsBnxgdhbIUten1-gbx-zqx70R6ag-Y,26
38
38
  abstract_webtools/managers/urlManager/urlManager.py,sha256=vCFuLADmv3h7icaaoAsImGqb_49VizPY_ZvMl-C7PYk,7756
39
39
  abstract_webtools/managers/videos/Heather brooke swallo from condom.mp4,sha256=h-bKFLAHt7pGLGu4EcMvSSox7BPRK0Nga3u813iMVKQ,8335544
40
- abstract_webtools-0.1.6.68.dist-info/METADATA,sha256=kgWgdN5nB7OjAErke8KHMYD0mLi6yVvIbBRx6TR9GQM,16029
41
- abstract_webtools-0.1.6.68.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
42
- abstract_webtools-0.1.6.68.dist-info/top_level.txt,sha256=2DMJ7RmjTcjCsa-uwAV0K6eXXlIIkFDEjBLg_uyCmCI,18
43
- abstract_webtools-0.1.6.68.dist-info/RECORD,,
40
+ abstract_webtools-0.1.6.70.dist-info/METADATA,sha256=p1B2GUVN6SXGxZEnAhokHvDNikp-L0TKJWXhprTQk4U,16029
41
+ abstract_webtools-0.1.6.70.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
42
+ abstract_webtools-0.1.6.70.dist-info/top_level.txt,sha256=2DMJ7RmjTcjCsa-uwAV0K6eXXlIIkFDEjBLg_uyCmCI,18
43
+ abstract_webtools-0.1.6.70.dist-info/RECORD,,