Remove Orphaned Subtitles?
Remove Orphaned Subtitles?
Is there some script that can remove orphaned subtitles?
I am using a the suball script to download subtitles for several shows.
After watching the show, using Plex, I delete it. However, the Filebot downloaded subtitles are of course not deleted. This causes an issue because Plex shows a long list of subtitles; old as well as the new correct one.
Thus, I need a Filebot script that removes subtitles that are no longer associated with an existing media file.
I am using a the suball script to download subtitles for several shows.
After watching the show, using Plex, I delete it. However, the Filebot downloaded subtitles are of course not deleted. This causes an issue because Plex shows a long list of subtitles; old as well as the new correct one.
Thus, I need a Filebot script that removes subtitles that are no longer associated with an existing media file.
Re: Remove Orphaned Subtitles?
Have you tried the cleaner script? If it's subtitles in otherwise empty folders then it might work.
@see https://github.com/filebot/scripts/blob ... ner.groovy
@see https://github.com/filebot/scripts/blob ... ner.groovy
Re: Remove Orphaned Subtitles?
In a particular folder, I would typically have 1-2 media files with associated subtitles and also 5-6 orphaned subtitles. I guess the cleaner script would not work in this case [i.e. only remove the orphans]?rednoah wrote:Have you tried the cleaner script? If it's subtitles in otherwise empty folders then it might work.
@see https://github.com/filebot/scripts/blob ... ner.groovy
Re: Remove Orphaned Subtitles?
Yep, then the cleaner script won't work. I don't have a script specifically for removing orphaned subtitles.
Re: Remove Orphaned Subtitles?
I tried the cleaner script to delete *srt files in folders without media files. I tried it in test mode:
I was surprised to see that it also wanted to delete empty folders even though I didn't use
--def root=y (Delete given folder as well if left empty);
Note that such folders did not contain any *.srt files
(but folders that were empty after any *.srt files were deleted were not deleted).
1. Why were empty folders deleted? How can this be avoided?
2. Is there a way to select the level in the path where the files will be deleted? For example, in the following paths
If I only want to delete files in the Seasons Folders, but not in the subfolder or anywhere else, I would need folderlevel = level4.
Code: Select all
filebot.cmd -script fn:cleaner "P:\Ultimate_Server\Television" --action test --def exts=srt
--def root=y (Delete given folder as well if left empty);
Code: Select all
e.g. : Delete P:\Ultimate_Server\Television\The Strain\Season 1
(but folders that were empty after any *.srt files were deleted were not deleted).
1. Why were empty folders deleted? How can this be avoided?
2. Is there a way to select the level in the path where the files will be deleted? For example, in the following paths
Code: Select all
P:\Ultimate_Server\Television\TV-Show1\Season 1\subfolder
P:\Ultimate_Server\Television\TV-Show2\Season 3\subfolder
etc....
Re: Remove Orphaned Subtitles?
1.
--def root=y instructs the script to delete "P:\Ultimate_Server\Television" as well if left empty. Otherwise it won't touch folders that were passed as arguments.
2.
The script will always delete empty folders, and there's no options for changing that.
3.
The script is simple enough, have a look at it yourself:
https://github.com/filebot/scripts/blob ... ner.groovy
4.
--def root=y instructs the script to delete "P:\Ultimate_Server\Television" as well if left empty. Otherwise it won't touch folders that were passed as arguments.
2.
The script will always delete empty folders, and there's no options for changing that.
3.
The script is simple enough, have a look at it yourself:
https://github.com/filebot/scripts/blob ... ner.groovy
4.
That can't happen. Check the logs. Check for hidden files. Check permissions.(but folders that were empty after any *.srt files were deleted were not deleted).
Re: Remove Orphaned Subtitles?
1. I looked at the Groovy script, and it appears that all I need to do is to delete the last line to keep empty directories intact (I don't completely understand the structure and syntax and I do not have time to learn Groovy)?rednoah wrote: 3.The script is simple enough, have a look at it yourself:
https://github.com/filebot/scripts/blob ... ner.groovy
.
Thus, I created a new file "cleaner2.groovy" w/o the last line and placed it in my portable FileBot directory (D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2.groovy). I then tried to execute it from a command prompt in the FileBot directory:
Code: Select all
filebot.cmd -script fn:cleaner2 "K:\Ultimate_Server\TestTV" --def exts=srt
Code: Select all
FileNotFoundException: https://raw.githubusercontent.com/filebot/scripts/m1/cleaner2.groovy
Code: Select all
filebot.cmd -script fn:"D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2" "K:\Ultimate_Server\TestTV" --def exts=srt
Code: Select all
FileNotFoundException: https://raw.githubusercontent.com/filebot/scripts/m1/D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2.groovy
Re: Remove Orphaned Subtitles?
Yes, as I wrote above:rednoah wrote:Have you tried the actual path yet?![]()
e.g.Code: Select all
filebot -script C:/MyScript.groovy
However, I realize my error now; I should not include the "fn:". Without it, it worksI next tried to include the complete path to cleaner2.groovy:but that also didn't workCode: Select all
filebot.cmd -script fn:"D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2" "K:\Ultimate_Server\TestTV" --def exts=srt

Code: Select all
filebot.cmd -script cleaner2.groovy "K:\Ultimate_Server\TestTV" --def exts=srt
Code: Select all
filebot.cmd -script "D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2.groovy" "K:\Ultimate_Server\TestTV" --def exts=srt
Re: Remove Orphaned Subtitles?
Next problem to solve is how to set the path level so that *srt files only in folder-level 4 are deleted. I believe that the command:
iterates though all directories and levels and deletes "Clutter" files in all directories. I would need to somehow modify this function. Alternatively, and better, is to write my own function, but that requires me to learn Groovy (no time at the moment
).
Can I add some arguments to getFiles so that it only iterates at a certain level (or only down to a certain level)?
Code: Select all
args.getFiles{ isClutter(it) && !hasMediaFiles(it.dir) }.each { clean(it) }

Can I add some arguments to getFiles so that it only iterates at a certain level (or only down to a certain level)?
Re: Remove Orphaned Subtitles?
The easiest way is probably by modifying isClutter. You can count the folder depth by counting occurrences of \ (on Windows).
Code: Select all
if (f.path.count('\\') != 4)
return false