devster wrote: ↑26 Nov 2017, 17:11
I would like to know how you keep your own version of the script in sync with what rednoah has on github.
There is nothing that you have to keep in sync with, as the sonarr groovy script is not really dependent on anything other than just filebot so you once you get things configured you will more than likely never have to update the script again unless something on sonarrs side changes.
devster wrote: ↑26 Nov 2017, 17:11
I'm also missing a crucial step in your
refreshSonarrLibrary function.
It seems that you're collecting all episodes of a series or a season before sending the notification via an API call, do I read it right or am I missing something?
This script will send off the API call per torrent and tell it to scan the show folder for the ID (it gets the ID from tvdb and matches it to tvdb ID through sonarrs API) that matches the episode that gets processed, the current iteration that is in this thread is just for using with tv shows (sonarr) but I have made some edits of my own to make it work with movies (radarr) as well.
Code: Select all
// The TVDB/TMDB ID
def id = id as int
// Sonarr API Configuration
def url = new URL('http://localhost:8989')
def header = ['X-Api-Key': 'PLACESONARRAPIKEYHERE']
def sonarrSeriesId = new JsonSlurper()
.parseText(new URL(url, '/api/series')
.get(header)
.text)
.find {
it.tvdbId == id
}.id
println new URL(url, '/api/command').post(
JsonOutput.toJson(
[name: 'rescanSeries', seriesId: sonarrSeriesId]
).getBytes('UTF-8'),
'application/json',
header
).text
// Radarr API Configuration
def url2 = new URL('http://localhost:7878')
def header2 = ['X-Api-Key': 'PLACERADARRAPIKEYHERE']
def radarrMovieId = new JsonSlurper()
.parseText(new URL(url2, '/api/movie')
.get(header2)
.text)
.find {
it.tmdbId == id
}.id
println new URL(url2, '/api/command').post(
JsonOutput.toJson(
[name: 'rescanMovie', movieId: radarrMovieId]
).getBytes('UTF-8'),
'application/json',
header2
).text
it could probably be condensed down a slight bit but it works.
to make it work with filebot, make a .groovy file with the above code in it, and then you'd add
Code: Select all
exec="filebot -script path/to/script.groovy --def id={id}"
at the end of your filebot command. like in this for example --
Code: Select all
@ECHO OFF
:: 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.bat" "%N" "%F"
:: Set up some logging
set LOGDIR=%userprofile%/Dropbox/Public/Folders/Filebot/logs
:: Groovy Script Location
set UPSR=%userprofile%/Dropbox/Public/Folders/Filebot/MyStuff/update-sonarr.groovy
:: Base destinations to move files, no trailing slash. The subfolder is defined in the format string.
set DESTINATION=D:/Shows
:: Passing Args from Qbittorrent
set TORRENT_NAME=%1
set TORRENT_PATH=%2
::set TORRENT_LABEL=%3
:: Rename action i.e: move | copy | keeplink | symlink | hardlink
set ACTION=move
:: Conflict resolution i.e: override | skip | fail
set CONFLICT=override
:: Paths for format and filter
::set FILTERPATH="@/%userprofile%/Dropbox/Public/Folders/Filebot/MyStuff/Filter.txt"
set FORMATPATH="@/%userprofile%/Dropbox/Public/Folders/Filebot/MyStuff/Formatting.txt"
:: Old Age Filter Format
set FILTERPATH2="any{ age < 170 }{ airdate ? true : false }"
:: Process music files
set MUSIC=false
:: Download subtitles for the given languages i.e: en | de | fr
set SUBTITLES=en
:: Fetch artwork/nfo
set ARTWORK=false
:: Generate *.url files and fetch all available backdrops
set EXTRAS=false
:: Tell the given Kodi/XBMC instance to rescan it's library
::Set KODI=host[:port]
:: Tell the given Plex instance to rescan it's library. Plex Home instances require an authentication token
set PLEX=host:apikey
:: Tell the given Emby instance to rescan it's library
::set EMBY=host:apikey
:: Save reports to local filesystem
set STOREREPORT=false
:: Do not extract archives
set 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
set CLEAN=true
:: Delete archives after extraction
set DELETEAFTEREXTRACT=true
:: Run filebot script
filebot -script fn:amc ^
--output "%DESTINATION%" ^
--log-file "%LOGDIR%/filebot-amc.log" ^
--action %ACTION% ^
--conflict %CONFLICT% ^
-non-strict ^
-no-xattr ^
--filter ^
%FILTERPATH2% ^
--def ^
ut_dir=%TORRENT_PATH% ^
ut_kind=multi ^
ut_title=%TORRENT_NAME% ^
excludeList="%LOGDIR%/filebot-history.log" ^
music=%MUSIC% ^
subtitles=%SUBTITLES% ^
artwork=%ARTWORK% ^
extras=%EXTRAS% ^
plex="%PLEX%" ^
storeReport=%STOREREPORT% ^
skipExtract=%SKIPEXTRACT% ^
clean=%CLEAN% ^
deleteAfterExtract=%DELETEAFTEREXTRACT% ^
%FORMATPATH% ^
exec="filebot -script %UPSR% --def id={id}"
or if using python you'd do
Code: Select all
'exec=filebot -script path/to/script.groovy --def id={id}'
like example --
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
# required args
label, state, title, kind, file, directory = sys.argv[1:7]
# 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 | test
ACTION = 'Move'
# Conflict resolution i.e: override | skip | auto | index | 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
if label == "tv-sonarr":
FILTERPATH2 = 'any{ age < 7 }{ airdate ? true : false }'
else:
FILTERPATH2 = 'any{ age < 5000 }{ airdate ? true : false }'
# Process Music Files
MUSIC = 'false'
# Download subtitles for the given languages i.e: en, de, fr, es, ja, zh, ...
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 = 'host:apikey'
# 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'
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)