fn:renall with --filter switch help

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

fn:renall with --filter switch help

Post by stephen147 »

I want not to rename any url extensions as the renall fn does this currently.

How can I use the --filter switch to exclude the filetype 'url'

There are two urls in the folder (Example of folder tree)

Code: Select all

\---_To Process
    \---A Perfect Getaway (2009) (Director's Cut) (Unrated) 1080p HD Blu-ray non-HDR x265 DTS 5.1ch_YoLo
        |   A Perfect Getaway (2009) (Director's Cut) (Unrated) 1080p HD Blu-ray non-HDR x265 DTS 5.1ch_YoLo.mkv
        |   A Perfect Getaway (2009) (Director's Cut) (Unrated) 1080p HD Blu-ray non-HDR x265 DTS 5.1ch_YoLo.nfo
        |   clearart.png
        |   disc.png
        |   fanart.jpg
        |   folder.jpg
        |   imdb.url
        |   logo.png
        |   poster.jpg
        |   poster_BAK.jpg
        |   tmdb.url
        |
        +---extrafanart
        |       fanart1.jpg
        |       fanart2.jpg
        |       fanart3.jpg
        |
        \---Theme
                A Perfect Getaway (2009) Theme Composed by Boris Elkis_TVTunesTheme.mp3
:!: My code below which doesn't cut the mustard:

Code: Select all

filebot -script fn:renall "Z:\Movies & TV\_Newly DL'd\_To Process" -non-strict --format "{n}" --db TheMovieDB --filter "ext != /url/" --action test --log info
:!: EDIT
Looks like there's a bug, nawt sure. tmdb.url doesn't get touched but imdb.url does.

This Is Run With The imdb.url In The Folder

Code: Select all

PS C:\Users\username_redacted> filebot -script fn:renall "Z:\path" -non-strict --format "{n}" --db TheMovieDB --filter "ext != /url/" --action test --log info
[TEST] from [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway (2009).nfo] to [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway.nfo]
[TEST] from [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway (2009).mkv] to [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway.mkv]
[TEST] from [Z:\path\A Perfect Getaway (2009)\imdb.url] to [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway.url]
This is run with the tmdb.url in the folder
:!: As you can see it's not processed.

Code: Select all

PS C:\Users\username_redacted> filebot -script fn:renall "Z:\path" -non-strict --format "{n}" --db TheMovieDB --filter "ext != /url/" --action test --log info
[TEST] from [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway (2009).nfo] to [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway.nfo]
[TEST] from [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway (2009).mkv] to [Z:\path\A Perfect Getaway (2009)\A Perfect Getaway.mkv]
My filebot -script fn:sysinfo output:

Code: Select all

FileBot 4.8.5 (r6224)
JNA Native: 5.2.2
MediaInfo: 18.12
7-Zip-JBinding: 9.20
Chromaprint: fpcalc version 1.4.2
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2019-04-30 (r563)
Groovy: 2.5.6
JRE: OpenJDK Runtime Environment 11.0.2
JVM: 64-bit OpenJDK 64-Bit Server VM
CPU/MEM: 32 Core / 29 GB Max Memory / 49 MB Used Memory
OS: Windows 10 (amd64)
Package: APPX
License: Microsoft Store License
Done ?(?????)?
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: fn:renall with --filter switch help

Post by rednoah »

1.
The --filter argument does not do what you think it does:
viewtopic.php?f=3&t=2127


2.
The --file-filter option does what you think it does.

e.g.

Code: Select all

--file-filter f.video

3.
I'm actually not sure if *.url files can be processed. Maybe it works. Maybe they'll be ignored by default just like artwork files.



EDIT:

I checked the code. FileBot treats *.url files as if they were *.nfo files, so they can be processed, IF they can be matched to a movie via IMDB ID pattern in the text content of the nfo / url file, which explains what's happening in your case.
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

Code: Select all

filebot -script fn:renall "Z:\Movies & TV\_Newly DL'd\_To Process" -non-strict --format "{n}" --db TheMovieDB --file-filter f.video --action test --log info
Returns nothing.

Either does it by specifying the folder where the file resides.

Code: Select all

filebot -script fn:renall "Z:\Movies & TV\_Newly DL'd\_To Process\A Perfect Getaway (2009) (Director's Cut) (Unrated) 1080p HD Blu-ray non-HDR x265 DTS 5.1ch_YoLo" -non-strict --format "{n}" --db TheMovieDB --file-filter f.video --action test --log info
rednoah wrote: 03 May 2019, 10:37 EDIT:
I checked the code. FileBot treats *.url files as if they were *.nfo files, so they can be processed IF they can be matched to a movie via IMDB ID pattern in the text content of the nfo / url file, which explains what's happening in your case.
Is this the sort of behavior okay? I don't mind as long as I can get the --file-filter switch to work.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: fn:renall with --filter switch help

Post by rednoah »

1.
Best to use filebot -rename -r unless you have a specific reason for using filebot -script fn:renall to cover some specific corner case. Presumably, the renall script does its own thing, processing your input arguments, and just ignores some of your options (same as the amc script).

The -rename command is typically used to rename files:

Code: Select all

filebot -rename -r ... --file-filter f.video ...

2.
stephen147 wrote: 03 May 2019, 12:02

Code: Select all

filebot -script fn:renall /some/folder ... --file-filter f.video ...
Returns nothing.
That's because input argument /some/folder is immediately ignored, because it's a folder and not a video file, and so the script has no input, and nothing to do.


3.
stephen147 wrote: 03 May 2019, 12:02 Is this the sort of behavior okay? I don't mind as long as I can get the --file-filter switch to work.
IDK. This particular corner case hasn't come up before. Might make sense to add if TMDb links are becoming more common nowadays.
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

rednoah wrote: 03 May 2019, 12:073.
stephen147 wrote: 03 May 2019, 12:02 Is this the sort of behavior okay? I don't mind as long as I can get the --file-filter switch to work.
IDK. This particular corner case hasn't come up before. Might make sense to add if TMDb links are becoming more common nowadays.
Yes, I feel it's not desired when it affects only one specific type of URL file. I much prefer tmdb links anyway but the amc script generates imdb ones along with it but it's no biggie.

Still no joy with my filter
:!: Using --file-filter "f.isVideo()" doesn't pick up .nfo files now.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: fn:renall with --filter switch help

Post by rednoah »

stephen147 wrote: 03 May 2019, 13:39 Using --file-filter "f.isVideo()" doesn't pick up .nfo files now.
Indeed, video only excludes all non-video files, such as nfo files. :lol:

Just go with your original logic then:

Code: Select all

--file-filter "ext != /url/"
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

That will bring me back to square one.. I only want to change the video files and the nfo also.
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: fn:renall with --filter switch help

Post by rednoah »

Per request, only video files or nfo files:

Code: Select all

--file-filter "f.video || ext == /nfo/"
:idea: Please read the FAQ and How to Request Help.
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

Perfect, thank you!
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

PowerShell Rename PS1 Script

Post by stephen147 »

Here my complete rename PowerShell script for anyone who may want it.

:!: READ THE SECTION AT THE HEADER OF THE CODE

Image

Code: Select all

# ABOUT
#################################################################
# Version 0.1 beta		- 2019.05.05 - FIRST RELEASE
# Version 0.11 beta		- 2019.05.10 - ADDED          - Variable 'filterFiles' to --file-filter switch.
# Version 0.11 beta		- 2019.05.11 - BUG            - Fixed regular expression for parsing format file.
#                                      BUG            - Fixed folders renaming. Now uses the {fn} binding to rename to ensure the same name.
#                                      ADDED          - fileProcessArg and folderProcessArg args. So that one Variable will do both test runs and full-runs.

# Works with movie files and .nfos and folder renaming.
# N.B. Use at your own risk.
# Uploaded here in the FileBot forum: https://www.filebot.net/forums/viewtopic.php?f=4&t=10766&p=43842#p43842

# IMPORTANT
#################################################################
# Change these paths to your desired format file and folder to process
# Change the file filters to your liking
$movieFormatPath = "Z:\Movies & TV\New Downloads\_FileBot Bindings\Format_Movie.groovy"
$movieFormat = Get-Content "$movieFormatPath" | Select-String -pattern "^.*//+|^\s*$" -notmatch
$processFolder = "Z:\Movies & TV\New Downloads\_To Process"
$filterFiles = ('"f.video || ext == /nfo/ || ext == /srt/ && fn != /(?i)extras/"')
# $filterFiles = ('"f.video || ext == /nfo/ || ext == /srt/ || minutes > 30"')
# $filterFiles = ('"f.video || ext == /nfo/ || ext == /srt/ || minutes > 30 || fn != /(?i)extras/"')

# Strings to pass below in 2 locations. Edit here.
$fileProcessArg = 'filebot -rename -r "$processFolder" -non-strict --format "$movieFormat" --db TheMovieDB --file-filter $filterFiles'
$folderProcessArg = 'filebot -script fn:renall "$processFolder" -non-strict --format "$movieFormat" --def ignore="Extras" --db TheMovieDB --def target=folder'

#################################################################

function closeWithTimer ($time) {
	$timeOutSec=$time
	Write-Host
	Write-Host ----------------------------------------
	Write-Host
	Write-Host "This screen will meow exit in"$timeOutSec" seconds..." -ForegroundColor Red
	timeout /T $timeOutSec; closePowerShell
}

# Set-ConsoleWindow fn here: https://stackoverflow.com/a/38999539/8262102
function Set-ConsoleWindow
{
	param(
		[int]$Width,
		[int]$Height
		)
	$WindowSize = $Host.UI.RawUI.WindowSize
	$WindowSize.Width = [Math]::Min($Width, $Host.UI.RawUI.BufferSize.Width)
	$WindowSize.Height = $Height
	try{
		$Host.UI.RawUI.WindowSize = $WindowSize
	}
	catch [System.Management.Automation.SetValueInvocationException] {
		$Maxvalue = ($_.Exception.Message |Select-String "\d+").Matches[0].Value
		$WindowSize.Height = $Maxvalue
		$Host.UI.RawUI.WindowSize = $WindowSize
	}
}
Set-ConsoleWindow 300 50

function closePowerShell {

	$PSProcess = Get-Process -name PowerShell -ErrorAction "Ignore"
	if ($PSProcess -ne $null) {
		echo "Stopping PowerShell..."
		Stop-Process -Name PowerShell
		} else {
			echo "No running PowerShell process found"
		}

	}

	function Find-Folders {
		[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
		[System.Windows.Forms.Application]::EnableVisualStyles()
		$browse = New-Object System.Windows.Forms.FolderBrowserDialog
		$browse.SelectedPath = $processFolder
		$processFolder = $processFolder

		Write-Host "RUN IN TEST MODE ? (DEFAULT IS NO)" -ForegroundColor Yellow
		$runTestAns = Read-Host " ( Y / N ) "
		Write-Host
		Write-Host ----------------------------------------
		Write-Host
		Switch ($runTestAns)
		{
			Y {Write-Host "RUN (TEST MODE)" -ForegroundColor Yellow; $runTestAns=$true}
			N {Write-Host "RUN (NON-TEST MODE)" -ForegroundColor Yellow; $runTestAns=$false}
			Default {Write-Host "RUN (NON-TEST MODE) [ DEFAULT ]" -ForegroundColor Yellow; $runTestAns=$false}
		}
		Write-Host
		Write-Host "HIT CTRL+C TO EXIT AT ANY TIME" -ForegroundColor Yellow
		Write-Host
		Write-Host ----------------------------------------
		Write-Host

		if (((Test-Path -Path ($processFolder) -PathType Container) -and (Test-Path -Path $movieFormatPath))) {$loop = $true}

		while($loop)
		{
			if ($browse.ShowDialog() -eq "OK")
			{
				$loop = $false
				# Begin Routine
				Set-PSDebug -Off
				$processFolder = $browse.SelectedPath
				Write-Host "PROCESSING FOLDER :"`t $processFolder -ForegroundColor Yellow
				Write-Host "FORMAT FILE PATH  : "`t" "$movieFormatPath -ForegroundColor Yellow
				Write-Host
				Write-Host ----------------------------------------
				# filebot -script fn:sysenv --format "$movieFormat"
				Write-Host

				if ($runTestAns -eq $false) {
					Write-Host "RENAME ROUTINE STARTING... (NON-TEST MODE)" -ForegroundColor Yellow
					Write-Host
					Write-Host ----------------------------------------
					Write-Host
					# Process files
					Invoke-Expression "$fileProcessArg"
					# Process folders
					Invoke-Expression "$folderProcessArg"

				}
				if ($runTestAns -eq $true) {
					Write-Host "RENAME ROUTINE STARTING... (TEST MODE)" -ForegroundColor Yellow
					Write-Host
					Write-Host ----------------------------------------
					Write-Host
					# Process files
					Invoke-Expression "$fileProcessArg --action test --log info"

					# Process folders
					Invoke-Expression "$folderProcessArg --action test --log info"

				}
				Write-Host
				closeWithTimer 10
				} else
				{
					$res = [System.Windows.Forms.MessageBox]::Show("You clicked Cancel. Would you like to try again or exit?", "Select a location", [System.Windows.Forms.MessageBoxButtons]::RetryCancel)
					if($res -eq "Cancel")
					{
						#Ends script
						closePowerShell
					}
				}
			}
			Set-PSDebug -Off
			if (((Test-Path -Path $browse.SelectedPath -PathType Container) -and (Test-Path -Path $movieFormat))) {
				$browse.ShowNewFolderButton = $true
				$browse.Description = "Select a Movie directory"
				} else {
					if ((Test-Path -Path $browse.SelectedPath -PathType Container) -ne $true) {Write-Host "`nERROR >>>`t" $browse.SelectedPath "`t<<< NOT FOUND!`n`nPlease correct the path in this script.`n" -ForegroundColor Red}
					if ((Test-Path -Path $movieFormat) -ne $true) {Write-Host "`nERROR >>>`t" $movieFormat "`t<<< NOT FOUND!`n`nPlease correct the path in this script.`n" -ForegroundColor Red}
					closeWithTimer 10
				}
				$browse.Dispose()
				} Find-Folders
Mason1171
Posts: 10
Joined: 14 May 2019, 00:33

Re: PowerShell Rename PS1 Script

Post by Mason1171 »

Stephen, can you please try to add TV Show support in your Rename Script? Thanks
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

Just change in the code:

Code: Select all

Format_Movie.groovy
With:

Code: Select all

TV_Movie.groovy
And then replace any:

Code: Select all

--db TheMovieDB
With:

Code: Select all

--db TheTVDB
:!: Then save as a different ps1 file and test it.
Mason1171
Posts: 10
Joined: 14 May 2019, 00:33

Re: fn:renall with --filter switch help

Post by Mason1171 »

Thank you but is it possible for the script to process tv shows and movies simultaneously?
stephen147
Donor
Posts: 131
Joined: 01 Sep 2015, 22:40

Re: fn:renall with --filter switch help

Post by stephen147 »

This is something I have not tested myself, you could always run the script I've posted and try to see if it skips on Series.

:!: As always, test first.
Post Reply