Processing media file after download but before import

Hi, I wrote an app that will process media files so that they behave well in my various media players, and I would like Sonarr to call this app, after download, but before importing the media file.

With process, I mean I remux or re-encode to H264 MKV (so that I can direct play on my playback devices), I set unknown language tracks to English (so that subtitle handling works correctly), I remove any subtitle or audio tracks other than English (to save space), etc. Today my app listens for file change notifications in the output folder, and then processes modified files.

Because I modify the file after it has been imported into Sonarr, and my media library, the media details in Sonarr are not accurate, and I need to dance around in-use files, e.g. an MP4 file will be converted to a MKV, or a MPEG2 video stream will be converted to H264.

What I’d like to do is as follows:

  1. File is successfully downloaded from downloader
  2. File is moved to a staging area
  3. My script is called with the input file name
  4. I process the file, this may change the extension, and it may change the media contents
  5. I set the new output file name (maybe environment variable, or maybe staging folder with whatever file is left in folder)
  6. The file is now processed and imported

I did try to use completed download handling in my downloader, but I get a directory, and I will and up doing similar cleanup as Sonarr to files in the folder, I could make it work, but much cleaner if I can get a shot at the file in Sonarr.

I see an open request for this type of handling, but other than waiting, is there another way to do this today?

Thx

I do this now but it’s not through Sonarr. I use a combination of tools and the Drone Factory setting in Sonarr which has me worried because that is suppose to be depricated. I like to make sure all my files have AC3 sound and are in mp4 containers so I built a script to process the files before they are added into my collection.

Here is my process:

  1. Sonarr finds show and adds to bittorrent client with tag “tv-raw”
  2. Bittorrent client removes shows after share ratio limit is reached.
  3. FileJuggler copy’s raw video file to “tv-toConvert” folder
  4. FileJuggler monitors folder and runs script against files in “tv-toConvert” folder. Output of script is put into “tv-ready” folder which is set as my Sonarr Drone Factory folder
  5. Sonarr scans drone factory folders and moves properly formatted (audio/video) file into main TV folder

I would like to move away from the Drone Factory but I am unsure as to how to inject my conversion process. PM if you want to discuss specifics.

I am using Sonarr with Google file stream to import my files into my Plex Cloud server. this is why I needed to do my file processing post download but pre-import as it would not make sense to grab a file, upload it, download it, process it, then upload it again. I finally managed to get this to work through some scripting without having to rely on the Drone Factory.

Here is my process:

  1. Sonarr finds show and adds to bittorrent client
  2. When download is complete, client executes a batch script that pauses torrent to unlock files, then moves all possible video files to a scratch folder to be processed (this is to avoid Sonarr grabbing them first)
  3. batch script then optimizes the video files to my specifications and moves the originals to a temporary postprocess holding folder.
  4. once all video files are processed, the new files are moved into the original download folder.
  5. Sonarr detects the video files and processes the import
  6. batch script waits for 3 hours (full seasons sometimes take a long time to import) then deletes new files, moves original files back, and resumes torrent.
  7. when seed ratio reached, Sonarr automatically removes torrent

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.