Page 1 of 1

[Script] Relocate files in Radarr / Sonarr

Posted: 24 Aug 2024, 11:30
by rednoah

Relocate movie folder in Radarr

This post-processing script will relocate files in Radarr after moving / renaming files with FileBot.

IMPORTANT: This code assumes that both FileBot and Radarr are working on the same file system view, i.e. target.dir.path set via FileBot must make sense to Radarr, i.e. same machine, no docker volume indirection, no remote network share, etc.

Groovy: Select all

{ source, target ->
	def host = '127.0.0.1'
	def port = 8310
	def auth = 'YOUR_API_KEY'

	def r = curl "http://${host}:${port}/api/v3/movie?tmdbId=${tmdbid}", 'X-Api-Key': auth
	r.each{ m ->
		// parent folder = movie folder
		m.path = target.dir.path
		http 'PUT', "http://${host}:${port}/api/v3/movie/${m.id}", m, 'X-Api-Key': auth

		http 'POST', "http://${host}:${port}/api/v3/command", [name: 'rescanMovie', movieId: m.id], 'X-Api-Key': auth
	}
}


Relocate series folder in Sonarr

This post-processing script will relocate files in Sonarr after moving / renaming files with FileBot.

IMPORTANT: This code assumes that both FileBot and Sonarr are working on the same file system view, i.e. target.dir.dir.path set via FileBot must make sense to Sonarr, i.e. same machine, no docker volume indirection, no remote network share, etc.

Groovy: Select all

{ source, target ->
	def host = '127.0.0.1'
	def port = 8989
	def auth = 'YOUR_API_KEY'

	def r = curl "http://${host}:${port}/api/v3/series?tvdbId=${tvdbid}", 'X-Api-Key': auth
	r.each{ s ->
		// parent folder = season folder
		// parent parent folder = series folder
		s.path = target.dir.dir.path
		http 'PUT', "http://${host}:${port}/api/v3/series/${s.id}", s, 'X-Api-Key': auth

		http 'POST', "http://${host}:${port}/api/v3/command", [name: 'rescanSeries', seriesId: s.id], 'X-Api-Key': auth
	}
}