Skip to content

Instantly share code, notes, and snippets.

@duplaja
Created December 31, 2023 03:59
Show Gist options
  • Save duplaja/8605140e6f84d6dba9c765f264a40ce2 to your computer and use it in GitHub Desktop.
Save duplaja/8605140e6f84d6dba9c765f264a40ce2 to your computer and use it in GitHub Desktop.
CLI to Set Series and Series Index on Epubs
#!/usr/bin/env python
import ebookmeta
import argparse
# Initialize the argument parser
parser = argparse.ArgumentParser(description='Process arguments.')
# Add the mandatory arguments
parser.add_argument('series_name', help='Series Name (allowing spaces)', type=str)
parser.add_argument('series_index', help='Series Index', type=str)
parser.add_argument('filename', help='Epub filename', type=str)
# Parse the arguments
args = parser.parse_args()
series_name = args.series_name
series_index = args.series_index
epub_filename = args.filename
#Gets existing metadata, displays title and author(s)
meta = ebookmeta.get_metadata(epub_filename) # returning Metadata class
print(meta.title)
for author in meta.author_list:
print(author)
#Sets new series name and index
meta.series = series_name
meta.series_index = series_index
ebookmeta.set_metadata(epub_filename, meta)
#Gets Updated Metadata to Display / Confirm
newmeta = ebookmeta.get_metadata(epub_filename)
print('Series: '+newmeta.series)
print('Index: '+newmeta.series_index)
@duplaja
Copy link
Author

duplaja commented Dec 31, 2023

usage: python3 epubseries.py [-h] series_name series_index filename

positional arguments:
series_name Series Name (allowing spaces)
series_index Series Index
filename Epub filename

options:
-h, --help show this help message and exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment