Noob here, needs help with CLI command

Support for Ubuntu and other Desktop Linux distributions
Post Reply
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Noob here, needs help with CLI command

Post by gKxFF »

Hey there.

I'm trying to rename a whole bunch of folders, into something more "readable".

So, without explaining too much, the directory where all the folders reside, is like this:

Code: Select all

/home/user/Movies/This.Is.A.Movie.1999.BluRay.x264-GROUP
/home/user/Movies/This.Is.Also.A.Movie.2001-BluRay.x264-GROUPP
and so on.

I would like to rename the folders, so that it'll be like:

Code: Select all

/home/user/Movies/This Is A Movie (1999)/This.Is.A.Movie.1999.BluRay.x264-GROUP
/home/user/Movies/This Is Also A Movie (2001)/This.Is.Also.A.Movie.2001-BluRay.x264-GROUPP
Can anybody help me with this? It would be especially nice, if the words like these start with a capital letter (upper-case):

Code: Select all

III, II, IV, The, Of, And, At, Vs, A, An, But, Nor, For, On, So, Yet
and so on :)

Thanks.

EDIT:
Another "important" thing - I would like only for the folders to be renamed, not the files inside them :).
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

try this:

Code: Select all

/home/user/Movies/{plex.name}/{fn}
if you REALLY need all words "start with a capital letter"

Code: Select all

/home/user/Movies/{plex.name.upperInitial()}/{fn}
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

Thanks for the answer, but how do I put it into a CLI command?

I tried running

Code: Select all

filebot -rename /home/user/Movies/* --db "TheMovieDB" --format "{plex.name.upperInitial()}/{fn}"
But that messed up things a lot. Made the right directories, except they're all sub-folders, plus the command added sub-folders that just includes the subtitles. Like:

Code: Select all

/home/user/Movies/This.Is.A.Movie.1999.BluRay.x264-GROUP/This Is A Movie (1999)/
/home/user/Movies/This.Is.A.Movie.1999.BluRay.x264-GROUP/This Is A Movie (1999).Eng/(subs)
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

looks like plex is f*cking the subs :( ?

better use this then:

Code: Select all

{ny.upperInitial()}/{fn}
e.g.

Code: Select all

filebot -rename -r /home/user/Movies -non-strict --db TheMovieDB --output "/home/user/Movies/" --format "{ny.upperInitial()}/{fn}"
btw: you can revert the rename (history)
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

Hey again Kim.

Running your command, gives somewhat unexpected results.

It's now:

Code: Select all

/home/user/Movies/This Is A Movie (1999)/allTheFilesCorrectlyNamed
/home/user/Movies/This.Is.A.Movie.1999.BluRay.x264-GROUP/(empty)
Which is not the result I was hoping for :(

I'm still looking for:

Code: Select all

/home/user/Movies/This Is A Movie (1999)/This.Is.A.Movie.1999.BluRay.x264-GROUP/(allFilesNamedAsOriginal)
EDIT:
Bunch of edits, sorry. 01:43AM gmt+1
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

so video folder + files renamed ok ?
and subs is not ?
sounds like your subs are badly named or something ?

test with subs named same as video file and in same dir as video

testing on windows this works

Code: Select all

filebot -rename -r "D:\temp" -non-strict --db TheMovieDB --output "D:\temp" --format "{ny.upperInitial()}/{fn}" --action test
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

No, they aren't correctly renamed :/

The folder structure, after running your command is:

Code: Select all

/home/user/Movies/This Is A Movie (1999)/(allTheFilesCorrectlyNamed)
/home/user/Movies/This.Is.A.Movie.1999.BluRay.x264-GROUP/(empty folder)
I would like it to be:

Code: Select all

/home/user/Movies/This Is A Movie (1999)/This.Is.A.Movie.1999.BluRay.x264-GROUP/(allTheFilesCorrectlyNamed)
So that the This.Is.A.Movie.1999.BluRay.x264-GROUP is a sub-folder to This Is A Movie (1999)

Does that make sense? And also, thanks so much for the help so far :)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Noob here, needs help with CLI command

Post by rednoah »

Here's what I get:

Code: Select all

filebot -rename -r . --output . --format "{ny}/{fn}" --action TEST --db TheMovieDB -non-strict

Code: Select all

Rename movies using [TheMovieDB]
Auto-detect movie from context: [Avatar.2009.mkv]
[TEST] from [Avatar.2009.mkv] to [Avatar (2009)/Avatar.2009.mkv]
Processed 1 files
:idea: Please read the FAQ and How to Request Help.
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

Yes, and me too.

Using your example, I would like it to be:

Code: Select all

Rename movies using [TheMovieDB]
Auto-detect movie from context: [Avatar.2009.mkv]
[TEST] from [Avatar.2009.mkv] to [Avatar (2009)/Avatar.2009/Avatar.2009.mkv]
Processed 1 files
So that the folder name, parent to the mkv file, is the same name as the mkv file, e.g. Avatar.2009


Edit
Running the command:

Code: Select all

filebot -rename -r . --output . --format "{ny.upperInitial()}/{fn}/{fn}" --action TEST --db TheMovieDB -non-strict
Works, BUT! It does create extra folders because the SRT files aren't named the same as the other files :/
Like so:

Code: Select all

/home/user/m/local/Movies/Movie Title (2008)/Movie.Title.2008.1080p.BluRay.x264-GROUP.en/Movie.Title.2008.1080p.BluRay.x264-GROUP.en.srt
Is there any way to exclude the SRT files? So that it doesn't "recognize" them, when renaming? Because of Plex, I kind of need the ".en.srt" part of the subtitle, so that it gets registered properly as an English subtitle
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Noob here, needs help with CLI command

Post by rednoah »

Can you post the command and console output that you're getting please? So can see exactly what you're doing and what's not working, so I can find a solution for you?
:idea: Please read the FAQ and How to Request Help.
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

Here's the command:

Code: Select all

filebot -rename -r . --output . --format "{ny.upperInitial()}/{fn}/{fn}" --action TEST --db TheMovieDB -non-strict
Here's the output:

Code: Select all

https://pastebin.com/ZDT1ea4g
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

try this:

Code: Select all

{f.isSubtitle() ? (ny-subt).upperInitial() + '/' + fn-subt : ny.upperInitial() + '/' + fn}/{fn}
btw: weird output path you want
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

I tried running

Code: Select all

filebot -rename -r . --output . --format "{f.isSubtitle() ? (ny-subt).upperInitial() + '/' + fn-subt : ny.upperInitial() + '/' + fn}/{fn}" --action TEST --db TheMovieDB -non-strict
Gave me this output:

Code: Select all

https://pastebin.com/YR0vEXqk
Which has the same problem. It still creates a separate folder for the subtitles, e.g.

Code: Select all

[TEST] from [/home/plex/m/local/Movies/Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS/Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS.en.srt] 
to 
[/home/plex/m/local/Movies/Mississippi Burning (1988)/Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS.en/Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS.en.srt]
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

{subt} converts 2 letter lang to 3 .. not good here :(

Code: Select all

{f.isSubtitle() ? (ny-subt).upperInitial() + '/' + fn.replaceAll(/\.\w*$/) : fn}/{fn}
Mississippi Burning (1988)\Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS\Mississippi.Burning.1988.REMASTERED.1080p.BluRay.x264-SiNNERS.en.srt
only works if e.g.
.XX.srt format
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Noob here, needs help with CLI command

Post by rednoah »

I have distilled a test case:

Code: Select all

filebot -rename -r . --output . --format "{ny}/{fn}/{fn}" --action TEST --db TheMovieDB -non-strict
Rename movies using [TheMovieDB]
Auto-detect movie from context: [Avatar.2009.mkv]
[TEST] from [Avatar.2009.mkv] to [Avatar (2009)/Avatar.2009/Avatar.2009.mkv]
[TEST] from [Avatar.2009.25fps.eng.srt] to [Avatar (2009)/Avatar.2009.25fps.eng/Avatar.2009.25fps.eng.srt]
Processed 2 files
Presumably, this is not working as expected, since the video and the subtitle file end up in different folders.


Problem: "Folder name same as the file name" doesn't work, since it's not what you want, since you want "Folder name same as the file name, if it's a movie file, but if it's a subtitle file, use guess the corresponding video file name, and use that as folder name instead" which is obviously more intricate.


Easy Solution: Use --format "{plex}" or --format "{ny}/{fn}" (if you really want to keep the original name) and call it a day.


Hard Solution: Write intricate format code that does exactly what you want. I'd go with the Easy Solution though, since it's probably gonna be more than good enough for your particular use case.
:idea: Please read the FAQ and How to Request Help.
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

Kim: Thanks so much for your help so far!
I tried running:

Code: Select all

filebot -rename -r . --output . --format "{f.isSubtitle() ? (ny-subt).upperInitial() + '/' + fn.replaceAll(/\.\w*$/) : fn}/{fn}" --action TEST --db TheMovieDB -non-strict
Which gave me this result:

Code: Select all

https://pastebin.com/bHP1Qfuw
Not sure what to make of it to be honest.

But when I remove the --action TEST part:

Code: Select all

filebot -rename -r . --output . --format "{f.isSubtitle() ? (ny-subt).upperInitial() + '/' + fn.replaceAll(/\.\w*$/) : fn}/{fn}" --db TheMovieDB -non-strict
It gives me all sorts of Java-related errors:

Code: Select all

https://pastebin.com/YmGkJQxt

Rednoah:
I'm more inclined to go the hard way :). I have a huge 30TB+ library, all set up this way, I'm not about to change that :) (and sorry for being such a nuisance).
That's the reason I'm so persistent with my weird way of sorting things...
But thanks a lot for your help so far, I guess I'll either have to do this manually, or find another solution.


Edit:
I found somewhat of a solution.... To run a command, that renames all the files as the parent folder name:

Code: Select all

rename 's/(.*)\/.*\./$1\/$1./' */*
And then run the simple Filebot command:

Code: Select all

filebot -rename -r . --output . --db TheMovieDB --format "{ny.upperInitial()}/{fn}/{fn}" -non-strict
And then rename the SRT files by running:

Code: Select all

rename 's/\.srt/\.en\.srt/' */*/*
But if there's any way to do all of this "within" Filebot, that would be preferable to me :)
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Noob here, needs help with CLI command

Post by kim »

I forgot "ny.upperInitial() + '/' + " part and remove subt
and maybe it's better to hardcode the lang codes:

Code: Select all

{f.isSubtitle() ? ny.upperInitial() + '/' + fn.replaceAll(/\.(en|eng)$/) : ny.upperInitial() + '/' + fn}/{fn}
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Noob here, needs help with CLI command

Post by rednoah »

Here's an idea. Since FileBot will automatically try to find the corresponding video file when using MediaInfo bindings such as {resolution} on subtitle files, you might be able to get the video file name via the {media} binding:

Code: Select all

{media.FileName}
:arrow: viewtopic.php?f=5&t=4285
:idea: Please read the FAQ and How to Request Help.
gKxFF
Posts: 9
Joined: 27 Jun 2019, 19:49

Re: Noob here, needs help with CLI command

Post by gKxFF »

kim wrote: 30 Jun 2019, 20:34 I forgot "ny.upperInitial() + '/' + " part and remove subt
and maybe it's better to hardcode the lang codes:

Code: Select all

{f.isSubtitle() ? ny.upperInitial() + '/' + fn.replaceAll(/\.(en|eng)$/) : ny.upperInitial() + '/' + fn}/{fn}
This seems to work! I have only tested on a single folder, but it seems to work out very well :). I'll edit this post, when I've tested it on a larger scale.

Thank you so much Kim (and rednoah) for the great help and persistence :)!!

For anyone, who should be curious to try it out:

Code: Select all

filebot -rename -r . --output . --db TheMovieDB --format "{f.isSubtitle() ? ny.upperInitial() + '/' + fn.replaceAll(/\.(en|eng)$/) : ny.upperInitial() + '/' + fn}/{fn}" -non-strict
Post Reply