Page 1 of 1
Remove Orphaned Subtitles?
Posted: 19 Nov 2015, 20:51
by viking
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.
Re: Remove Orphaned Subtitles?
Posted: 19 Nov 2015, 21:03
by rednoah
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?
Posted: 19 Nov 2015, 21:27
by viking
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]?
Re: Remove Orphaned Subtitles?
Posted: 20 Nov 2015, 05:34
by rednoah
Yep, then the cleaner script won't work. I don't have a script specifically for removing orphaned subtitles.
Re: Remove Orphaned Subtitles?
Posted: 13 Dec 2015, 08:42
by viking
I tried the cleaner script to delete *srt files in folders without media files. I tried it in test mode:
Code: Select all
filebot.cmd -script fn:cleaner "P:\Ultimate_Server\Television" --action test --def exts=srt
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);
Code: Select all
e.g. : Delete P:\Ultimate_Server\Television\The Strain\Season 1
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
Code: Select all
P:\Ultimate_Server\Television\TV-Show1\Season 1\subfolder
P:\Ultimate_Server\Television\TV-Show2\Season 3\subfolder
etc....
If I only want to delete files in the Seasons Folders, but not in the subfolder or anywhere else, I would need folderlevel = level4.
Re: Remove Orphaned Subtitles?
Posted: 13 Dec 2015, 09:20
by rednoah
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.
(but folders that were empty after any *.srt files were deleted were not deleted).
That can't happen. Check the logs. Check for hidden files. Check permissions.
Re: Remove Orphaned Subtitles?
Posted: 13 Dec 2015, 20:22
by viking
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)?
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
However, I get an error as FileBot tries to find the script at github:
Code: Select all
FileNotFoundException: https://raw.githubusercontent.com/filebot/scripts/m1/cleaner2.groovy
I next tried to include the complete path to 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
but that also didn't work:
Code: Select all
FileNotFoundException: https://raw.githubusercontent.com/filebot/scripts/m1/D:\@Prog_Portable\FileBot_4.6.1-portable\cleaner2.groovy
2. How do I specify a local path to cleaner2.groovy?
Re: Remove Orphaned Subtitles?
Posted: 13 Dec 2015, 21:19
by rednoah
Have you tried the
actual path yet?
e.g.
Code: Select all
filebot -script C:/MyScript.groovy
Re: Remove Orphaned Subtitles?
Posted: 13 Dec 2015, 22:04
by viking
rednoah wrote:Have you tried the
actual path yet?
e.g.
Code: Select all
filebot -script C:/MyScript.groovy
Yes, as I wrote above:
I next tried to include the complete path to 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
but that also didn't work
However, I realize my error now; I should not include the "fn:". Without it, it works

. For example:
Code: Select all
filebot.cmd -script cleaner2.groovy "K:\Ultimate_Server\TestTV" --def exts=srt
or
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?
Posted: 13 Dec 2015, 22:48
by viking
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:
Code: Select all
args.getFiles{ isClutter(it) && !hasMediaFiles(it.dir) }.each { clean(it) }
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)?
Re: Remove Orphaned Subtitles?
Posted: 15 Dec 2015, 07:44
by rednoah
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