Set destination drive while renaming

Any questions? Need some help?
Post Reply
suppi3838
Posts: 3
Joined: 17 Aug 2016, 08:47

Set destination drive while renaming

Post by suppi3838 »

Hi,

Could anyone help me out in setting how to dynamically set the destination path while renaming?
i.e. Suppose if the external HDD is connected, then i want to move the renamed files into Hdd else keep it in same drive where source file resides.

Basically want to specify if-else condition for -- format or --output attribute.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

1.
--output format is fixed and must be a folder, so you'd have to set it via your own shell script depending on the situation. If you're using bash this might be ok, but if you're on Windows CMD scripting is not sensible.


2.
The --format is scriptable, so you can do anything, including checks for existing paths. I'd use the format if I wanted full control of the output path.

The existing examples should get you a long way here:
viewtopic.php?f=5&t=2

The example that sorts files into the drive with the most disk space should probably work out of the box for this use case.
:idea: Please read the FAQ and How to Request Help.
suppi3838
Posts: 3
Joined: 17 Aug 2016, 08:47

Re: Set destination drive while renaming

Post by suppi3838 »

Hi..Thanks for the shared info.

As I'm new to command line, i'm having trouble with below script. Could you please help in modifying the script to work with based on drive letter availability instead of disk space.i.e. If 'D' exists set it as "D:/" or if 'E' exists set is as "E:/"...

{['C:', 'D:', 'E:'].collect{ (it+'/TV/'+n) as File }.sort{ a, b -> a.exists() <=> b.exists() ?: a.diskSpace <=> b.diskSpace }.last()}/{episode}
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

Use the GUI and play with the Format Editor.

A format like this might be easier to understand and modify:

Code: Select all

{('X:' as File).exists() ? 'X' : 'Y'}:/Media/...
:idea: Please read the FAQ and How to Request Help.
suppi3838
Posts: 3
Joined: 17 Aug 2016, 08:47

Re: Set destination drive while renaming

Post by suppi3838 »

Thanks a lot..That works for me 8-)
immenz
Posts: 8
Joined: 25 Oct 2016, 13:59

Re: Set destination drive while renaming

Post by immenz »

Hi, is there a way to pass a regex as file(folder) name?

For example, i want to check, if "Showname/Season 02 .*" exists.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

Yes, Groovy supports if-then-else-conditions and regular expressions.

What exactly are you trying to do? What have you tried?
:idea: Please read the FAQ and How to Request Help.
immenz
Posts: 8
Joined: 25 Oct 2016, 13:59

Re: Set destination drive while renaming

Post by immenz »

I have the following folder structure: ../series/Season xx [source]-[language]-[group]/episode

if there is a new episode, i want to check if a folder for that season and language already exist, regardless the source and group information. If so, move the file to this folder, if not, create the folder with the given tags.
Besides this, i also struggle with some other problems, so i haven't a final expression yet, only some fragments. Problem is, that detection of source, language and group are quite long, and i don't want to repeat it in the whole expression.

This is my current messy state:

Code: Select all

{[['/volume1/Serien/', 'S:/'].collect{ it + primaryTitle as File}.sort{a,b -> a.exists() <=> b.exists()}.last()].collect().sort{a,b -> a.getFolders({it.toString().find(s.pad(2) + /.*/+{audio.size()>1?'DL':(file.path.find(/\W[Gg][Ee][Rr]/)? 'DE' :'EN')}+/.*/)}) <=> 'Staffel ' +  {s.pad(2)} +  {allOf{file.path.lower().match(/(Amazon(HD)?|netflix(uhd)?)/)}{model.source.minus(null).unique().max()}{audio.size()>1?'DL':(file.path.find(/\W[Gg][Ee][Rr]/)? 'DE' :'EN')}{model.group.minus(null).countBy {it}.groupBy {it.value}.max{it.key}.value.keySet().join('')}.join('-').upper()}}.last()}
with audio:

Code: Select all

{audio.size()>1?'DL':(file.path.find(/\W[Gg][Ee][Rr]/)? 'DE' : 'EN')]
source

Code: Select all

{{file.path.lower().match(/(Amazon(HD)?|netflix(uhd)?)/)}{model.source.minus(null).unique().max()}
and group

Code: Select all

{model.group.minus(null).countBy {it}.groupBy {it.value}.max{it.key}.value.keySet().join('')}.join('-').upper()}}.last()
it tried several functions like find, match etc, but couldn't get them to work properly.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

Nobody will be able to understand your intent based on that. I recommend keeping things as simple as possible.
:idea: Please read the FAQ and How to Request Help.
immenz
Posts: 8
Joined: 25 Oct 2016, 13:59

Re: Set destination drive while renaming

Post by immenz »

Sorry, i just want to find out if a folder "season xx .?-language-.?" already exist. If so, move the file there, if not, create it and move it there.
If possible, without double checking the language.
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

I don't quite understand why you would need to check in advance, if the files is going to be moved to the same folder in either case anyway.

I recommend using a simple format that yields the same path regardless of whether or not some other file or folder exists.
:idea: Please read the FAQ and How to Request Help.
immenz
Posts: 8
Joined: 25 Oct 2016, 13:59

Re: Set destination drive while renaming

Post by immenz »

The Use Case is a TV Show, that comes in once a week or other period. In some Case, the episode is released by another group, and therefore there would be another folder based on the release group. Another case is a show, which is released in 2 languages with only a few days between them. I want to separate them by language, otherwise i could not determine which language the file has, because the episode names from lookup are already in my selected language (german)
User avatar
rednoah
The Source
Posts: 22984
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Set destination drive while renaming

Post by rednoah »

I would do something like this:

Code: Select all

X:/Media/TV Shows/{n}/Season {s} {audioLanguages}/{n} - {s00e00} - {t} {[group]}

{audioLanguages} may not work for older files where that information is not available in the container. If that is a problem then {any{fn.match(/GER/)}{'ENG'}} might be a reasonable solution.
:idea: Please read the FAQ and How to Request Help.
Post Reply