From 31053d5465c9073501c052918545efcaeeb6da90 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 25 Jan 2023 17:44:15 -0500 Subject: [PATCH] updates --- 00_exportchapters.py | 7 ++++--- chapter_ms.py | 3 ++- config.py | 24 ++++++++++++++++++++++++ durations.py | 4 +++- final_metadata_add.py | 5 +++-- metadatatoxml.py | 3 ++- overdrive_full.sh | 10 +++++----- overdrivedelete.sh | 12 ++++++++++-- xmlparse.py | 3 ++- 9 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 config.py diff --git a/00_exportchapters.py b/00_exportchapters.py index c14b15e..8836d5c 100644 --- a/00_exportchapters.py +++ b/00_exportchapters.py @@ -3,6 +3,7 @@ import os import shutil from pydub import AudioSegment +from config import annex,circulation,archive AudioSegment.converter = "/opt/homebrew/Cellar/ffmpeg/5.1.2_3/bin/ffmpeg" AudioSegment.ffmpeg = "/opt/homebrew/Cellar/ffmpeg/5.1.2_3/bin/ffmpeg" @@ -13,7 +14,7 @@ def export_audio_file(start, end, name): end_ms = int(end) export = combined[start_ms:end_ms] folder_name = folder.split(" - ")[-1].strip() - destination_path = '/Users/jonas/Documents/SERVER/BOOKS/01_LABELED AUDIO' + destination_path = circulation author_name = folder.split(" - ")[0].strip() export_folder = os.path.join(destination_path, author_name, folder_name) author_folder = os.path.join(destination_path, author_name) @@ -33,7 +34,7 @@ def export_audio_file(start, end, name): shutil.copy(album_art, export_folder) shutil.copy(metadata_file, export_folder) -main_directory = "/Users/jonas/Documents/SERVER/BOOKS/TEST" +main_directory = annex for folder in sorted(os.listdir(main_directory)): folder_path = os.path.join(main_directory, folder) @@ -80,4 +81,4 @@ for folder in sorted(os.listdir(main_directory)): #Archive everything except chapters_list.py if folder_path != "chapters_list.py": - shutil.move(folder_path, '/Users/jonas/Documents/SERVER/BOOKS/00_ARCHIVE/' + folder) \ No newline at end of file + shutil.move(folder_path, archive + folder) \ No newline at end of file diff --git a/chapter_ms.py b/chapter_ms.py index eef606a..4619412 100644 --- a/chapter_ms.py +++ b/chapter_ms.py @@ -3,6 +3,7 @@ import os import re from datetime import datetime, timedelta +from config import annex def duration_to_milliseconds(duration): hours, minutes, seconds = duration.split(':') @@ -10,7 +11,7 @@ def duration_to_milliseconds(duration): return int(seconds * 1000) # path to directory containing the files -directory = '/Users/jonas/Documents/SERVER/BOOKS/TEST' +directory = annex # loop through all files in directory tree for dirpath, dirnames, filenames in os.walk(directory): diff --git a/config.py b/config.py new file mode 100644 index 0000000..4f408ff --- /dev/null +++ b/config.py @@ -0,0 +1,24 @@ +# Define directories +# I like having multiple folders so as to visualize each step happening +# but you could easily adjust the setup to fit your preferences + +import os + +# Where you will be downloading your .odm's to, we're writing this one +# as an environment for the bash to reference +os.environ["queue"] = "/Users/jonas/Documents/SERVER/QUEUE" + +# Where the unpackaged odm mp3s will get moved +# First for the bash +os.environ["annex"] = "/Users/jonas/Documents/SERVER/BOOKS/01_ANNEX" +# Then for python +annex="/Users/jonas/Documents/SERVER/BOOKS/01_ANNEX" + +# Where chapterized and labeled mp3s will be stored +circulation="/Users/jonas/Documents/SERVER/BOOKS/02_CIRCULATION" + +# Where the final finished product will land +bookshelf="/Users/jonas/Documents/SERVER/BOOKS/03_READY_FOR_PLEX" + +# Where the scraps go +archive="/Users/jonas/Documents/SERVER/BOOKS/00_ARCHIVE" \ No newline at end of file diff --git a/durations.py b/durations.py index f93cc3b..a822a07 100644 --- a/durations.py +++ b/durations.py @@ -1,8 +1,10 @@ #Confirmed working as of 1/22/23 import os +from config import annex + +root_dir = annex -root_dir = '/Users/jonas/Documents/SERVER/BOOKS/TEST' for subdir, dirs, files in os.walk(root_dir): for file in files: file_path = os.path.join(subdir, file) diff --git a/final_metadata_add.py b/final_metadata_add.py index 0287ea2..1119997 100644 --- a/final_metadata_add.py +++ b/final_metadata_add.py @@ -5,6 +5,7 @@ import shutil import json import re from mutagen.id3 import ID3, APIC, TIT2, TPE1, TCOM, TCON, TSOA, TRCK, TIT3, TALB, COMM +from config import circulation,bookshelf def traverse_directory(directory): # Iterate through all subfolders and files @@ -65,7 +66,7 @@ def add_metadata(directory): audio.save() # Point the script at a directory -directory = "/Users/jonas/Documents/SERVER/BOOKS/01_LABELED AUDIO" +directory = circulation # Traverse the directory and apply the metadata to the mp3 files traverse_directory(directory) @@ -75,4 +76,4 @@ for root, dirs, files in os.walk(directory): subfolder_path = os.path.join(root, dir) parent_folder = os.path.dirname(subfolder_path) if parent_folder == directory: - shutil.move(subfolder_path, "/Users/jonas/Documents/SERVER/BOOKS/02_READY FOR PLEX") \ No newline at end of file + shutil.move(subfolder_path, bookshelf) \ No newline at end of file diff --git a/metadatatoxml.py b/metadatatoxml.py index 33c6902..dba08dc 100644 --- a/metadatatoxml.py +++ b/metadatatoxml.py @@ -2,8 +2,9 @@ import os import shutil +from config import annex -root_dir = '/Users/jonas/Documents/SERVER/BOOKS/TEST' +root_dir = annex for subdir, dirs, files in os.walk(root_dir): for file in files: diff --git a/overdrive_full.sh b/overdrive_full.sh index ee05cd3..4e91a42 100644 --- a/overdrive_full.sh +++ b/overdrive_full.sh @@ -2,15 +2,15 @@ #download odm's to chosen directory -#navigate to folder where scripts are located - -cd /Users/jonas/Documents/code/overdrive-plex +# configure variables +python3.10 config.py # unpack odm's bash overdrivedelete.sh -# extract chapters -python3.10 extract_overdrive_chapters.py /Users/jonas/Documents/SERVER/BOOKS/01_ANNEX +# extract chapters, specify folder holding the unpackaged overdrive mp3's +source config.env +python3.10 extract_overdrive_chapters.py $annex # clean metadata python3.10 metadatatoxml.py diff --git a/overdrivedelete.sh b/overdrivedelete.sh index 83ea478..1caa00a 100644 --- a/overdrivedelete.sh +++ b/overdrivedelete.sh @@ -1,7 +1,15 @@ #This officially works for the full ODM extraction as of 1/21/23 at 9:54pm -input_folder="/Users/jonas/Documents/SERVER/QUEUE" -output_folder="/Users/jonas/Documents/SERVER/BOOKS/01_ANNEX" +# Define the directories +source config.env +input_folder=$queue +output_folder=$annex + +shopt -s nullglob +if [ -z "$(find $input_folder -type f -name '*.odm')" ]; then + echo "No .odm files found in $input_folder, exiting." + exit 0 +fi # Open ODM's in temporary directory and export contents for file in $input_folder/*.odm diff --git a/xmlparse.py b/xmlparse.py index 3b89f40..8146de1 100644 --- a/xmlparse.py +++ b/xmlparse.py @@ -3,6 +3,7 @@ import os import xml.etree.ElementTree as ET import json +from config import annex def extract_metadata(xml_file): tree = ET.parse(xml_file) @@ -35,5 +36,5 @@ def process_folder(folder_path): json.dump(metadata, f) print(f"Processed {xml_file}, output saved to {cleaned_file}") -folder_path = "/Users/jonas/Documents/SERVER/BOOKS/TEST" +folder_path = annex process_folder(folder_path) \ No newline at end of file