TheCaptain989 / radarr-striptracks

A Docker Mod to Radarr/Sonarr to automatically strip out unwanted audio and subtitle tracks
https://hub.docker.com/r/thecaptain989/radarr-striptracks
GNU General Public License v3.0
20 stars 1 forks source link

don't do anything if nothing gets removed #49

Closed Benni-chan closed 11 months ago

Benni-chan commented 1 year ago

it would be great, if the script would skip the mkvmerge step (and following steps) if nothing get's removed. currently, even if nothing gets removed, a new file is created and the old file is moved to the recycle bin.

this takes space and time

TheCaptain989 commented 1 year ago

Thanks for the feedback.

I had thought about this issue when I was writing the script, but decided against it for two reasons:

  1. The source file may not be an MKV. The resulting file will always be an MKV, regardless of source file type, which is something I wanted because of the features of the container (tagging, metadata, etc.)
  2. The MKV Title attribute is set to its canonical name. This is an aesthetic that is important to me because the Title will show up in some programs like VNC or Kodi in place of the filename.

In my experience, the time factor is not really important, and you can have Radarr or Sonarr themselves manage the Recycle Bin space, so it's never been a concern of mine.

If you want to change the behavior yourself, you could insert the following code at line 761 (untested):

  if (length(AudioCommand)+length(SubsCommand)+VidCnt == NoTr) { print "Info|No tracks would be removed! Exiting."; exit }
CozMedic commented 1 year ago

just to throw another perspective into the mix: I've got all my media on an UNRAID server. Like most UNRAID users, I'm using a cache SSD (a 1TB SATA in my case) to initially write my media, which is then moved to the array (a whole 18TB of SATA HDDs) on a daily basis.

When the cache drive fills up, Sonarr/Radarr start throwing fits until I manually invoke the mover. So if I'm running a batch job, or just doing an import, all media will end up taking double space. This happens even if nothing was removed or if the file already lives on the array. (Batch jobs currently run, re-writing all files back to the SSD, until no more files can be written to the SSD then crash, for example.)

Having the script skip the mkvmerge step when there's nothing to remove could be a real space-saver for users with a similar setup. Just something to consider. I'll use your suggested workaround for now.

TheCaptain989 commented 1 year ago

Thanks for the color. I hadn't thought of your scenario, and I understand. I still don't think I'll change the default behavior, but it may make sense to add a command line switch, like --save-space or something. If I have time I'll work on implementing that. In the meantime, let me know how the quick fix works for you.

CozMedic commented 1 year ago

If you don't mind, is this how you intended the fix to be implemented, or did I misinterpret what you meant? This is my striptracks.sh lines 759-763:

  if (length(SubsRmvLog) != 0) print "Info|Removed subtitles tracks: " join(SubsRmvLog, ",")
  print "Info|Kept tracks: "length(AudioCommand)+length(SubsCommand)+VidCnt" (audio: "length(AudioCommand)", subtitles: "length(SubsCommand)")"
  if (length(AudioCommand)+length(SubsCommand)+VidCnt == NoTr) { print "Info|No tracks would be removed! Exiting."; exit }
  if (length(AudioCommand) == 0) {
    # This should never happen, but belt and suspenders

I only ask because I noticed my striptracks.txt logfile was last written to yesterday, despite having done imports a little bit ago. But I believe it's working as intended due to seeing 2023-7-8 19:41:14.5|[737]Info|No tracks would be removed! Exiting. in the most recent log. Perhaps it's unrelated.

TheCaptain989 commented 1 year ago

If you don't mind, is this how you intended the fix to be implemented, or did I misinterpret what you meant?

Your snippet looks correct, as does your log file output. To see if its working, in the log check that before the No tracks would be removed! entry that there are Original tracks: # and Kept tracks: # entries that have the same count. That's basically what the added line is comparing. I would also think that immediately after would be an Unable to locate or invalid remuxed file: <name> entry in the log, but since I haven't run this myself I can't be sure.

CozMedic commented 1 year ago

I would also think that immediately after would be an Unable to locate or invalid remuxed file: entry in the log, but since I haven't run this myself I can't be sure.

Lol sure is. I was going to include it but thought it may have something to do with playing around with Tdarr.

2023-7-9 17:22:27.0|[2433]Info|Sonarr event: Download, Video: /data/tvshows/File_Name_Omitted.mkv, Size: 1.348G, AudioKeep: :eng:jpn:und, SubsKeep: :eng
2023-7-9 17:22:36.2|[2433]Info|Original tracks: 2 (audio: 1, subtitles: 0)
2023-7-9 17:22:36.2|[2433]Info|Keeping audio track 1: eng (AAC)
2023-7-9 17:22:36.2|[2433]Info|Kept tracks: 2 (audio: 1, subtitles: 0)
2023-7-9 17:22:36.2|[2433]Info|No tracks would be removed! Exiting.
2023-7-9 17:22:36.2|[2433]Error|Unable to locate or invalid remuxed file: "/data/tvshows/File_Name_Omitted.tmp".  Halting.

If it matters at all, I'm using the provided 'striptracks-eng-jpn.sh' wrapper script only on imported & upgraded series with an anime tag.

Benni-chan commented 1 year ago

works for me, too. thanks for the snipped. (I'm also using unraid and my ssd was filling up fast when processing larger season packs)

would be nice to have a command line switch :) and maybe hide the error msg about not finding the remuxed file.

TheCaptain989 commented 1 year ago

If it matters at all, I'm using the provided 'striptracks-eng-jpn.sh' wrapper script only on imported & upgraded series with an anime tag.

Glad it is working for you. The wrapper scripts just call the main script with different options, and since you modified the main script all wrappers will work the same way now.

TheCaptain989 commented 1 year ago

would be nice to have a command line switch :) and maybe hide the error msg about not finding the remuxed file.

I hear ya. As time permits, I'll work on implementing that. I have some other things I want to change about the script anyway based on lessons learned from another project and it won't be too hard to build in a new switch... It may take a little time, though.

TheCaptain989 commented 11 months ago

I figured out how to do this and testing has gone well. I made an executive decision to still proceed with the remux if the source file is not an MKV, even if no tracks are removed. Can you live with that?

I'll probably push a development build with this feature in the next few days.

CozMedic commented 11 months ago

Sounds great! Thank you for continuing to consider our use-case. I'll keep an eye out and look forward to testing it when I see it.

TheCaptain989 commented 11 months ago

Just a quick update. I've got this issue fully working the way I want, but I've hit a slight roadblock related to issue #50 that has slowed me down.

TheCaptain989 commented 11 months ago

I just created a new branch and uploaded the new script.

I'm still testing myself, but if you are brave, you can pull this new version by setting your DOCKER_MODS variable to thecaptain989/radarr-striptracks:latest. Testing feedback would be welcomed.

The new version addressed this issue and has a lot of changes under the hood.