Need help converting my .bat file to python (almost done just need help on one thing)

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Need help converting my .bat file to python (almost done just need help on one thing)

Post by ZeroByDivide »

so I decided to look into switching up my bat file I've been using for the past few months or so in favor of using python. So I decided to go and grab the "utorrent-postprocess.pyw" and start my work on it to get it to my liking, so far I've gotten everything I have wanted so far done on it other than one small thing I can't figure out.

1. A while back I got help on this thread viewtopic.php?t=4768 and ended up with a groovy script for sonarr in the end, things have been working great so far with it and everything, but this is where the issue comes in. the bit that I uses the sonarr groovy script doesn't seem to run in python. I am currently using

Code: Select all

exec="filebot -script %UPSR% --def id={id}"
in my bat script which works but upon trying to switch and apply it

Code: Select all

'exec=' + 'filebot', '-script', UPSR, '--def id={id}'
to the python script just ends up throwing an error.

Code: Select all

Illegal Argument: java.nio.file.NoSuchFileException: C:\Windows\system32\{id} ({id})
No such property: id for class: Script1
Possible solutions: log, now, _def
groovy.lang.MissingPropertyException: No such property: id for class: Script1
Possible solutions: log, now, _def
	at Script1.run(Script1.groovy:2)
	at net.filebot.cli.ScriptShell.evaluate(ScriptShell.java:64)
	at net.filebot.cli.ScriptShell.runScript(ScriptShell.java:74)
	at net.filebot.cli.ArgumentProcessor.runScript(ArgumentProcessor.java:127)
	at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:29)
	at net.filebot.Main.main(Main.java:111)

Failure (°_°)
idk if I messed up somewhere or what exactly happened. If I take out my sonarr stuff

Code: Select all

'exec=' + 'filebot', '-script', UPSR, '--def id={id}'
the python script runs perfectly, but I'd love to be able to keep my sonarr script moving into python..

This is my current python script (with the sonarr stuff included)

Code: Select all

# Media file processing script for Filebot
# CLI https://www.filebot.net/cli.html
# Format https://www.filebot.net/naming.html
# Forums https://www.filebot.net/forums

# Qbittorrent Call ---
# "C:/Users/JourneyOver/Dropbox/Public/Folders/Filebot/MyStuff/Filebot_Wrapper.pyw" "%L" "" "%N" "multi" "" "%F"

import os
import sys
import subprocess

# Set up some logging
LOGDIR = os.path.expanduser(os.sep.join(["~","Dropbox/Public/Folders/Filebot/logs"]))

# Groovy Script Locations
UPSR = os.path.expanduser(os.sep.join(["~","Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy"]))

# Base destinations to move files, no trailing slash. The subfolder is defined in the format string.
DESTINATION = 'D:/Shows'

# Rename action i.e: move | copy | keeplink | symlink | hardlink
ACTION = 'Move'

# Conflict resolution i.e: override | skip | fail
CONFLICT = 'Override'

# custom formats
#FILTERPATH = "@/" + os.path.expanduser(os.sep.join(["~","Dropbox/Public/Folders/Filebot/MyStuff/Filter.txt"]))
FORMATPATH = "@/" + os.path.expanduser(os.sep.join(["~","Dropbox/Public/Folders/Filebot/MyStuff/Formatting.txt"]))

# Old Age Filter Format
FILTERPATH2 = 'any{ age < 170 }{ airdate ? true : false }'

# Process Music Files
MUSIC = 'false'

# Download subtitles for the given languages i.e: en | de | fr
SUBTITLES = 'en'

# Fetch Artwork/NFO
ARTWORK = 'false'

# Generate *.url files and fetch all available backdrops
EXTRAS  = 'false'

# Tell the given Kodi/XBMN instance to rescan it's library
#Kodi = 'host[:port]'

# Tell the given Plex instance to rescan it's library. Plex Home instances require an authentication token
PLEX = 'localhost:'

# Tell the given Emby instance to rescan it's library
#EMBY = 'host:apikey'

# Save reports to local filesystem
STOREREPORT = 'false'

# Skip extracting file
SKIPEXTRACT = 'false'

# Automatically remove empty folders and clutter files that may be left behind after moving the video files, or temporary extracted files after copying
CLEAN = 'true'

# Delete archives after extraction
DELETEAFTEREXTRACT = 'true'

# required args
label, state, title, kind, file, directory = sys.argv[1:7]

command = [
  'filebot', '-script', 'fn:amc',
  '--output', DESTINATION,
  '--action', ACTION,
  '--conflict', CONFLICT,
  '-non-strict',
  '-no-xattr',
  '--filter',
    FILTERPATH2,
  '--log-file', LOGDIR + '/filebot-amc.log',
  '--def',
     FORMATPATH,
    'excludeList=' + LOGDIR + '/filebot-history.log',
    'music=' + MUSIC,
    'subtitles=' + SUBTITLES,
    'artwork=' + ARTWORK,
    'extras=' + EXTRAS,
    'storeReport=' + STOREREPORT,
    'skipExtract=' + SKIPEXTRACT,
    'clean=' + CLEAN,
    'deleteAfterExtract=' + DELETEAFTEREXTRACT,
    'plex=' + PLEX,
    'ut_label=' + label,
    'ut_state=' + state,
    'ut_title=' + title,
    'ut_kind='  + kind,
    'ut_file='  + file,
    'ut_dir='   + directory,
    'exec=' + 'filebot', '-script', UPSR, '--def id={id}'
]

# execute command (and hide cmd window)
subprocess.run(command, creationflags=0x08000000)
Last edited by ZeroByDivide on 11 May 2018, 21:14, edited 2 times in total.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by ZeroByDivide »

Tbh I could of probably of posted this in "Scripting and Automation" but egh to late I guess.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by rednoah »

The exec=/script bit should be a single argument.

e.g.

Code: Select all

'exec=filebot -script /path/to/script.groovy --def id={id}'
:idea: Please read the FAQ and How to Request Help.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by ZeroByDivide »

rednoah wrote: 26 Nov 2017, 10:38 The exec=/script bit should be a single argument.

e.g.

Code: Select all

'exec=filebot -script /path/to/script.groovy --def id={id}'
That seems to have fixed the {id} issue that I was having

Code: Select all

Run script [fn:amc] at [Sun Nov 26 06:11:48 CST 2017]
Parameter: seriesFormat = /TV Shows/{N}/{episode.special ? 'Specials' : 'Season '+s.pad(2)}/{N.replaceTrailingBrackets()} - {episode.special ? 'S00E'+special.pad(2) : S00E00} - {T.replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')}
Parameter: animeFormat = /Anime/{N}/{episode.special ? 'Specials' : 'Season '+s.pad(2)}/{N.replaceTrailingBrackets()} - {episode.special ? 'S00E'+special.pad(2) : S00E00} - {T.replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')}
Parameter: movieFormat = /Movies/{N.replaceTrailingBrackets().replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')} [{y}]/{N.replaceTrailingBrackets().replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')} [{y}]
Parameter: excludeList = C:\Users\JourneyOver\Dropbox/Public/Folders/Filebot/logs/filebot-history.log
Parameter: music = false
Parameter: subtitles = en
Parameter: artwork = false
Parameter: extras = false
Parameter: storeReport = false
Parameter: skipExtract = false
Parameter: clean = true
Parameter: deleteAfterExtract = true
Parameter: plex = *****
Parameter: ut_label = 
Parameter: ut_state = 
Parameter: ut_title = Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Parameter: ut_kind = multi
Parameter: ut_file = 
Parameter: ut_dir = C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Parameter: exec = filebot -script UPSR --def id={id}
Use excludes: C:\Users\JourneyOver\Dropbox\Public\Folders\Filebot\logs\filebot-history.log
Input: C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv
Group: [tvs:z nation] => [Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv]
Get [English] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
No matching subtitles found: C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv
Rename episodes using [TheTVDB]
Auto-detected query: [Z Nation]
Fetching episode data for [Z Nation]
Fetching episode data for [HD Nation]
Fetching episode data for [Ham Nation]
Fetching episode data for [Magi-Nation]
Fetching episode data for [Alien Nation]
Apply filter [any{ age < 170 }{ airdate ? true : false }] on [535] items
Include [Z Nation - 4x01 - Warren's Dream]
Include [Z Nation - 4x02 - Escape from Zona]
Include [Z Nation - 4x03 - The Vanishing]
Include [Z Nation - 4x04 - A New Mission: Keep Moving]
Include [Z Nation - 4x05 - The Unknowns]
Include [Z Nation - 4x06 - Back From the Undead]
Include [Z Nation - 4x07 - Warren's Wedding]
Include [Z Nation - 4x08 - Crisis of Faith]
Include [Z Nation - 4x09 - We Interrupt This Program]
Include [Z Nation - 4x10 - Frenemies]
Include [Z Nation - 4x11 - Return to Mercy Labs]
Include [Z Nation - 4x12 - Mt. Weather]
Include [Z Nation - 4x13 - The Black Rainbow]
[MOVE] from [C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv] to [D:\Shows\TV Shows\Z Nation\Season 04\Z Nation - S04E09 - We Interrupt This Program.mkv]
Processed 1 files
Execute: filebot -script UPSR --def id=280494
Notify Plex: [host:localhost, token:]
GET: http://localhost:32400/library/sections/all/refresh?X-Plex-Token=
Clean clutter files and empty folders
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0001.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0002.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0003.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0004.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.nfo
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Done ヾ(@⌒ー⌒@)ノ
so thanks on that, but looks like doing that doesn't allow variables like

Code: Select all

# Groovy Script Locations
UPSR = os.path.expanduser(os.sep.join(["~", "Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy"]))

'exec=filebot -script UPSR --def id={id}'
to have it see it as

Code: Select all

filebot -script C:\Users\JourneyOver\Dropbox\Public\Folders\Filebot\MyStuff\update-sonarr.groovy --def id={id}

:( guess I'll have to hardcode it for now.
Last edited by ZeroByDivide on 11 May 2018, 21:13, edited 1 time in total.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by ZeroByDivide »

Anyone mind helping me on that last little bit above with the

Code: Select all

# Groovy Script Locations
UPSR = os.path.expanduser(os.sep.join(["~", "Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy"]))

'exec=filebot -script UPSR --def id={id}'
if I run my script it executes part of it correctly and gets the ID but it doesn't seem to understand the UPSR part so it doesn't end up changing it to look like so

Code: Select all

filebot -script C:\Users\JourneyOver\Dropbox\Public\Folders\Filebot\MyStuff\update-sonarr.groovy --def id={id}
it just ends up showing as for example:

Code: Select all

Execute: filebot -script UPSR --def id=280494
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by rednoah »

1.
Have you tried this?

Code: Select all

'exec=filebot -script ' + UPSR + ' --def id={id}'

2.
I'd recommend having your script in the $PATH so you can do this:

Code: Select all

--def exec="update-sonarr {id}"
Your update-sonarr shell script would then do the rest, which may just be calling filebot, or may be calling something else if you find a better solution.
:idea: Please read the FAQ and How to Request Help.
ZeroByDivide
Posts: 170
Joined: 16 Dec 2014, 01:39

Re: Need help converting my .bat file to python (almost done just need help on one thing)

Post by ZeroByDivide »

rednoah wrote: 27 Nov 2017, 12:05 1.
Have you tried this?

Code: Select all

'exec=filebot -script ' + UPSR + ' --def id={id}'

2.
I'd recommend having your script in the $PATH so you can do this:

Code: Select all

--def exec="update-sonarr {id}"
Your update-sonarr shell script would then do the rest, which may just be calling filebot, or may be calling something else if you find a better solution.
First setup seems to have made it work :D

Code: Select all

Run script [fn:amc] at [Mon Nov 27 12:03:00 CST 2017]
Parameter: seriesFormat = /TV Shows/{N}/{episode.special ? 'Specials' : 'Season '+s.pad(2)}/{N.replaceTrailingBrackets()} - {episode.special ? 'S00E'+special.pad(2) : S00E00} - {T.replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')}
Parameter: animeFormat = /Anime/{N}/{episode.special ? 'Specials' : 'Season '+s.pad(2)}/{N.replaceTrailingBrackets()} - {episode.special ? 'S00E'+special.pad(2) : S00E00} - {T.replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')}
Parameter: movieFormat = /Movies/{N.replaceTrailingBrackets().replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')} [{y}]/{N.replaceTrailingBrackets().replaceAll(/[!?.]+$/).replaceAll(/[\`´‘’ʻ]/, "'").lowerTrail().replacePart(', Part $1')} [{y}]
Parameter: excludeList = C:\Users\JourneyOver\Dropbox/Public/Folders/Filebot/logs/filebot-history.log
Parameter: music = false
Parameter: subtitles = en
Parameter: artwork = false
Parameter: extras = false
Parameter: storeReport = false
Parameter: skipExtract = false
Parameter: clean = true
Parameter: deleteAfterExtract = true
Parameter: plex = *****
Parameter: ut_label = 
Parameter: ut_state = 
Parameter: ut_title = Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Parameter: ut_kind = multi
Parameter: ut_file = 
Parameter: ut_dir = C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Parameter: exec = filebot -script C:\Users\JourneyOver\Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy --def id={id}
Use excludes: C:\Users\JourneyOver\Dropbox\Public\Folders\Filebot\logs\filebot-history.log
Input: C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv
Group: [tvs:z nation] => [Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv]
Get [English] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
No matching subtitles found: C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv
Rename episodes using [TheTVDB]
Auto-detected query: [Z Nation]
Fetching episode data for [Z Nation]
Fetching episode data for [HD Nation]
Fetching episode data for [Ham Nation]
Fetching episode data for [Magi-Nation]
Fetching episode data for [Alien Nation]
Apply filter [any{ age < 170 }{ airdate ? true : false }] on [535] items
Include [Z Nation - 4x01 - Warren's Dream]
Include [Z Nation - 4x02 - Escape from Zona]
Include [Z Nation - 4x03 - The Vanishing]
Include [Z Nation - 4x04 - A New Mission: Keep Moving]
Include [Z Nation - 4x05 - The Unknowns]
Include [Z Nation - 4x06 - Back From the Undead]
Include [Z Nation - 4x07 - Warren's Wedding]
Include [Z Nation - 4x08 - Crisis of Faith]
Include [Z Nation - 4x09 - We Interrupt This Program]
Include [Z Nation - 4x10 - Frenemies]
Include [Z Nation - 4x11 - Return to Mercy Labs]
Include [Z Nation - 4x12 - Mt. Weather]
Include [Z Nation - 4x13 - The Black Rainbow]
[MOVE] from [C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.mkv] to [D:\Shows\TV Shows\Z Nation\Season 04\Z Nation - S04E09 - We Interrupt This Program.mkv]
Processed 1 files
Execute: filebot -script C:\Users\JourneyOver\Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy --def id=280494
Notify Plex: [host:localhost, token:]
GET: http://localhost:32400/library/sections/all/refresh?X-Plex-Token=
Clean clutter files and empty folders
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0001.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0002.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0003.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens\screen0004.png
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta.nfo
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta\Screens
Delete C:\Users\JourneyOver\Desktop\QBT\Z.Nation.S04E09.iNTERNAL.720p.HEVC.x265-MeGusta
Done ヾ(@⌒ー⌒@)ノ
Now that I have all that done and my old batch script converted to a python script I can start working on adding various other little features to it.
Post Reply