Surn commited on
Commit
995bb60
·
1 Parent(s): c4f500c

user_history 0.3.2

Browse files
Files changed (1) hide show
  1. modules/user_history.py +8 -8
modules/user_history.py CHANGED
@@ -18,7 +18,7 @@ Useful links:
18
  Update by Surn (Charles Fettinger)
19
  """
20
 
21
- __version__ = "0.3.1"
22
 
23
  import json
24
  import os
@@ -393,7 +393,7 @@ def _copy_image(image: Image.Image | np.ndarray | str | Path, dst_folder: Path,
393
  if isinstance(image, str):
394
  image = Path(image)
395
  if isinstance(image, Path):
396
- dst = dst_folder / f"{uniqueId}_{Path(image).name}.png" # keep file ext
397
  shutil.copyfile(image, dst)
398
  return dst
399
 
@@ -401,7 +401,7 @@ def _copy_image(image: Image.Image | np.ndarray | str | Path, dst_folder: Path,
401
  if isinstance(image, np.ndarray):
402
  image = Image.Image.fromarray(image)
403
  if isinstance(image, Image):
404
- dst = dst_folder / f"{Path(image).name}.png"
405
  image.save(dst)
406
  return dst
407
 
@@ -420,21 +420,21 @@ def _copy_file(file: Any | np.ndarray | str | Path, dst_folder: Path, uniqueId:
420
  if isinstance(file, str):
421
  file = Path(file)
422
  if isinstance(file, Path):
423
- dst = dst_folder / f"{file.stem}_{uniqueId}{file.suffix}" # keep file ext
424
  shutil.copyfile(file, dst)
425
  return dst
426
 
427
  # Still a Python object => serialize it
428
  if isinstance(file, np.ndarray):
429
  file = Image.fromarray(file)
430
- dst = dst_folder / f"{file.filename}_{uniqueId}{file.suffix}"
431
  file.save(dst)
432
  return dst
433
 
434
  # try other file types
435
  kind = filetype.guess(file)
436
  if kind is not None:
437
- dst = dst_folder / f"{Path(file).stem}_{uniqueId}.{kind.extension}"
438
  shutil.copyfile(file, dst)
439
  return dst
440
  raise ValueError(f"Unsupported file type: {type(file)}")
@@ -454,7 +454,7 @@ def _add_metadata(file_location: Path, metadata: Dict[str, Any], support_path: s
454
  raise ValueError("Invalid file type. Valid file types are .wav, .mp3, .mp4, .png")
455
 
456
  directory, filename, name, ext, new_ext = get_file_parts(file_location)
457
- new_file_location = rename_file_to_lowercase_extension(directory + name +"_h"+ new_ext)
458
 
459
  if file_type == ".wav":
460
  # Open and process .wav file
@@ -484,7 +484,7 @@ def _add_metadata(file_location: Path, metadata: Dict[str, Any], support_path: s
484
  elif file_type == ".mp4":
485
  # Open and process .mp4 file
486
  # Add metadata to the file
487
- wave_file_location = Path(support_path) if support_path is not None else file_location.with_suffix(".wav")
488
  wave_exists = wav_file_location.exists()
489
  if not wave_exists:
490
  # Use torchaudio to create the WAV file if it doesn't exist
 
18
  Update by Surn (Charles Fettinger)
19
  """
20
 
21
+ __version__ = "0.3.2"
22
 
23
  import json
24
  import os
 
393
  if isinstance(image, str):
394
  image = Path(image)
395
  if isinstance(image, Path):
396
+ dst = dst_folder / Path(f"{uniqueId}_{Path(image).name}") # keep file ext
397
  shutil.copyfile(image, dst)
398
  return dst
399
 
 
401
  if isinstance(image, np.ndarray):
402
  image = Image.Image.fromarray(image)
403
  if isinstance(image, Image):
404
+ dst = dst_folder / Path(f"{Path(image).name}")
405
  image.save(dst)
406
  return dst
407
 
 
420
  if isinstance(file, str):
421
  file = Path(file)
422
  if isinstance(file, Path):
423
+ dst = dst_folder / Path(f"{file.stem}_{uniqueId}{file.suffix}") # keep file ext
424
  shutil.copyfile(file, dst)
425
  return dst
426
 
427
  # Still a Python object => serialize it
428
  if isinstance(file, np.ndarray):
429
  file = Image.fromarray(file)
430
+ dst = dst_folder / Path(f"{file.stem}_{uniqueId}{file.suffix}")
431
  file.save(dst)
432
  return dst
433
 
434
  # try other file types
435
  kind = filetype.guess(file)
436
  if kind is not None:
437
+ dst = dst_folder / Path(f"{Path(file).stem}_{uniqueId}.{kind.extension}")
438
  shutil.copyfile(file, dst)
439
  return dst
440
  raise ValueError(f"Unsupported file type: {type(file)}")
 
454
  raise ValueError("Invalid file type. Valid file types are .wav, .mp3, .mp4, .png")
455
 
456
  directory, filename, name, ext, new_ext = get_file_parts(file_location)
457
+ new_file_location = rename_file_to_lowercase_extension(os.path.join(directory, name +"_h"+ new_ext))
458
 
459
  if file_type == ".wav":
460
  # Open and process .wav file
 
484
  elif file_type == ".mp4":
485
  # Open and process .mp4 file
486
  # Add metadata to the file
487
+ wav_file_location = Path(support_path) if support_path is not None else file_location.with_suffix(".wav")
488
  wave_exists = wav_file_location.exists()
489
  if not wave_exists:
490
  # Use torchaudio to create the WAV file if it doesn't exist