Created
May 4, 2024 23:45
-
-
Save cmpadden/1887c61a32fb0650b9007b79de8deca1 to your computer and use it in GitHub Desktop.
Rename epub library from metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Renames epub files using title and author(s) present in metadata.""" | |
| import ebookmeta | |
| import os | |
| import shutil | |
| from glob import glob | |
| SOURCE_DIRECTORY = os.path.expanduser("~/Desktop/Books/") | |
| DESTINATION_DIRECTORY = os.path.expanduser("~/Desktop/Library/") | |
| os.makedirs(DESTINATION_DIRECTORY, exist_ok=True) | |
| for f in glob(f"{SOURCE_DIRECTORY}*.epub"): | |
| meta = ebookmeta.get_metadata(f) | |
| new_file_name = f"{meta.title} - {', '.join(meta.author_list)}.epub" | |
| shutil.copy(f, DESTINATION_DIRECTORY + new_file_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment