Remove Orphaned Subtitles?

Support for Windows users
Post Reply
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Remove Orphaned Subtitles?

Post 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.
User avatar
rednoah
The Source
Posts: 24026
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Remove Orphaned Subtitles?

Post 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
:idea: Please read the FAQ and How to Request Help.
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Re: Remove Orphaned Subtitles?

Post by viking »

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
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]?
User avatar
rednoah
The Source
Posts: 24026
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Remove Orphaned Subtitles?

Post by rednoah »

Yep, then the cleaner script won't work. I don't have a script specifically for removing orphaned subtitles.
:idea: Please read the FAQ and How to Request Help.
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Re: Remove Orphaned Subtitles?

Post 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.
User avatar
rednoah
The Source
Posts: 24026
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Remove Orphaned Subtitles?

Post 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.
:idea: Please read the FAQ and How to Request Help.
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Re: Remove Orphaned Subtitles?

Post by viking »

rednoah wrote: 3.The script is simple enough, have a look at it yourself:
https://github.com/filebot/scripts/blob ... ner.groovy
.
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?
User avatar
rednoah
The Source
Posts: 24026
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Remove Orphaned Subtitles?

Post by rednoah »

Have you tried the actual path yet? :lol:

e.g.

Code: Select all

filebot -script C:/MyScript.groovy
:idea: Please read the FAQ and How to Request Help.
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Re: Remove Orphaned Subtitles?

Post by viking »

rednoah wrote:Have you tried the actual path yet? :lol:

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
viking
Power User
Posts: 128
Joined: 14 Jul 2013, 08:21

Re: Remove Orphaned Subtitles?

Post 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 :roll:).

Can I add some arguments to getFiles so that it only iterates at a certain level (or only down to a certain level)?
User avatar
rednoah
The Source
Posts: 24026
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Remove Orphaned Subtitles?

Post 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
:idea: Please read the FAQ and How to Request Help.
Post Reply