generate_pretty_name.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import re
  3. def generate_pretty_name(directory: str):
  4. name = directory
  5. # remove directory name
  6. name = os.path.basename(name)
  7. # remove the date and time
  8. date_regex = r"([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2})"
  9. name = re.sub(date_regex, "", name)
  10. # remove "audio"
  11. name = name.replace("audio", "")
  12. # replace _long with (long)
  13. name = name.replace("_long", "(long)")
  14. # replace continued_generation with history: continued
  15. name = name.replace("continued_generation", "history: continued")
  16. # replace the new continued_from_ with history:
  17. name = name.replace("from_", "history: ")
  18. # replace none with history: none
  19. name = name.replace("None", "history: none")
  20. # __bark__None
  21. name = name.replace("__", " ")
  22. # bark None
  23. return name.strip().capitalize()
  24. if __name__ == "__main__":
  25. # outputs\2023-06-02_10-54-24__bark__None
  26. dirname = "outputs\\2023-06-02_10-54-24__bark__None"
  27. print(generate_pretty_name(dirname))
  28. # outputs\audio__bark__continued_generation__2023-05-21_15-36-14
  29. dirname = "outputs\\audio__bark__continued_generation__2023-05-21_15-36-14"
  30. print(generate_pretty_name(dirname))
  31. # outputs\audio__bark__continued_generation__2023-05-21_15-36-14_long
  32. dirname = "outputs\\audio__bark__continued_generation__2023-05-21_15-36-14_long"
  33. print(generate_pretty_name(dirname))