initial commit
This commit is contained in:
		
						commit
						b8f3397afe
					
				
					 2 changed files with 155 additions and 0 deletions
				
			
		
							
								
								
									
										82
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,82 @@
 | 
			
		|||
out/
 | 
			
		||||
src/
 | 
			
		||||
 | 
			
		||||
*~
 | 
			
		||||
 | 
			
		||||
# temporary files which can be created if a process still has a handle open of a deleted file
 | 
			
		||||
.fuse_hidden*
 | 
			
		||||
 | 
			
		||||
# Metadata left by Dolphin file manager, which comes with KDE Plasma
 | 
			
		||||
.directory
 | 
			
		||||
 | 
			
		||||
# Linux trash folder which might appear on any partition or disk
 | 
			
		||||
.Trash-*
 | 
			
		||||
 | 
			
		||||
# .nfs files are created when an open file is removed but is still being accessed
 | 
			
		||||
.nfs*
 | 
			
		||||
 | 
			
		||||
# Log files created by default by the nohup command
 | 
			
		||||
nohup.out
 | 
			
		||||
 | 
			
		||||
# General
 | 
			
		||||
.DS_Store
 | 
			
		||||
__MACOSX/
 | 
			
		||||
.AppleDouble
 | 
			
		||||
.LSOverride
 | 
			
		||||
Icon[
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
# Thumbnails
 | 
			
		||||
._*
 | 
			
		||||
 | 
			
		||||
# Files that might appear in the root of a volume
 | 
			
		||||
.DocumentRevisions-V100
 | 
			
		||||
.fseventsd
 | 
			
		||||
.Spotlight-V100
 | 
			
		||||
.TemporaryItems
 | 
			
		||||
.Trashes
 | 
			
		||||
.VolumeIcon.icns
 | 
			
		||||
.com.apple.timemachine.donotpresent
 | 
			
		||||
 | 
			
		||||
# Directories potentially created on remote AFP share
 | 
			
		||||
.AppleDB
 | 
			
		||||
.AppleDesktop
 | 
			
		||||
Network Trash Folder
 | 
			
		||||
Temporary Items
 | 
			
		||||
.apdisk
 | 
			
		||||
 | 
			
		||||
# Windows thumbnail cache files
 | 
			
		||||
Thumbs.db
 | 
			
		||||
Thumbs.db:encryptable
 | 
			
		||||
ehthumbs.db
 | 
			
		||||
ehthumbs_vista.db
 | 
			
		||||
 | 
			
		||||
# Dump file
 | 
			
		||||
*.stackdump
 | 
			
		||||
 | 
			
		||||
# Folder config file
 | 
			
		||||
[Dd]esktop.ini
 | 
			
		||||
 | 
			
		||||
# Recycle Bin used on file shares
 | 
			
		||||
$RECYCLE.BIN/
 | 
			
		||||
 | 
			
		||||
# Windows Installer files
 | 
			
		||||
*.cab
 | 
			
		||||
*.msi
 | 
			
		||||
*.msix
 | 
			
		||||
*.msm
 | 
			
		||||
*.msp
 | 
			
		||||
 | 
			
		||||
# Windows shortcuts
 | 
			
		||||
*.lnk
 | 
			
		||||
 | 
			
		||||
.vscode/*
 | 
			
		||||
!.vscode/settings.json
 | 
			
		||||
!.vscode/tasks.json
 | 
			
		||||
!.vscode/launch.json
 | 
			
		||||
!.vscode/extensions.json
 | 
			
		||||
!.vscode/*.code-snippets
 | 
			
		||||
!*.code-workspace
 | 
			
		||||
 | 
			
		||||
# Built Visual Studio Code Extensions
 | 
			
		||||
*.vsix
 | 
			
		||||
							
								
								
									
										73
									
								
								to-m4b.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								to-m4b.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
set -x
 | 
			
		||||
set -eufo pipefail
 | 
			
		||||
 | 
			
		||||
# CONSTANTS
 | 
			
		||||
declare -r m4b-tool="nix run github:sandreas/m4b-tool#m4b-tool-libfdk -- "
 | 
			
		||||
declare -r script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 | 
			
		||||
 | 
			
		||||
# VARS
 | 
			
		||||
LEADING_ZEROES=2
 | 
			
		||||
SRC="${SRC:${script_dir}/src}"
 | 
			
		||||
OUT="${OUT:${script_dir}/out}"
 | 
			
		||||
AUTHOR="${AUTHOR:-}"
 | 
			
		||||
NARRATOR="${NARRATOR:-}"
 | 
			
		||||
TITLE="${TITLE:-}"
 | 
			
		||||
YEAR="${YEAR:-}"
 | 
			
		||||
SERIES="${SERIES:-}"
 | 
			
		||||
SERIES_INDEX="${SERIES_INDEX:-}"
 | 
			
		||||
 | 
			
		||||
# FUNCTIONS
 | 
			
		||||
parse-vars() {
 | 
			
		||||
  # TODO implement parsing the directory structure to fill in missing vars and return them
 | 
			
		||||
  # Series structure: ${SRC}/<author>/<series>/Book <part> - <year> - <book> {<narrator>}/
 | 
			
		||||
  # Standalone structure: ${SRC}/<author>/<year> - <book> {<narrator>}/
 | 
			
		||||
  # Return the <part> wihh leading zeros based on the LEADING_ZEROES variable
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get-book-directories() {
 | 
			
		||||
  # TODO implemet getting the book directoris based on the ${SRC} path
 | 
			
		||||
  # find the directories that contains the books files and return them as an array
 | 
			
		||||
  # Example book directory:
 | 
			
		||||
  # /path/to/src/Author/Series/Book Part - Year - Book {Narrator}/
 | 
			
		||||
  # /path/to/src/Author/Year - Book {Narrator}/
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
m4b-merge() {
 | 
			
		||||
  local output_file="${1}"
 | 
			
		||||
  local source_dir="${2}"
 | 
			
		||||
  local author="${3}"
 | 
			
		||||
  local narrator="${4}"
 | 
			
		||||
  local title="${5}"
 | 
			
		||||
  local year="${6}"
 | 
			
		||||
  local series="${7}"
 | 
			
		||||
  local series_index=${8}
 | 
			
		||||
 | 
			
		||||
  mkdir -p "$(dirname "${output_file}")"
 | 
			
		||||
  "${m4b-tool}" \
 | 
			
		||||
    merge \
 | 
			
		||||
      -v \
 | 
			
		||||
      --jobs=6 \
 | 
			
		||||
      --audio-samplerate=44100 \
 | 
			
		||||
      --audio-quality=100 \
 | 
			
		||||
      --writer="${author}" \
 | 
			
		||||
      --artist="${narrator}" \
 | 
			
		||||
      --title="${title}" \
 | 
			
		||||
      --year="${year}" \
 | 
			
		||||
      --album="${series}" \
 | 
			
		||||
      --album-sort="${series_index}" \
 | 
			
		||||
      --output-file="${output_file}/" \
 | 
			
		||||
      -- "${source_dir}"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main() {
 | 
			
		||||
  parse-vars
 | 
			
		||||
  local book_dirs
 | 
			
		||||
  IFS=$'\n' read -r -d '' -a book_dirs < <(get-book-directories && printf '\0')
 | 
			
		||||
  for book_dir in "${book_dirs[@]}"; do
 | 
			
		||||
    local book_output_file="${OUT}/${AUTHOR}/${(SERIES:+${SERIES}/)}${(SERIES:+Book ${SERIES_INDEX} - )}${YEAR} - ${TITLE}.m4b"
 | 
			
		||||
    m4b-merge "${LEADING_ZEROES}" "${book_output_file}" "${book_dir}" "${AUTHOR}" "${NARRATOR}" "${TITLE}" "${YEAR}" "${SERIES}" "${SERIES_INDEX}"
 | 
			
		||||
  done
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
main "$@"
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue