Sometimes a trailing space for no apparent reason

Support for Windows users
Post Reply
minime
Posts: 5
Joined: 06 Dec 2019, 12:40

Sometimes a trailing space for no apparent reason

Post by minime »

I am using this format to add ".eng" before .srt extension for subtitle files

Code: Select all

{n} {s00e00} {t} {if (ext =~ /srt/) '.eng'}
so "V Wars S01E02 Blood Brothers.srt"
should change to "V Wars S01E02 Blood Brothers.eng.srt"

For some reason that filename adds a trailing space before ".eng" and changes to
"V Wars S01E02 Blood Brothers .eng.srt"
AND "V Wars S01E04 Bad as Me.srt"
changes to "V Wars S01E04 Bad as Me .eng.srt"

However "V Wars S01E05 Cold Cold Ground.srt" doesn't do that and correctly changes to
"V Wars S01E05 Cold Cold Ground.eng.srt"

I can't identify why certain filenames do that but it happens with some frequency. Is there a code snippet I can add to remove trailing space? I thought that was built into FileBot? I can provide other filenames that do that if it helps.

I have also noticed that sometimes it does this if there is no episode title in the TVDB search which is perhaps explainable and I can work around that. Any help is appreciated!!
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

With space, as specified in the naming scheme:

Code: Select all

{n} {s00e00} {t} {if (ext =~ /srt/) '.eng'}
Without space, as specified in the naming scheme:

Code: Select all

{n} {s00e00} {t}{if (ext =~ /srt/) '.eng'}
:idea: Please read the FAQ and How to Request Help.
minime
Posts: 5
Joined: 06 Dec 2019, 12:40

Re: Sometimes a trailing space for no apparent reason

Post by minime »

Thank you for the quick reply!
Sorry, I guess I typed my code wrong. I am using your 2nd one - without space.

Code: Select all

{n} {s00e00} {t}{if (ext =~ /srt/) '.eng'}
with those 3 filenames 2 have trailing space and 1 doesn't.
Maybe create 3 quick txt files and see what happens if you try renaming them

V Wars S01E02 Blood Brothers.srt
V Wars S01E04 Bad as Me.srt
V Wars S01E05 Cold Cold Ground.srt
Last edited by minime on 06 Dec 2019, 18:08, edited 1 time in total.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

Looks like the upstream episode title metadata includes a space at the end:

Code: Select all

$ filebot -list --q "V Wars" --db TheTVDB --log INFO --filter "e == 4" --format "{t}" | tr ' ' '_'
Bad_as_Me_
Just get rid of it with the String.trim() method:

Code: Select all

filebot -rename *.srt --action TEST --log INFO --format "{n} {s00e00} {t.trim()}{if (ext =~ /srt/) '.eng'}"
[TEST] from [V Wars S01E02 Blood Brothers.srt] to [V Wars S01E02 Blood Brothers.eng.srt]
:idea: Please read the FAQ and How to Request Help.
minime
Posts: 5
Joined: 06 Dec 2019, 12:40

Re: Sometimes a trailing space for no apparent reason

Post by minime »

It renames the corresponding .mp4 file correctly though with no trailing space? Can I add something to my code that will delete trailing spaces and leave it like that? I don't want to keep changing my format if possible? Will this work?

Code: Select all

{n} {s00e00} {t.trim()}{if (ext =~ /srt/) '.eng'}
minime
Posts: 5
Joined: 06 Dec 2019, 12:40

Re: Sometimes a trailing space for no apparent reason

Post by minime »

I just that bit of code and seems to work fine!!! Thank you very much!! Love FileBot!!

Code: Select all

{n} {s00e00} {t.trim()}{if (ext =~ /srt/) '.eng'}
minime
Posts: 5
Joined: 06 Dec 2019, 12:40

Re: Sometimes a trailing space for no apparent reason

Post by minime »

This is my code for movies

Code: Select all

{n.space(' ')} [{y}]{' '+source}{if (ext =~ /srt/) '.eng'}
do you see any issues if I change to this?

Code: Select all

{n.space(' ')} [{y}]{' '+source.trim()}{if (ext =~ /srt/) '.eng'}
Sorry but I can copy and paste but really don't understand the various extra commands like .trim
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

source will never end with blank, so no need to trim blanks at the end.

{' '+source} is fine. It'll never yield a lonely blank. Either source yields a valid value which is then prefixed with a space, or source errors out, which means {...} yields no value at all.

:idea: viewtopic.php?f=5&t=1895
:idea: Please read the FAQ and How to Request Help.
619annamalc
Posts: 3
Joined: 06 Jan 2024, 00:46

Re: Sometimes a trailing space for no apparent reason

Post by 619annamalc »

I am having a similar issue, and I am unable to get a proper solution using the codes that you provided above.

I compiled a code using various information from different forum posts:

Format: Select all

{collection+'/'}{n} ({y}) {' (' + fn.matchAll(/extended|uncensored|uncut|directors[ ._-]cut|remastered|unrated|special[ ._-]edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[.]/, " ") + ')'} {" {imdb-$imdbid}"} / {n} ({y}) {" [$vf $vc $ac $af]"} {"{edition-${tags.first()}}"} { subt }
I recently added the {subt} tag to the end of the code to make it easier to auto name subtitle files, but it keeps adding a leading space into the name:

Picture of examples:
Screenshot

Picture of system info:
Screenshot

Logs:


Any help on this would be greatly appreciated. Thank you.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

Your format includes a leading space before {subt} so the target file will get a leading space before the .eng bit.


e.g. 1 leading space:

Format: Select all

 { subt }
e.g. No leading space:

Format: Select all

{ subt }


e.g. Firefly - S01E01 - Serenity .eng

Format: Select all

{n} - {s00e00} - {t} {subt}
e.g. Firefly - S01E01 - Serenity.eng

Format: Select all

{n} - {s00e00} - {t}{subt}
:idea: Please read the FAQ and How to Request Help.
619annamalc
Posts: 3
Joined: 06 Jan 2024, 00:46

Re: Sometimes a trailing space for no apparent reason

Post by 619annamalc »

Damn noob mistake lol.... thank you for that information.

Is there a way to download the English SDH or Foreign subtitles? I saw the post about adding subtitles in multiple languages but I'm not sure how to get English SDH or Forced Foreign Parts
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

You can add subtitles via the Subtitles feature:

:arrow: Getting Started: Automatic Subtitle Lookup

:arrow: Post-Processing Features › Fetch subtitle files


Getting specific subtitles is tricky and not well-supported. You're lucky if subtitles are available in the first place for most languages.
:idea: Please read the FAQ and How to Request Help.
619annamalc
Posts: 3
Joined: 06 Jan 2024, 00:46

Re: Sometimes a trailing space for no apparent reason

Post by 619annamalc »

I saw those threads, and I now have FileBot updated to fetch subtitles for the movies. Is there a way for it to fetch multiple versions of English subtitles?

I found this post, but it only shows different languages, not the English SDH or Foreign:
Add subtitles in multiple languages

Groovy: Select all

{ source, target ->
	getSubtitles target, 'en', 'de', 'fr', strict:false
}
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Sometimes a trailing space for no apparent reason

Post by rednoah »

619annamalc wrote: 06 Jan 2024, 13:01 I saw those threads, and I now have FileBot updated to fetch subtitles for the movies. Is there a way for it to fetch multiple versions of English subtitles?
Getting specific subtitles, e.g. only SDH, only forced, etc, is not supported. Theoretically possible via custom post-processing code, but there's no copy & paste solution at this point in time.
:idea: Please read the FAQ and How to Request Help.
Post Reply