[HIRE REQUEST] Modified AMC script

Running FileBot from the console, Groovy scripting, shell scripts, etc
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

[HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Hi rednoah,

First off awesome work on filebot, this program rocks. Here is a confirmation number for my donation for the work you've already done! Confirmation number: 6A690845FG624934J.

Now if you are still taking requests for donations to modify or create scripts I'd like to hire you to help me automate my media renaming needs as follows:

Currently I put all my video files into a single directory, then I use a .bat file I've created to convert .mkv to .mp4

Code: Select all

set avidemux="C:\Program Files (x86)\Avidemux 2.6\avidemux.exe"
set videocodec=copy
set audiocodec=copy
set outputformat=mkv
for %%f in (*.mkv) do %avidemux% --video-codec %videocodec% --audio-codec %audiocodec% --output-format %outputformat% --force-alt-h264 --load "%%f" --save "%%f.mp4" --quit
move *.mkv c:\downloads\converted\
I do this for use on my ps3 as well I do this before I rename my files as it ends up appending .mkv to the end of my files so "Inception.mkv" becomes "Inception.mkv.mp4".

Next I use the GUI to manually rename my files

TV shows

Code: Select all

{n.replaceTrailingBrackets().replace(':',' -').replace('?','')} - S{s.pad(2)}E{es*.pad(2).join('-E')} - {t.replace(':',' -').replace('?','').replacePart (' (Part $1)')} {('(')+vf.match(/720[pP]|1080[pP]/)+(')')}
Movies

Code: Select all

{n.replace(':',' -').replace('?','')} ({y}){" CD$pi"} {('(')+vf.match(/720[pP]|1080[pP]/)+(')')}
Then I copy them to my 2 removable storage drives into folders such as
/Tv Shows/Game of Thrones/Season 1/
or if they are HD
/TV Shows/Game of Thrones/Season 1 (720p)/

and finally I write a log file for backup purposes that has a date stamp then what I recently added

Code: Select all

April 24, 2014
--------------

=TV Shows=
Game of Thrones s02e02
Game of Thrones s02e02 (720p)

=Kids TV Shows=
Teenage Mutant Ninja Turtles (2013) s01e01

=Movies=
Inception
I'd like to automate this whole process and add a couple features if possible,

Using Utorrent I'd like to trigger either a filebot script or a .bat file that will

1.Convert all my .mkv to .mp4

2.Rename them all automatically (deciding if they are movies or tv shows) and dump them all into a single folder unorganized but renamed using the schemes above.

3.Take these files and copy them onto the removable drives in a folder structure similar to above (ie: /Season #/ for SD and /Season # (720p)/ for HD), however one extra little wrinkle is that some shows are on 1 drive (g:) in a folder called "TV Shows" and some are on the other drive (h:) in a folder called "Kids Shows" so I'd like it to search the kids shows drive first and if the Series folder exists already to copy them there, if it doesn't to copy them to the regular shows drive (creating folders as needed). Also the kids tv shows and movies folders do not need to add the (720p) tag if they are HD, just the TV Shows folder.

4.Append a CSV or text file with the addtions with a time stamp

5.Trigger my plex to rescan itself

6.Send a notification via pushover

Also while renaming the shows I'd either like it to add +1 to the Season number for American Dad as the thetvdb database has shifted seasons (ex the show downloads as S09, however it is actually S10 that is airing) or to just ignore American Dad and I'll do those files manually.

I know 2,5,6 are possible with AMC, and I think 3 is probably possible as well. Not sure about the rest but you are the expert. :)
If a single script is able to do all that then great! If it requires multiple steps in a .bat file that works too, let me know what you think. And if you are up to it I'll send another Donation your way :)

Edit: I don't need it to download subs or nfo or artwork or anything like that, just renaming and sorting.
Edit 2: I should probably mention, I'm running Win 7, UTorrent and the latest version of filebot.
Thanks!

Tweak
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

1. AMC: --def exec
2. AMC 1st call
3. AMC 2nd call with different formats (see the Advanced Formats section)
4. AMC: --def report=y
5. AMC: --def plex=localhost
6. AMC: --def pushover=apikey

AMC 1st call will be normal utorrent usage. Where as you can probably add the AMC 2nd call to utorrent as well like cmd1 && cmd2 but the AMC 2nd would run in standalone-mode on the output of AMC 1st. In standalone mode you have to make sure to set --def excludeList so you only process the new files that weren't there during the previous run of AMC 2nd.

A bit complicated by you can test things step by step. Only 3 is a bit difficult but the format can do all that and there's examples for pretty much that usage in the Shared Formats thread.

PS: You can hire me, but i don't really consider offers for less than $100 :mrgreen:
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

What does AMC - exec do? Is there a thread somewhere with all the different groovy lingo?
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

--def exec is in the AMC docs. You can use it to call programs on newly processed files. For example your video converter.
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

OK, so I'm assuming 1st and 2nd call is in there too? Is this something that will require a batch file or can one complicated string in torrent accomplish all this?
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

I've started everything and so far it seems to be progressing nicely, however I run a script on 10 files and it only processes 9 of them, the 10th sends this error

Code: Select all

Rename episodes using [TheTVDB]
Auto-detected query: [Greys Anatomy]
Fetching episode data for [Grey's Anatomy]
[Fatal Error] :5863:1: XML document structures must start and end within the same entity.
RuntimeException: org.xml.sax.SAXParseException; llineNumber: 5863; columnNumber: 1; XML document structures must start and end within the same entity.
What does that mean?

Thanks,

Tweak
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

Some entry in TheTVDB is borked again.

Do filebot -clear-cache to see if it's been fixed already. And if not run Fiddler2 so you can see the http request filebot is making until you find the one that is broken. Which then needs to be reported to TheTVDB.

PS: I can only try these things myself if I have the file paths.

PS2: If you use the latest beta version you'll get better error messages for this particular case.
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Thanks for your replies rednoah! So TheTVDB gets borked and fixed periodically for some shows? That could explain an issue I've been having with plex not downloading certain meta data the first couple times it tries..thanks for the heads up! Is there a way for filebot to try another DB such as tvrage if TheTVDB fails?

Also I've been tinkering away and I think I'm making good progress so far, as far as my orignal point 3 goes I'm assuming this code snippet is a place to start to get the script to check a drive for a folder first and if it doesn't exist to put it on another?

Code: Select all

{["C:", "D:", "E:"].collect{"$it/TV/$n" as File}.sort{a,b -> a.exists() <=> b.exists() ?: a.root.freeSpace <=> b.root.freeSpace}.last()}/{episode}
something like..

Code: Select all

{["H:", "G:"].collect{"$it/TV/$n" as File}.sort{a,b -> a.exists() <=> b.exists() ?: b.last()}/{episode}
I'm not gonna lie, I have no idea what I'm doing for this chunk but I assume from the start you specify the drives (H: and G:?) and have it evaluate if it exsists or not, I want to to check H:\videos\Kids\ first for the series name and if its not there to default to G:\videos\tv shows\ and create it there..am I on the right track? Any insight?

Also is it possible to have filebot move/organize files w/o renaming them? just scrap all the videos out of a series of folders and put them somewhere else?

Thanks again for your help! I think I may get this to work one day! :D haha

one last question for now, the --def report=y doesn't seem to be generating anything? From searching around ti seems to me it should show up as C:\users\{user}\apdata\roaming\filebot\logs\amc [date].html? The only thing in that folder is amc.txt...?

EDIT:


Ok, I found another code snippet that maybe already does what I want?

Code: Select all

{new File('H:/videos/Kids tv', n).exists() ? 'H:/videos/Kids tv/'+n : 'G:/videos/TV Shows/'+n}/
So if I'm decoding this correct it checks if H:/vidoes/Kids tv/{series name} exists and if so uses that, if not defaults to G:/videos/TV shows/{series name} ..is that correct? If so where would that go in the cmd string? I'm guessing something like

Code: Select all

seriesformat="{new File('H:/videos/Kids tv', n).exists() ? 'H:/videos/Kids tv/'+n : 'G:/videos/TV Shows/'+n}{n.replaceTrailingBrackets().replace(':',' -').replace('?','')} - S{s.pad(2)}E{es*.pad(2).join('-E')} - {t.replace(':',' -').replace('?','').replacePart (' (Part $1)')} {('(')+vf.match(/720[pP]|1080[pP]/)+(')')}
/
But I'm not sure? If I'm on the right track please let me know, I can't test it until late tonightt at the earliest but I'm trying to figure out some stuff while I'm at work lol
-Tweak
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

1.
Can't default between databases. That would probably lead to some weird inconsistencies. Use the latest release and report the URLs that return invalid XML.

2.
You're generally on the right path. There's many different way to do it though. I highly recommend play with it in the GUI Format Editor so you get instant feedback and can play with it until you get it working.

3.
You need the latest revision for --def report=y to work. Then it'll be stored to %FILEBOT_HOME%/reports/AMC <date/time>.html

EDIT: It's --def storeReport=y
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Ok, I'm using the latest stable build I believe, no beta. I'll check Grey's again when I get home and see if the issue is fixed. Also the missing reports were likely due to the wrong --def so that should clear itself up and I'll try what you say by using the GUI to see what happens. I feel like I'm almost there lol.

Was there a way to just sort files into a directory w/o renaming them? Something like "seriesformat:/path/{n}/{file.name]" work?
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

I suppose you mean move and keep the original name, for which you'd use {fn}
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Awesome, thanks :)
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Ok I think I have everything work 95% now! :D

If anyone else is caring, this is the code that pretty much does what I want

Code: Select all

{new File('H:/videos/Kids TV Shows/', n.replace(':',' -').replace('?','')).exists() ? 'H:/videos/Kids TV Shows/'+n.replace(':',' -').replace('?','') : 'G:/videos/TV Shows/'+n.replace(':',' -').replace('?','')}/{'Season ' +s}{(' (')+vf.match(/720[pP]|1080[pP]/)+(')')}/{n.replaceTrailingBrackets().replace(':',' -').replace('?','')} - S{s.pad(2)}E{es*.pad(2).join('-E')} - {t.replace(':',' -').replace('?','').replacePart (' (Part $1)')} {('(')+vf.match(/720[pP]|1080[pP]/)+(')')}
It checks the kids folder on H drive if the series already exists, if so it puts the episodes there, otherwise it puts it onto the G drive and creates a new folder. /Season 1/ or /Season 1 (720p)/ if its HD. I couldn't quite figure out how to have it not care if the kids stuff was HD or not but thats ok since I rarely download any cartoons for them in HD anyways.

Also go the reports working, it seems like it is case sensitive as the only thing I changed was
I guess my only other question (for now lol) is would it be --def storereport=y to --def storeReport=y ..didn't think that was an issue, oh well.

I guess I have 1 last question (for now lol) is it possible to have the reports append each other with the newest at the top of the table instead of a single .html file everytime the script runs? That would be awesome if it was!
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Ok, so I got the reports to append using a couple small lines in a .bat file

Code: Select all

copy /b file1.html + file2.html file1.html
Works good so far!

On some occasions when filebot doesn't actually do anything (ex: if I run the script on an empty folder) it still sends the report but the email is just a blank table, is there a way to tell the groovy file not to send itself out if it hasn't done anywork?

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

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

Use the latest jar and the latest script (with dev:amc) and it should work. Pretty sure I fixed that sometime last week.
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

I'm using the latest stable version, should I be using a beta? Also when you say dev:amc do you mean fn:amc? I'm using a modified version of AMC but its from a version I downloaded last night..?
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

This is the latest script:
https://github.com/filebot/scripts/blob ... amc.groovy

And it'll only work with something very recent:
https://sourceforge.net/projects/filebo ... ebot/HEAD/
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Ok, I'll update to those scripts when I get home. So what does it do if it does no work? Just doesn't save/email the report or does it do something else?

Is it the difference between

Code: Select all

_args.bindings?.each{ _log.finer('Parameter: ' + [it.key, it.key =~ /pushover|pushbullet|gmail|mailto|myepisodes/ ? '*****' : it.value].join(' = ')) }
and this?

Code: Select all

_def.each{ n, v -> log.finer('Parameter: ' + [n, n =~ /pushover|pushbullet|gmail|mailto|myepisodes/ ? '*****' : v].join(' = ')) }
I'm just trying to decipher the code and glean what I can lol
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Just thinking about something we discussed a couple days ago re: TheTVDB not finding a show because of an error on their end...you said filebot can't "fall back" to a different DB if it fails to find a file, but could a workaround be to do a 2nd call of filebot with a different db?

ex:

Code: Select all

filebot -script fn:amc --output "/path/to/output" --log-file amc.log --action move -non-strict "/path/to/input" --def excludeList=amc.txt
followed by

Code: Select all

filebot -script fn:amc --output "/path/to/output" --log-file amc.log --db tvrage --action move -non-strict "/path/to/input" --def excludeList=amc.txt
This would rename and move all files using TheTVDB, then the 2nd call would only try and match whatever was leftover (ie: the files thetvdb couldn't send the data for..?)
Am I way off base here?
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

1.
This is just logging the parameter that have been passed.

This line stops processing before it reaches the reporting code:

Code: Select all

if (getRenameLog().size() == 0) die("Finished without processing any files")
2.
You can't set --db with the amc script. It will be ignored. Just report the issue in TheTVDB and it'll be fixed for everyone.
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Oh ok, I see that now.
Would something like this work to send a pushover notification but not an email / save the log file?
Put this on line 382 where the "die" code is currently

Code: Select all

If (getRenameLog().size() ==0) 
{
     def getNotificationTitle = { "FileBot finished at ${now.format('''[yyyy-MM-dd HH'h'mm'm']}
     def getNotificationMesage = { "Finished without processing any files" }
}
Else
{
     def getNotificationTitle = { "FileBot finished processing ${getRenameLog().size()} files" }.memoize()
     def getNotificationMessage = { prefix = '• ', postfix = '\n' -> tryQuietly{ ut_title } ?: (input.any{ !it.isSubtitle() } ? input.findAll{ !it.isSubtitle() } : input).collect{ relativeInputPath(it) as File }*.getRoot()*.getNameWithoutExtension().unique().sort{ it.toLowerCase() }.collect{ prefix + it + postfix }.join('').trim() }.memoize()
}
and then put this line around line 420 (right before the html table is built)

Code: Select all

if (getRenameLog().size() == 0) die("Finished without processing any files")
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Also, would what need to be changed in the getNotificationMessage to notify of the output not the input?

ps. Thanks alot for your help! I sent you another donation :) Confirmation number: 6DP258081E783281A
User avatar
rednoah
The Source
Posts: 23940
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HIRE REQUEST] Modified AMC script

Post by rednoah »

The above will probably a bad idea since the variable will only be created in the local block scope.

Maybe more like this?

Code: Select all

def getNotificationTitle = (getRenameLog().size() == 0) ? { "FileBot finished at ${now.format('''[yyyy-MM-dd HH'h'mm'm']} : { "FileBot finished processing ${getRenameLog().size()} files" }
As for the output this should get you started:

Code: Select all

def output = getRenameLog().values().toList()
And then apply whatever logic you want to create a message from that list of files.
:idea: Please read the FAQ and How to Request Help.
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Ok, I will give these a shot. Just to be clear I need v4.1 for the devol AMC script or is 4.0 good enough?
Tweak_four17
Donor
Posts: 53
Joined: 24 Apr 2014, 19:30

Re: [HIRE REQUEST] Modified AMC script

Post by Tweak_four17 »

Well I'm stumped :(
My first guess was to def the Output then just replace the getNotificationMessage "input" for "output" no dice. Made about 10 other attempts at random strings that looked like they could work. Best I could get was the output files with the full output path, doesn't leave much room for the message and isn't in nice clear point form when it looks like

"[D:\videos\Tv\Shows\Family Guy\Season 4\Family Guy - S04E05 - EPISODE TITLE,D:\videos\TV Shows\Robot Chicken\Season 3\Robot Chicken - S03E01 - Episode Title,...]"

instead of

"•Family Guy - S04E05 - EPISODE Title
•Robot Chicken - S03-E01 - Episode Title
•..."

Any hints? :D
Post Reply