m4b-tool icon indicating copy to clipboard operation
m4b-tool copied to clipboard

PHP Error when splitting by chapter

Open Jimmni opened this issue 4 years ago • 17 comments
trafficstars

When splitting by chapter I get the following error. It might well be an issue with the version of PHP installed, I really wouldn't know.

The error has a lot of backticks so it's messing up the markdown and I can't figure out how to properly escape them all. You should get the idea though.

PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in phar:///usr/local/Cellar/m4b-tool/0.4.2/bin/m4b-tool/vendor/twig/twig/src/Node/Node.php on line 43

Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in phar:///usr/local/Cellar/m4b-tool/0.4.2/bin/m4b-tool/vendor/twig/twig/src/Node/Node.php on line 43 an error occured, that has not been caught: Array ( [type] => 64 [message] => Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` [file] => phar:///usr/local/Cellar/m4b-tool/0.4.2/bin/m4b-tool/vendor/twig/twig/src/Node/Node.php [line] => 43

Jimmni avatar Aug 02 '21 20:08 Jimmni

What is your php version, and what was the command you ran to produce this error?

djdembeck avatar Aug 02 '21 21:08 djdembeck

php -v returns:

PHP 8.0.2 (cli) (built: Feb 4 2021 18:57:55) ( NTS )

Copyright (c) The PHP Group

Zend Engine v4.0.2, Copyright (c) Zend Technologies with Zend OPcache v8.0.2, Copyright (c), by Zend Technologies

The command I run is:

split [filename]

It used to work until one day it didn't. I have no idea if I updated php in between.

Jimmni avatar Aug 02 '21 21:08 Jimmni

I'll add that it's macOS 11.4, installed via brew as per the instructions.

Jimmni avatar Aug 02 '21 21:08 Jimmni

The version would be interesting. Are you using latest pre-release or 0.4.2?

sandreas avatar Aug 02 '21 21:08 sandreas

0.4.2 - I haven't ever tried to install a pre-release via brew. I'll look into it.

Edit: Just saw the install instructions. I'll do that and report back.

Jimmni avatar Aug 02 '21 21:08 Jimmni

There are instructions for that in the Pre-Release notes. If it does not work (might be), I'll take a look.

sandreas avatar Aug 02 '21 21:08 sandreas

Assuming I installed correctly (got no errors, but "m4b-tool version" returns " Command "version" is not defined."):

No errors come up now, but it doesn't function as expected.

The split now fills my home directory with files named with three letters and no extensions (xqg, xqk etc.), rather than to the created folder in the same directory it would before.

Jimmni avatar Aug 02 '21 21:08 Jimmni

I would need the whole command line you ran... (e.g. m4b-tool split ...)

sandreas avatar Aug 02 '21 22:08 sandreas

I used:

m4b-tool split --audio-format m4a --audio-bitrate 128k --audio-channels 2 --audio-samplerate 22050 '/Users/UserName/Desktop/Book Name.m4b'

I just ran it again and it's doing something a little different. This time it split the file into 71 valid m4b files, in the expected directory (/Desktop/Book Name_splitted). However, the book has 11 chapters. The outputted chapters.txt file shows the correct chapters and chapter markings. It pulled the description and cover fine too.

Edit: My mistake, the chapters.txt was from a previous attempt with the last version. The prerelease isn't generating a chapters.txt that I can see.

Maybe it's doing silence detection instead of chapters even though I didn't ask it to?

Getting closer :D

Jimmni avatar Aug 02 '21 22:08 Jimmni

I will try to reproduce this... thanks for detailed reporting.

You could try to use --use-existing-chapters for split (see docs)

sandreas avatar Aug 02 '21 22:08 sandreas

Apologies if I'm doing this wrong.

With the command:

m4b-tool split --audio-format m4a --use-existing-chapters --audio-bitrate 128k --audio-channels 2 --audio-samplerate 22050 '/Users/UserName/Desktop/Book Name.m4b'

I get:

The "--use-existing-chapters" option does not exist.

split [--logfile [LOGFILE]] [--debug] [-f|--force] [--tmp-dir [TMP-DIR]] [--no-cleanup] [--no-cache] [--ffmpeg-threads [FFMPEG-THREADS]] [--platform-charset [PLATFORM-CHARSET]] [--ffmpeg-param [FFMPEG-PARAM]] [-a|--silence-min-length [SILENCE-MIN-LENGTH]] [-b|--silence-max-length [SILENCE-MAX-LENGTH]] [--max-chapter-length [MAX-CHAPTER-LENGTH]] [--name [NAME]] [--sortname [SORTNAME]] [--album [ALBUM]] [--sortalbum [SORTALBUM]] [--artist [ARTIST]] [--sortartist [SORTARTIST]] [--genre [GENRE]] [--writer [WRITER]] [--albumartist [ALBUMARTIST]] [--year [YEAR]] [--description [DESCRIPTION]] [--longdesc [LONGDESC]] [--comment [COMMENT]] [--copyright [COPYRIGHT]] [--encoded-by [ENCODED-BY]] [--grouping [GROUPING]] [--purchase-date [PURCHASE-DATE]] [--encoder [ENCODER]] [--cover [COVER]] [--skip-cover-if-exists] [--skip-cover] [--series [SERIES]] [--series-part [SERIES-PART]] [--remove [REMOVE]] [--ignore-source-tags] [--prefer-metadata-tags] [--audio-format [AUDIO-FORMAT]] [--audio-extension [AUDIO-EXTENSION]] [--audio-channels [AUDIO-CHANNELS]] [--audio-bitrate [AUDIO-BITRATE]] [--audio-samplerate [AUDIO-SAMPLERATE]] [--audio-codec [AUDIO-CODEC]] [--audio-quality [AUDIO-QUALITY]] [--audio-profile [AUDIO-PROFILE]] [--adjust-for-ipod] [--use-nero-chapter-format] [--fix-mime-type] [--no-conversion] [--trim-silence] [--add-silence [ADD-SILENCE]] [-o|--output-dir [OUTPUT-DIR]] [-p|--filename-template [FILENAME-TEMPLATE]] [--use-existing-chapters-file] [--reindex-chapters] [--fixed-length [FIXED-LENGTH]] [--chapters-filename [CHAPTERS-FILENAME]] [--by-silence] [--]

Jimmni avatar Aug 02 '21 22:08 Jimmni

I also note that it's failing to extract the cover, saying perhaps there is none. There definitely is, though, and the old (0.4.2) version would extract the cover from the same file with no issue.

This isn't an issue for me as I don't need the cover extracted, but I thought I'd mention in case it helps you reproduce/pin down.

Jimmni avatar Aug 02 '21 22:08 Jimmni

I used the chapter.txt file generated by the previous version and the "--use-existing-chapters-file" and "--chapters-filename" commands and it split just fine.

Sadly not a viable workaround in general though as the new version doesn't generaten the chapters.txt, and I'm guessing if it did it wouldn't need my help to use it :D

Thanks for looking into this and huge thanks for m4b-tool in general - I've used it so many times and hope to use it many more!

Jimmni avatar Aug 02 '21 22:08 Jimmni

m4b-tool meta --export-all exports all data of the m4b-file in the latest pre-release (also cover, chapters, etc.)

I'll take a look, whats wrong with splitting and leave the issue open.

sandreas avatar Aug 03 '21 06:08 sandreas

Hi, also had the same PHP error message. But I'm using the Docker image built from repo code. In the container, php is version 7.4.22. Note that despite the warning I get mp3's created ok. m4b-tool version:

m4b-tool v.0.4.2

FYI I built the image as follows:

git clone https://github.com/sandreas/m4b-tool.git
cd m4b-tool
sudo docker build . -t m4b-tool
alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt m4b-tool'

(Forget where these commands come from...) To get the PHP version:

docker run -it --rm --entrypoint=/bin/sh -u $(id -u):$(id -g) -v "$(pwd)":/mnt m4b-tool

Then php -v.

BTW this is all on latest Clear Linux 34930. Please don't hate me.

My commands for splitting:

IFS=$(echo -en "\n\b"); \
for b in $(find . -name "*.m4b" -print); do
m4b-tool split --audio-format mp3 $b
done

(I have a lot to split.)

My error is:

an error occured, that has not been caught:
Array
(
    [type] => 8192
    [message] => Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`
    [file] => phar:///usr/local/bin/m4b-tool/vendor/twig/twig/src/Node/Node.php
    [line] => 43
)

ghost avatar Aug 06 '21 17:08 ghost

install latest twig version (3.3.2) and build from source to fix this error

ReallyNotARussianSpy avatar Aug 10 '21 17:08 ReallyNotARussianSpy

@sreed101 I'll fix this soon, thanks for helping out.

sandreas avatar Aug 10 '21 20:08 sandreas