This commit is contained in:
bender
2023-01-25 17:44:15 -05:00
parent 21b44c148a
commit 31053d5465
9 changed files with 55 additions and 16 deletions
+4 -3
View File
@@ -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)
shutil.move(folder_path, archive + folder)
+2 -1
View File
@@ -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):
+24
View File
@@ -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"
+3 -1
View File
@@ -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)
+3 -2
View File
@@ -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")
shutil.move(subfolder_path, bookshelf)
+2 -1
View File
@@ -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:
+5 -5
View File
@@ -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
+10 -2
View File
@@ -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
+2 -1
View File
@@ -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)