|
|
@ -26,6 +26,7 @@ Opus Audiobook profile |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
import os |
|
|
|
|
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
from ..profile import * |
|
|
|
from ..profile import * |
|
|
|
|
|
|
|
|
|
|
@ -34,7 +35,7 @@ abdefines = dict( |
|
|
|
bitrate = "Use custom target bitrate", |
|
|
|
bitrate = "Use custom target bitrate", |
|
|
|
stereo = "Use 2 channels (Ignored for mono source streams)", |
|
|
|
stereo = "Use 2 channels (Ignored for mono source streams)", |
|
|
|
fancy = "Use higher bitrates (48k mono/64k stereo)", |
|
|
|
fancy = "Use higher bitrates (48k mono/64k stereo)", |
|
|
|
ogg = "Use the .ogg file extension (Currently required on Android)" |
|
|
|
ogg = "Use the .ogg file extension (Currently required on Android)", |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def apply_stream(stream, defines): |
|
|
|
def apply_stream(stream, defines): |
|
|
@ -66,10 +67,26 @@ def apply_stream(stream, defines): |
|
|
|
stream.bitrate = min(stream.bitrate, stream.source.bitrate) |
|
|
|
stream.bitrate = min(stream.bitrate, stream.source.bitrate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
metadefines = dict( |
|
|
|
|
|
|
|
title="Name of the book", |
|
|
|
|
|
|
|
series="Series the book belongs to", |
|
|
|
|
|
|
|
author="Name of the book's author", |
|
|
|
|
|
|
|
performer="Name of the audiobook's reader/narrator", |
|
|
|
|
|
|
|
genre="Name of the genre. Default is Audiobook", |
|
|
|
|
|
|
|
publisher="Name of the recording company", |
|
|
|
|
|
|
|
language="Language", |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_metadata(ob, defines): |
|
|
|
|
|
|
|
ob.apply_meta(defines, "language", "author", "performer", publisher="organization", title="album") |
|
|
|
|
|
|
|
ob.meta(genre=defines.get("genre", "Audiobook")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@profile |
|
|
|
@profile |
|
|
|
@description("Encode Opus Audiobook") |
|
|
|
@description("Encode Opus Audiobook") |
|
|
|
@output(container="ogg", ext="opus") |
|
|
|
@output(container="ogg", ext="opus") |
|
|
|
@defines(**abdefines) |
|
|
|
@defines(**abdefines, **metadefines) |
|
|
|
@singleaudio |
|
|
|
@singleaudio |
|
|
|
def audiobook(task, stream, defines): |
|
|
|
def audiobook(task, stream, defines): |
|
|
|
if "ogg" in defines: |
|
|
|
if "ogg" in defines: |
|
|
@ -77,6 +94,8 @@ def audiobook(task, stream, defines): |
|
|
|
|
|
|
|
|
|
|
|
apply_stream(task.map_stream(stream), defines) |
|
|
|
apply_stream(task.map_stream(stream), defines) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apply_metadata(task.output, defines) |
|
|
|
|
|
|
|
|
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -87,7 +106,7 @@ def audiobook(task, stream, defines): |
|
|
|
@features(no_single_output=True) |
|
|
|
@features(no_single_output=True) |
|
|
|
@defines(ignore_ends="Ignore chapter end marks and continue until next chapter starts", |
|
|
|
@defines(ignore_ends="Ignore chapter end marks and continue until next chapter starts", |
|
|
|
chapter_only_names="Don't include the input filename in the output filename", |
|
|
|
chapter_only_names="Don't include the input filename in the output filename", |
|
|
|
**abdefines) |
|
|
|
**abdefines, **metadefines) |
|
|
|
@singleaudio |
|
|
|
@singleaudio |
|
|
|
def from_chapters(task, stream, defines): |
|
|
|
def from_chapters(task, stream, defines): |
|
|
|
# Read chapters from input |
|
|
|
# Read chapters from input |
|
|
@ -126,9 +145,77 @@ def from_chapters(task, stream, defines): |
|
|
|
|
|
|
|
|
|
|
|
apply_stream(out.map_stream(stream), defines) |
|
|
|
apply_stream(out.map_stream(stream), defines) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apply_metadata(out, defines) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@profile |
|
|
|
|
|
|
|
@description("Split & Encode Opus Audiobook from Audible AAX") |
|
|
|
|
|
|
|
@output(container="ogg", ext="opus") |
|
|
|
|
|
|
|
@features(no_single_output=True) |
|
|
|
|
|
|
|
@defines(key="Audible activation_bytes (required)", |
|
|
|
|
|
|
|
cover_file="Filename for the extracted cover (Default: <album>.jpg)", |
|
|
|
|
|
|
|
#dont_embed_cover="Don't try to embed the cover", |
|
|
|
|
|
|
|
artist_tag="Specify the tag to store the artist name (Default: author)", |
|
|
|
|
|
|
|
performer="Add a performer tag", |
|
|
|
|
|
|
|
#album="Override book title", |
|
|
|
|
|
|
|
**abdefines) |
|
|
|
|
|
|
|
def audible(task, defines): |
|
|
|
|
|
|
|
if len(task.inputs) != 1: |
|
|
|
|
|
|
|
print("audiobook.audible profile must be applied to a single AAX file!") |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input = task.inputs[0] |
|
|
|
|
|
|
|
if "key" not in defines: |
|
|
|
|
|
|
|
if input.metadata["major_brand"].lower() == "aax": |
|
|
|
|
|
|
|
print("Audible activation_bytes must be specified in the 'key' define!") |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
input.set(activation_bytes=defines["key"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
audio = input.audio_streams[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Extract cover |
|
|
|
|
|
|
|
cover = input.video_streams[0] |
|
|
|
|
|
|
|
cover_file = defines.get("cover_file", True) |
|
|
|
|
|
|
|
if cover_file != "": |
|
|
|
|
|
|
|
if cover_file is True: |
|
|
|
|
|
|
|
cover_file = input.album + ".jpg" |
|
|
|
|
|
|
|
elif "." not in cover_file: |
|
|
|
|
|
|
|
cover_file += ".jpg" |
|
|
|
|
|
|
|
cof = task.add_output(os.path.join(task.output_directory, cover_file)) |
|
|
|
|
|
|
|
cof.map_stream(cover).set(c="copy") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ext = "ogg" if "ogg" in defines else "opus" |
|
|
|
|
|
|
|
chaps = len(input.chapters) |
|
|
|
|
|
|
|
ct_fmt = "%%s %%0%dd - %%s.%s" % (math.ceil(math.log10(chaps)), ext) |
|
|
|
|
|
|
|
add_meta = {defines.get("artist_tag", "author"): input.artist} |
|
|
|
|
|
|
|
#album = defines.get("album", input.album) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for chapter in input.chapters: |
|
|
|
|
|
|
|
no = chapter.index + 1 |
|
|
|
|
|
|
|
title = " - ".join((input.album, chapter.title)) |
|
|
|
|
|
|
|
filename = os.path.join(task.output_directory, ct_fmt % (input.album, no, chapter.title)) |
|
|
|
|
|
|
|
out = task.add_output(filename) |
|
|
|
|
|
|
|
out.set(ss = chapter.start_time, |
|
|
|
|
|
|
|
to = chapter.end_time, |
|
|
|
|
|
|
|
map_metadata = "-1", |
|
|
|
|
|
|
|
reorder_streams = False) |
|
|
|
|
|
|
|
out.meta(title = title, |
|
|
|
|
|
|
|
album = input.title, |
|
|
|
|
|
|
|
tracknumber = "%d/%d" % (no, chaps), |
|
|
|
|
|
|
|
**add_meta) |
|
|
|
|
|
|
|
out.apply_meta(input.metadata, "copyright", "genre", "date", comment="description") |
|
|
|
|
|
|
|
out.apply_meta(defines, "performer", publisher="organization") |
|
|
|
|
|
|
|
apply_stream(out.map_stream(audio), defines) |
|
|
|
|
|
|
|
#if not "dont_embed_cover" in defines: |
|
|
|
|
|
|
|
# out.map_stream(cover) # Not sure how to make ffmpeg add covers to ogg |
|
|
|
|
|
|
|
|
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@profile |
|
|
|
@profile |
|
|
|
@description("Split into uniform pieces & Encode Opus Audiobook") |
|
|
|
@description("Split into uniform pieces & Encode Opus Audiobook") |
|
|
|
@output(container="ogg", ext="opus") |
|
|
|
@output(container="ogg", ext="opus") |
|
|
|