[AMC] Problem: How do I create a CSV file on Windows? (Goal: use custom series name instead of official series name)

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

[AMC] Problem: How do I create a CSV file on Windows? (Goal: use custom series name instead of official series name)

Post by n8chavez »

Hello.

I'm using Filebot from a CL as an automated way to auto-convert using HandbrakeCLI, then take those resulting files and run it through Filebot CL, afterwards copying the original video files into a directory where I can easily know what I need to watch.

Code: Select all

for /R n:\todo\ %%F in (*.mkv, *.avi, *.mp4) do (
    "C:\Program Files\HandBrake\HandBrakeCLI.exe" --preset-import-file C:\Scripts\HBMine.json -i "%%~fF" -o "n:\done\%%~nF.mp4"
    if exist "%%~dpF%%~nF_conv.mp4" (
        del "%%~fF"
        ren "%%~dpF%%~nF_conv.mp4" "%%~nxF"
    )
)
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={n}/{s00e00} - {t}" --def minFileSize=0 --def ut_label=TV


xcopy n:\todo n:\watch /sy

rd /s /q n:\todo

md n:\todo

exit
This script works amazingly well for what I want. However, there are a few shows that I would prefer to be renamed. For example Filebot sees "Andor.S01E10.1080p.HEVC.x265-MeGusta" as simply Andor, where I would prefer it to be "Star Wars - Andor." My questions is, would it be possible to auto-force-rename certain shows within the bolded CL, which is the portion of the script that pertains to filebot? Perhaps using the --q switch? If so, what would that look like?

Thanks!
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

The destination file path is entirely up to your custom format. [SNIPPET] Use Custom Series Names has got you covered.
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

I guess that's what I don't understand. If I wanted to use method below, how would that look in the script I have above? Would I need to insert a reference file into the script I posted above? If so, where would that go in my example? For me the destination needs to be E:\TV, because I many other shows and not just the ones that need to be given a custom name.

Code: Select all

Deep Space 9;DS9
How I Met Your Mother;HIMYM
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

If you just need this for one individual series, then I would choose an option that does not require external files for the sake of simplicity:
rednoah wrote: 15 Jul 2012, 09:03 3. Use character replacement:

Code: Select all

{
	n.replace(
		'Deep Space 9' : 'DS9',
		'How I Met Your Mother' : 'HIMYM'
	)
}

1. Prototype custom format in the Format Editor:

Code: Select all

{ n.replace('Andor':'Star Wars - Andor') }/{ s00e00 } - { t }

2. Test custom format on the command-line:

Code: Select all

$ filebot -list --q "Andor" --db TheTVDB --format "{ n.replace('Andor':'Star Wars - Andor') }/{ s00e00 } - { t }"
Star Wars - Andor/S01E01 - Kassa
Star Wars - Andor/S01E02 - That Would Be Me
Star Wars - Andor/S01E03 - Reckoning
...

3. Integrate custom format into your amc script call:

Code: Select all

--def seriesFormat="{ n.replace('Andor':'Star Wars - Andor') }/{ s00e00 } - { t }"



:idea: Use the @file syntax for reading command-line arguments from external text files.
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

Thanks for this. That #2 line helped a lot. It seems that I can just replace the bolded section above with the lines below, adding another series' when an addition is needed.

call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Andor" --format "{ n.replace('Andor':'Star Wars - Andor') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={n}/{s00e00} - {t}" --def minFileSize=0 --def ut_label=TV


That seems to work correctly. Am I missing something. Doing it this way is a lot easier than referencing an external args.txt file.

Edit- The end result is that that my .bat file looks like below:

Code: Select all

call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Reboot (2022)" --format "{ n.replace('Reboot (2022)':Reboot') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Yellowstone (2018)" --format "{ n.replace('Yellowstone (2018)':Yellowstone') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Ghosts (US)" --format "{ n.replace('Ghosts (US)':Ghosts') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Titans (2018)" --format "{ n.replace('Titans (2018)':Titans') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Quantum Leap (2022)" --format "{ n.replace('Quantum Leap (2022)':Quantum Leap') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Big Sky (2020)" --format "{ n.replace('Big Sky (2020)':Big Sky') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Archer (2009)" --format "{ n.replace('Archer (2009)':Archer') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" -list --q "Andor" --format "{ n.replace('Andor':'Star Wars - Andor') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
call C:\Progra~1\FileBot\filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={n}/{s00e00} - {t}" --def minFileSize=0 --def ut_label=TV
It seem to work just fine.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

:?: How did you come up with this? :?: How did you test this? :?: Why would you call filebot multiple times in a row on the same input files?

:!: -list has no effect if you're using the amc script.

:!: --q
doesn't do what you seem to think it does. Your first amc script call will simply process all files as Reboot (2022) because --q forces the series and thus disables auto-detection, and then the other 8 filebot calls will do nothing because the input folder will be empty after the first call incorrectly processed all files.

:!: --format is ignored by the amc script in favour of --def seriesFormat script parameter. Though --format may be used a default if --def seriesFormat is left unspecified, though this is undocumented and should not be relied upon.


Anyway...


:arrow: Since you apparently have many custom replacement patterns, you will probably prefer to maintain them in a simple external CSV file, so that you can modify that in a central location without ever touching your code:
rednoah wrote: 15 Jul 2012, 09:03 5. Use a custom lookup table read from an external TSV or CSV file:

Code: Select all

{
	def table = csv('/path/to/names.csv')
	table[n] ?: n
}
e.g. /path/to/names.csv

Code: Select all

Deep Space 9;DS9
How I Met Your Mother;HIMYM

1. Prototype custom format in the Format Editor:

Code: Select all

{ csv('N:/names.csv')[n] ?: n }/{ s00e00 } - { t }

2. Integrate custom format into your amc script call:

Code: Select all

filebot -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('N:/names.csv')[n] ?: n }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV

:idea: The example above assumes that your CSV mapping file is located at N:/names.csv as specified in the code.
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

Using your method, bat pointing to csv file, the results were better. However the csv was ignored, so I'm assuming I messed that up.

Code: Select all

call C:\Progra~1\FileBot\Filebot.exe -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('N:/Names.csv')[n] ?: n }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV

Code: Select all

Andor;Star Wars - Andor
Assuming that your examples, "Deep Space 9;DS9" and "How I Met Your Mother;HIMYM" are correct. I can''t see what I did wrong. The original name and desired name are separated by a semicolon only. Is that right? Now should the Names.csv file be formatted?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

You don't need to worry about @file syntax if you don't have a problem with the command-line argument parser yet. Your command is simple and none of the argument values contain " (which would require some finesse to pass correctly on the command-line) so you'll be fine.
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

Thank you for that, but I altered my post to reflect your previous help that I did not see prior to posting. I'm no longer using that method.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

1. Prototype custom format in the Format Editor:

Code: Select all

{ csv('N:/Names.csv') }

Code: Select all

{ csv('N:/Names.csv')[n] }

Code: Select all

{ csv('N:/Names.csv')[n] ?: n }
:?: What does the Format Editor say? (you can click on the message to copy & paste the message)
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

I just know that if I purposefully try to run Andor s01e11 through the script. The resulting file is moved to "Andor\S01E11 - Daughter of Ferrix" and not "Star Wars - Andor\S01E11 - Daughter of Ferrix" as the cvs tells it to. That tells me the formatting of the Names.csv file is not correct. For example:

Code: Select all

[MOVE] from [N:\done\Bobs.Burgers.S13E07.720p.HEVC.x265-MeGusta\Bobs.Burgers.S13E07.720p.HEVC.x265-MeGusta.mkv] to [E:\TV\Bob's Burgers\S13E07 - Ready Player Gene.mkv]
[MOVE] from [N:\done\Big.Sky.2020.S03E08.720p.HEVC.x265-MeGusta\Big.Sky.2020.S03E08.720p.HEVC.x265-MeGusta.mkv] to [E:\TV\Big Sky (2020)\S03E08 - Duck Hunting.mkv
This shows the csv was not used, otherwise E:\TV\Big Sky (2020)\S03E08 - Duck Hunting.mkv would have been E:\TV\Big Sky\S03E08 - Duck Hunting.mkv
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

"{ csv('N:/Names.csv') }" results in a series name of unreadable 'letters'

"{ csv('N:/Names.csv')[n] }" result in no series folder in the root

"{ csv('N:/Names.csv')[n] ?: n }" result in a series name ignoring the csv file; \Big Sky (2020) instead of \Big Sky
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

n8chavez wrote: 17 Nov 2022, 06:26 "{ csv('N:/Names.csv') }" results in a series name of unreadable 'letters'
:?: Sounds like your N:/Names.csv file is not a CSV file. And so csv() is reading in gibberish binary content. How did you write your CSV file? Can you share your CSV file via Google Drive?

:?: Can you post screenshots so that we can see what you can see?
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

Example #1: Unreadable characters in destination directory

Code: Select all

{ csv('N:/Names.csv') } ----> call "C:\Program Files\Filebot\Filebot.exe" -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('N:/Names.csv') }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
https://drive.google.com/file/d/1A5woct ... share_link

Example 2: No Series Name in destination

Code: Select all

{ csv('N:/Names.csv')[n] } ----> call "C:\Program Files\Filebot\Filebot.exe" -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('N:/Names.csv')[n] }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
https://drive.google.com/file/d/1GhTyny ... share_link

Example #3: Resulting series destination directory not run through names.csv file

Code: Select all

{ csv('N:/Names.csv')[n] ?: n } ----> call "C:\Program Files\Filebot\Filebot.exe" -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('N:/Names.csv')[n] ?: n }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
https://drive.google.com/file/d/1u3hb63 ... share_link

Here is an editable copy of my Names.csv file:
https://drive.google.com/file/d/179V2tu ... share_link
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

:?: Did you use Microsoft Excel to create a *.xlsx file and then manually change the extension to *.csv by any chance? :roll:


:arrow: A *.csv file is a PLAIN TEXT FILE that you can edit in a TEXT EDITOR so it'll look like this:

Code: Select all

Andor;Star Wars - Andor
And NOT like this:
Image
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

No. I created a new notepad file and then changed the extension from txt to csv. I'll try associating csv files with Notepad++ and recreate the file.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

The file you have shared is a 6 KB Microsoft Excel / Office Open XML format file and so it is most certainly not a plain/text file and most certainly was not created with a text editor:

Code: Select all

$ ls -lh *.csv
... 6.0K ... Names.csv

Code: Select all

$ file *.csv
Names.csv: Microsoft OOXML

n8chavez wrote: 18 Nov 2022, 01:58 I created a new notepad file and then changed the extension from txt to csv.
I don't know what to tell you. But the file you shared is not that file. :lol:
:idea: Please read the FAQ and How to Request Help.
n8chavez
Posts: 12
Joined: 18 May 2018, 19:46

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by n8chavez »

Perhaps that's because the csv file opened in office? I dunno...

In any case, after redoing to the csv file in Notepad++, I got these results using '{ csv('C:/Names.csv')[n] ?: n }'

https://drive.google.com/file/d/1GE1pV_ ... share_link

So this works.

Code: Select all

call "C:\Program Files\Filebot\Filebot.exe" -script fn:amc --output "E:\TV" --action move -non-strict "n:\done" --def "seriesFormat={ csv('C:/Names.csv')[n] ?: n }/{ s00e00 } - { t }" --def minFileSize=0 --def ut_label=TV
One question though, why does the csv file location always have to be in a root? I use c:\scripts, and the path C:\Scripts/Names.csv doesn't work. In fact, no path other than a root works.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [AMC] Use custom series name instead of official series name, e.g. "Star Wars - Andor" instead of "Andor"

Post by rednoah »

The file can be anywhere:

Code: Select all

{ csv('X:/Y/Z/Names.csv') }

:!: But your code is wrong because you - yet again - did not prototype your code in the Format Editor:

Image


:!: We always use / because \ has special meaning as escape character on the command-line, in String literals, etc, and will thus require some finesse depending on the context. Always using / bypasses the problem entirely.
:idea: Please read the FAQ and How to Request Help.
Post Reply