pymedusa / Medusa

Automatic Video Library Manager for TV Shows. It watches for new episodes of your favorite shows, and when they are posted it does its magic.
https://pymedusa.com
GNU General Public License v3.0
1.78k stars 277 forks source link

Automatically Delete Episodes with Equal Quality in Download Folder #4517

Closed SycoPath closed 3 years ago

SycoPath commented 6 years ago

Any chance we can get an option added to the post processor that will allow it to delete the file on an equal match? I keep ending up with leftovers from season packs for episodes I already have and have to periodically clean up my incoming folder from leftovers.

Examples:

2018-07-01 18:41:33 WARNING  Thread_44 :: [212cd1c] /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E01.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E01.1080p.HDTV.h264-SFM.mkv: Processing failed: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:41:33 WARNING  Thread_44 :: [212cd1c] /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E11.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E11.1080p.HDTV.h264-SFM.mkv: Processing failed: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:41:33 WARNING  Thread_44 :: [212cd1c] /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E22.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E22.1080p.HDTV.h264-SFM.mkv: Processing failed: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:41:33 WARNING  Thread_44 :: [212cd1c] /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E03.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E03.1080p.HDTV.h264-SFM.mkv: Processing failed: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:41:33 WARNING  Thread_44 :: [212cd1c] /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E10.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E10.1080p.HDTV.h264-SFM.mkv: Processing failed: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:41:23 WARNING  Thread_44 :: [212cd1c] Processing failed for /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E11.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E11.1080p.HDTV.h264-SFM.mkv: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:40:05 WARNING  Thread_44 :: [212cd1c] Processing failed for /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E01.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E01.1080p.HDTV.h264-SFM.mkv: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:39:55 WARNING  Thread_44 :: [212cd1c] Processing failed for /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E22.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E22.1080p.HDTV.h264-SFM.mkv: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:39:29 WARNING  Thread_44 :: [212cd1c] Processing failed for /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E03.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E03.1080p.HDTV.h264-SFM.mkv: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
2018-07-01 18:39:29 WARNING  Thread_44 :: [212cd1c] Processing failed for /mnt/RAID10/Torrents/Medusa/www.Speed.cd - Stargate.SG-1.S03E10.1080p.HDTV.h264-SFM/Stargate.SG-1.S03E10.1080p.HDTV.h264-SFM.mkv: File exists. Marking it unsafe to replace. Reason: New quality is equal than current Preferred. Ignoring quality
Rouzax commented 6 years ago

You can do this using API import. I just run an API call in my script to post process, there you can mark it a priority

Name Required Description Type Default value Allowed values
failed   Mark download as failed bool False [0, 1]
delete_files   Delete files and folders like auto processing bool False [0, 1]
force_replace   Force already post-processed files to be post-processed again bool False [0, 1]
is_priority   Replace the file even if it exists in a higher quality bool False [0, 1]
path   The path to the folder to post-process string None see desc
return_data   Returns the result of the post-process bool False [0, 1]
process_method   How should valid post-processed files be handled string False [u'copy', u'symlink', u'hardlink', u'move', u'reflink']
type   The type of post-process being requested string auto [u'auto', u'manual']
SycoPath commented 6 years ago

Thanks for the reply, sadly I am not a great coder, and I am not using a script to post process, just the default webui. Looking at those API calls though, how would you even do this? There is no API call to compare a file's quality to an existing file in the database? I don't want to mark it for force_replace since it's probably equal or lower quality. I don't want to mark it as failed since that will cause it to re-download again. Am I missing something? I thought about writing a cron job that reads the medusa log every 30 minutes or so and just deletes any file the log mentions "Equal Than Preferred" but this seems extremely messy and not very secure. This seems like something that should be a checkbox integrated into the UI for Medusa. If I had the skills, I'd submit some code, and I wouldn't be wasting everyone's time putting up a feature request. Any chance you can provide an example script that will do this? or at least enough to get me started and I'll build from there?

Rouzax commented 6 years ago

It would be 'force_replace' that will mark it to overwrite the same quality if exists. The 'is_priority' will overwrite no matter what the current quality or size is.

SycoPath commented 6 years ago

Right, but doesn't force_replace overwrite it even if it's lower quality? So let's say that Medusa can't find episode 12 as a single download but Medusa finds a season pack that contains episode 12 at 720P but all the rest of the episodes have already been downloaded at 1080P. This would owerwrite the entire season with 720P and cause a re-download of every episode except 12 at 1080p at the next backlog search, assuming it even can find a 1080P download to complete. Some of the things I have are years old and the original download is long dead.

p0psicles commented 6 years ago

Im curious why it attempts to snatch a quality thats the same?

SycoPath commented 6 years ago

It usually comes from a show that an episode or two can't be found as a single episode download, so it fails back to season packs. Medusa pulls the single episode it needed from the pack and the rest gets abandoned in the downloads folder. The problem arises when lets say 24/26 episodes are already downloaded in 4k or 1080p, but for some reason, 25 and 26 are only found as 720 in a season pack. Medusa downloads the season pack to fill the missing episodes 25 and 26, then leaves 1-24 sitting in the download folder. Now, obviously I don't want to force replace or mark as priority a bunch of 720p episodes when 1080p or 4k already exists, so it just ends up sitting there until I go delete it.

SycoPath commented 6 years ago

I just ran into another case where doing this with force_replace would be bad. If there is a download from a pack that episodes are a smaller file size. Medusa downloads a season pack of 1080p when a show is only missing a few episodes. Most of the existing episodes are say 3-5GB each and 1080p, but this pack it downloaded to fill the gaps just happens to contain 1-2GB episodes that are also 1080p. So now with force_replace it's going to push the lower bitrate/quality files over the existing higher bitrate/quality files. I don't fully understand all the code, but looking at the source it seems like it would be much easier to trigger a delete off of the post processor when it would generate the message for the log about equal or lower quality. Just add a branch that deletes the duplicate lower quality file if a UI setting is ticked and write a different log message, right? Implementing this function through external post-processing scripts seems like a huge amount of work. Two API calls would need to be created from scratch. One API call to compare an episode to an existing episode in the database and another API call to actually delete the file. That's why I figured the best route was a feature request. I mean, I guess you could do this by creating an external postprocessing script that did it's own comparison to Medusa's log instead of making a cron job, but that would be a seriously complicated script well beyond me. I suppose this could be handled at the searcher level by passing arguments to the external client to only partially download a pack, but that seems even more messy and much more work than creating API calls. This would have the benefit of conserving bandwidth I suppose, but coding this to work with the multitude of clients out there would be enough to be it's own github project.

medariox commented 3 years ago

This won't happen anymore since packs need to have at least 50% wanted to be downloaded.