Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing Nero M4A chapters #7159

Merged

Conversation

IsAvaible
Copy link
Contributor

@IsAvaible IsAvaible commented May 2, 2024

Description

This pull request adds a simple M4A parser to detect and read Nero type chapters. I do not intend to implement parsing QuickTime type chapters, as it requires a more elaborate process.

Most M4A editors (such as FFMPEG) embed both types of chapters in the media file, so nonetheless a high percentage of M4A files with chapters should be supported after this pull request is merged.

As the previous test file only embedded QT chapters, I have added a new test file with Nero type chapters (nero-chapters.m4a).

partially fixes #4311

This commit adds testcases that verify whether the application correctly parses Nero type M4A chapters.
Copy link
Member

@ByteHamster ByteHamster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is great! Looks pretty good. I have added a few comments below :)

This commit introduces a mechanism to keep track of the remaining size of each part while searching for an atom in the M4A file. This is done to ensure that we do not exceed the size of the current part while searching for the next part in the atom name. If the remaining size is exhausted before finding the next part, the search for the atom is aborted and a message is logged. This change improves the robustness of the atom search process and helps prevent potential errors due to exceeding part sizes (e.g. reading the whole file even though the atom is not present).
This commit modifies the method of reading M4A atoms in the M4AChapterReader class. Previously, the method used a combination of InputStream.read and manual byte array handling. This commit replaces that with the use of IOUtils.readFully from Apache Commons IO. This method ensures that the entire atom is read into the buffer, even if it requires multiple read operations. This change simplifies the code and makes it more robust against situations where a single read operation might not read the entire atom.
Additionally the method does not return -1 anymore when failing to find the atom but instead throws an IOException.
This commit introduces a functionality to validate if the provided file is an M4A file. This is achieved by checking the signature of the file. The signature of an M4A file is a specific sequence of bytes at the beginning of the file. If the signature does not match the expected M4A signature, an IOException is thrown indicating that the file is not an M4A file. This validation is crucial to ensure that the file can be correctly processed as an M4A file in subsequent steps.
Refactored the findAtom function in the M4AChapterReader class to improve performance. The function now uses a more efficient method to search for atoms in the M4A file, reducing the overall time complexity. This optimization should lead to faster parsing of M4A files, especially for larger files. The changes do not affect the functionality of the function, and all existing tests pass successfully.
Replaced the test file with a shorter copy-right free one.
Fixed a bug where the find atom function returned the wrong size (8-bytes too large).
@IsAvaible
Copy link
Contributor Author

@ByteHamster I have made some changes to the pull request, trying to keep the commits atomic. I think you should get a good overview of the changes by stepping through each commit and reading the commit message.

@ByteHamster ByteHamster merged commit ba14510 into AntennaPod:develop May 5, 2024
6 checks passed
@ByteHamster
Copy link
Member

Thanks! Will be released in 3.5.x

@40ZqTYY4ag3tAO4hdlxR1
Copy link

@IsAvaible Vielen Dank 🙂

@IsAvaible
Copy link
Contributor Author

Thanks! Will be released in 3.5.x

Great, glad to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for parsing m4a chapters
3 participants