sandreas / tone

tone is a cross platform audio tagger and metadata editor to dump and modify metadata for a wide variety of formats, including mp3, m4b, flac and more. It has no dependencies and can be downloaded as single binary for Windows, macOS, Linux and other common platforms.
https://pilabor.com
Apache License 2.0
418 stars 17 forks source link

Null reference exception using dump --format json on DRM protected file #25

Closed tmr0861 closed 2 years ago

tmr0861 commented 2 years ago

Trying to extract the chapters from a DRM protected file and write to a file so I can write them back into the non-DRM protected version. I can dump the chapters using the standard format, and manually edit this into a standard chapter format, but this is time consuming.

Trying this command so I can automate all files: tone dump drmfilename.m4b --include-property chapters --format json > chapters.json

Then write back with this command: tone tag nodrmfilename.m4b --meta-tone-json-file="chapters.json" --auto-import="tonejson"

When I try to dump the chapters with the json format I get a null reference exception. Debugging the application, turns out that track.ChannelsArragement is null on these files. So, the SerializeAsync method fails with the null reference exception on this line:

Channels = new { Count = track.ChannelsArrangement.NbChannels, Description = track.ChannelsArrangement.Description },

I tried it with this line commented out and I was able to write the file fine without the Channels info and the nodrm file kept its existing Channels info.

Great tool btw!

sandreas commented 2 years ago

Hey thanks for this detailed report.

Trying to extract the chapters from a DRM protected file and write to a file so I can write them back into the non-DRM protected version.

Interesting approach :-)

When I try to dump the chapters with the json format I get a null reference exception. Debugging the application, turns out that track.ChannelsArragement is null on these files.

Ah I see, I did not know that this is even a possibility. Unfortunately, due to this exception it is not possible to workaround this issue by using tone.json format.

However, it would have been possible to use ffmetadata or ChptFmtNativeformat to overcome this, if there was a feature to auto-import / export and vice versa these :-/

 # no import possible
tone dump --format=ffmetadata 'audiobook.m4b' --include-property=chapters

# no export / dump possible
tone tag --auto-import=chapters 'audiobook.m4b'

So in a series of unfortunate events, I think you have to wait until this is fixed in the next release - I think I'll fix this pretty quick, but the next release will take some time.

Can you build a latest code version on your own?

Seems that I have to fix / add a few things here:

tmr0861 commented 2 years ago

Trying to extract the chapters from a DRM protected file and write to a file so I can write them back into the non-DRM protected version.

Interesting approach :-)

Well, it would have been better if I had found a utility that would just strip the encryption so I could play the audiobooks on non-iTunes players and not lose the chapters. :-)

Can you build a latest code version on your own?

Yes, I was able to comment out the offending line, build and run from within Visual Studio. I didn't spend a lot of time, but I would have to figure out how you created the portable exe version.

So in a series of unfortunate events, I think you have to wait until this is fixed in the next release - I think I'll fix this pretty quick, but the next release will take some time.

I'm not in a huge rush. I can wait until you get it fixed, and then I'll work on updating my library. This is a winter project anyways. :-)

sandreas commented 2 years ago

I didn't spend a lot of time, but I would have to figure out how you created the portable exe version.

This is easy, take a look at https://github.com/sandreas/tone/blob/main/tone/build.sh (you have to adjust the runtime id) or simply fork and run ./release.sh 0.1.1, then github will do the rest for you.

I'm not in a huge rush. I can wait until you get it fixed, and then I'll work on updating my library. This is a winter project anyways. :-)

Great, then I can take the time to fix this and some other things. Thank you for the quick feedback.

sandreas commented 2 years ago

Ok, should be fixed in the latest commits - targeted for v0.1.1. You can now also use

tone dump --format=ChptFmtNative my-file.m4b

to get a chapters.txt only dump, which then can be used for --auto-import=chapters

I would really appreciate feedback if this fixes it for you.

tmr0861 commented 2 years ago

Works like a charm! Either format will do what I need! Thanks for fixing it so quickly.