Page 1 of 1

delete srt if no mp4

Posted: Sat Apr 29, 2023 8:33 pm
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 !

Re: delete srt if no mp4

Posted: Sun Apr 30, 2023 8:32 am
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?

Re: delete srt if no mp4

Posted: Sun Apr 30, 2023 3:46 pm
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 !

Re: delete srt if no mp4

Posted: Tue May 09, 2023 5:51 pm
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;

Re: delete srt if no mp4

Posted: Tue May 09, 2023 6:29 pm
by turbalf
hello,
thanks a lot I'll give a try !
this software and your support are top of the class !

Re: delete srt if no mp4

Posted: Tue May 09, 2023 6:56 pm
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.

Re: delete srt if no mp4

Posted: Tue May 09, 2023 8:35 pm
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 !

Re: delete srt if no mp4

Posted: Tue May 09, 2023 10:09 pm
by tobias
Hello,
yes, maybe, can you give me some examples?

Re: delete srt if no mp4

Posted: Tue May 09, 2023 10:44 pm
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 !