(ask) How to rename movie with filesize in gigabytes

All about user-defined episode / movie / file name format expressions
Post Reply
randy030991
Posts: 4
Joined: 25 Jan 2016, 11:07

(ask) How to rename movie with filesize in gigabytes

Post by randy030991 »

Hi Iam newbie
How to rename movie with filesize in gigabytes?

eg:

I Origins (1958)

become: I Origins (2.1)

or : I Origins (2.1 Gb)


Thanks for your help
Last edited by randy030991 on 25 Jan 2016, 11:59, edited 1 time in total.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: (ask) How to rename movie with filesize in gigabytes

Post by rednoah »

The latest revision does have the {megabytes} and {gigabytes} bindings.

With FileBot v4.6.1 and older you can always use file.length() to calculate the numbers you want though:
viewtopic.php?f=5&t=3283
:idea: Please read the FAQ and How to Request Help.
randy030991
Posts: 4
Joined: 25 Jan 2016, 11:07

Re: (ask) How to rename movie with filesize in gigabytes

Post by randy030991 »

rednoah wrote:The latest revision does have the {megabytes} and {gigabytes} bindings.

With FileBot v4.6.1 and older you can always use file.length() to calculate the numbers you want though:
viewtopic.php?f=5&t=3283
so its like this?:
{n} {gigabytes}

or
{n} file.length({gigabytes})

sorry iam so newbie about code programming
thanks
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: (ask) How to rename movie with filesize in gigabytes

Post by rednoah »

More like this:

Code: Select all

{(file.length()/1e9).toFloat().round(1)} GB
:idea: Please read the FAQ and How to Request Help.
nickodemos
Posts: 10
Joined: 20 Dec 2015, 15:54

Re: (ask) How to rename movie with filesize in gigabytes

Post by nickodemos »

I am the one who asked in the other thread that rednoah linked to. He helped out a great deal in getting me straightened out with my coding.

What I ended up with was two different codes. One for a MB file up to a GB and one for over a GB.

For files from 1-999MB I use this:

Code: Select all

({(file.length()/1024/1024).toFloat().round()})
For files over 1000MB I use:

Code: Select all

({(file.length()/1024/1048).toFloat().round()})
Not sure why the math is different but it works for when I add file size to the folders.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: (ask) How to rename movie with filesize in gigabytes

Post by rednoah »

So you're switching your format for each file!? Just a condition that formats files differently depending on their file size.

Code: Select all

{file.length() < 1e6 ? (file.length()/1e6).toFloat().round() + ' MB' : (file.length()/1e9).toFloat().round(1) + ' GB'}
:idea: Please read the FAQ and How to Request Help.
AbedlaPaille
Posts: 107
Joined: 12 Apr 2020, 04:02

Re: (ask) How to rename movie with filesize in gigabytes

Post by AbedlaPaille »

rednoah wrote: 13 Mar 2016, 06:41 So you're switching your format for each file!? Just a condition that formats files differently depending on their file size.

Code: Select all

{file.length() < 1e6 ? (file.length()/1e6).toFloat().round() + ' MB' : (file.length()/1e9).toFloat().round(1) + ' GB'}
Is this supposed to display 0.8 GB ? Thought it'd use MB if inferior to 1 GB.

Is there a way to use this on folders and have the linked srt going in the same 3 GB folder instead of a 0 MB one?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: (ask) How to rename movie with filesize in gigabytes

Post by rednoah »

AbedlaPaille wrote: 09 May 2020, 18:47 Is there a way to use this on folders and have the linked srt going in the same 3 GB folder instead of a 0 MB one?
It should work by default, if you use {bytes}, or preferrably {gigabytes} in this case, unless it's an orphaned subtitle, in which case FileBot can't implicitly use the primary video file.


Alternatively, you can always do your own size calculations based on the parent folder or something like that:

Code: Select all

{folder.files.sum{ it.length() }}
:idea: Please read the FAQ and How to Request Help.
AbedlaPaille
Posts: 107
Joined: 12 Apr 2020, 04:02

Re: (ask) How to rename movie with filesize in gigabytes

Post by AbedlaPaille »

Wow we can make stuff happen depending on how many files are in? Cool.

{gigabytes} works great, just wanted 700 MO displayed instead of 0.7 GO in those < 1GO files.
Post Reply