delete srt if no mp4

English Support for Syncovery on Linux etc.
Post Reply
turbalf
Posts: 6
Joined: Tue Nov 23, 2021 11:08 pm

delete srt if no mp4

Post by turbalf »

Hi,
I use syncovery with my plex database, to remove empty folders as plex deletes files but not folders.
But plex don't delete srt, so sometimes I deleted the mp4 but there is a srt file left in the folder, preventing syncovery to delete it, so I have the question :
Is there a way to get syncovery to delete srt files only if there is no mp4 file in the same folder ?
Thanks !

tobias
Posts: 1605
Joined: Tue Mar 31, 2020 7:37 pm

Re: delete srt if no mp4

Post by tobias »

Hello,
yes it's possible. The exact settings depend on how your profile is set up. For example, is it a one-way or two-way job? Where are you copying files from and to? Do you use Exact Mirror or SmartTracking?

turbalf
Posts: 6
Joined: Tue Nov 23, 2021 11:08 pm

Re: delete srt if no mp4

Post by turbalf »

Hello,
It's a one way sync, I use an empty folder with exact mirror left to right, and I use filter like file age etc to set witch files will be deleted or not.
It works very well for other jobs.
But now I have a folder with all my movies and some with srt subtitles.
When I watch a movie, I delete it with plex, but the srt file remains, so I'd like a way to delete srt file only when a mp4 file with the same name don't exist.
thanks !

tobias
Posts: 1605
Joined: Tue Mar 31, 2020 7:37 pm

Re: delete srt if no mp4

Post by tobias »

Hello,
this PascalScript will do it. You can add it to the profile via Job->PascalScript.

Code: Select all

function OnIncludeItem(const FileName, RelativePath: UnicodeString;
        const isRightSide, isFolder:Boolean;
        const FileSize:Int64; const FileAttr:LongWord;
        const Connector: Opaque):Boolean;
var TestPath:UnicodeString;
begin
  if isFolder then
     Result:=true
  else begin
     if isRightSide then
        TestPath:=ConcatPath(ConcatPath(RightBasePath,RelativePath,Connector),ChangeFileExt(FileName,'.mp4'),Connector)
     else
        TestPath:=ConcatPath(ConcatPath(LeftBasePath,RelativePath,Connector),ChangeFileExt(FileName,'.mp4'),Connector);
     Log('Checking '+TestPath);
     Result:=not ConnFileExists(Connector,TestPath);
     end;
  end;

turbalf
Posts: 6
Joined: Tue Nov 23, 2021 11:08 pm

Re: delete srt if no mp4

Post by turbalf »

hello,
thanks a lot I'll give a try !
this software and your support are top of the class !

tobias
Posts: 1605
Joined: Tue Mar 31, 2020 7:37 pm

Re: delete srt if no mp4

Post by tobias »

Thanks.

This script assumes you are using the strategy that you mentioned, i.e. mirroring an empty folder against your Plesk folders with Exact Mirror.

Please try it in Attended Mode first.

turbalf
Posts: 6
Joined: Tue Nov 23, 2021 11:08 pm

Re: delete srt if no mp4

Post by turbalf »

it works great !
just to know, is there a way to have the script working even if mp4 file and srt file are slightly different (mostly in the end of the name, sometimes srt files add language info) and in this case not deleting srt file ?
Thanks !

tobias
Posts: 1605
Joined: Tue Mar 31, 2020 7:37 pm

Re: delete srt if no mp4

Post by tobias »

Hello,
yes, maybe, can you give me some examples?

turbalf
Posts: 6
Joined: Tue Nov 23, 2021 11:08 pm

Re: delete srt if no mp4

Post by turbalf »

yes, for exemple :
the mp4 file has this name : Avatar - The Way of Water (2022).mp4
and the srt file has this name : Avatar.The.Way.of.Water.2022.1080p.WEB-DL.DDP5.1.Atmos.H.264-CMRG.srt
so there is the same key words but unless I rename all my subtitle, the previous script will delete the srt file.
Thanks !

Post Reply