Skip to content

Commit

Permalink
Merge pull request #7 from orbitalteapot/develop
Browse files Browse the repository at this point in the history
Added issue 3, 4, 5
  • Loading branch information
orbitalteapot authored Aug 1, 2023
2 parents 084752e + 867290c commit f9e3184
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenAudible Organizer

Organize your audiobook or music collection!
Organize your audiobook collection!

[![Audiobook latest](https://github.com/orbitalteapot/audiocollectionsorter/actions/workflows/docker-audiobooksort-latest.yml/badge.svg)](https://github.com/orbitalteapot/audiocollectionsorter/actions/workflows/docker-audiobooksort-latest.yml)
[![Audiobook tagged](https://github.com/orbitalteapot/audiocollectionsorter/actions/workflows/docker-audiobooksort.yml/badge.svg)](https://github.com/orbitalteapot/audiocollectionsorter/actions/workflows/docker-audiobooksort.yml)
Expand All @@ -16,7 +16,7 @@ It can be downloaded **[here](https://github.com/orbitalteapot/OpenAudible-FileO
### Running the Program
Fill in the details promptet as ilustrated below:

![Example](images/example.png)
![Example](images/menu.gif)

The program will now quickly organize a copy of your books in the spesified folder.

Expand Down
Binary file removed images/example.png
Binary file not shown.
Binary file added images/menu.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions scripts/organize_audiobook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys

class Book:
file_name = str
def __init__(self, key, title, author, narrated_by, purchase_date, duration, release_date, ave_rating, genre, series_name, series_sequence, product_id, asin, book_url, summary, description, rating_count, publisher, short_title, copyright, author_url, file_name, series_url, abridged, language, pdf_url, image_url, region, ayce, read_status, user_id, audible_aax, image, m4b=None):
self.key = key
self.title = title
Expand Down Expand Up @@ -42,6 +43,17 @@ def __init__(self, key, title, author, narrated_by, purchase_date, duration, rel
self.image = image
self.m4b = m4b


def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))

percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)

sys.stdout.write('[%s] %s%s %s\r' % (bar, percents, '%', status))
sys.stdout.flush()

def sanitize(path):
return re.sub(r'[\\/*?:"<>|]', ',', path)

Expand Down Expand Up @@ -90,6 +102,7 @@ def move_audio(file, author, album, title, book_number, destination_folder):

def organize_audio(source_folder, csv_file, destination_folder):
books = load_books(csv_file)
i = 0
for subdir, dirs, files in os.walk(source_folder):
for file in files:
file_path = os.path.join(subdir, file)
Expand All @@ -101,27 +114,31 @@ def organize_audio(source_folder, csv_file, destination_folder):
if title:
book_number = None

book = next((b for b in books if b.file_name + ".m4b" == file), None)
book = next((b for b in books if b.file_name in file), None)
if book:
author = sanitize(book.author)
if book.series_name:
album = sanitize(book.series_name)
title = sanitize(book.file_name)
if book.series_sequence:
book_number = sanitize(book.series_sequence)

move_audio(file_path, author, album, title, book_number, destination_folder)
progress(i, len(books), status=f"Organizing Audiobook {i} of {len(books)}")
i += 1

else:
print(f"Metadata is missing for file {file_path}")
else:
print(f"Unable to load metadata for file {file_path}")

progress(i, len(books), status="Organizing Audiobooks")
try:
print("The script will only take .m4b file format at the moment")
print("The script will make a copy of your audiobooks in a new folder structure based on the metadata in the openaudible export file.")
source_folder = input("Enter the full path to the source folder containing audio files: ")
csv_file = input("Enter the full path to the openaudible book export file: ")
destination_folder = input("Enter the full path to the destination folder where you want the organized copy of your audiobooks: ")
organize_audio(source_folder, csv_file, destination_folder)
print("Done!")
except Exception as e:
print(f"Unexpected error: {e}")
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion scripts/organize_audiobook_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def organize_audio(source_folder, csv_folder, destination_folder):
if title:
book_number = None

book = next((b for b in books if b.file_name + ".m4b" == file), None)
book = next((b for b in books if b.file_name in file), None)
if book:
author = sanitize(book.author)
if book.series_name:
Expand Down

0 comments on commit f9e3184

Please sign in to comment.