Using Network Air Date + Time in Post Processing Script

Sonarr version: 2.0.0.5322
Mono version: 5.16.0
OS: Unraid
Debug logs:
Description of issue:

Hi Guys,

So i’ve been encountering the random Mono bug that stops you from setting the modified date of some files. This wouldn’t normally be an issue but i’m using rclone to store a bunch of media in the cloud and each time it re scans it was downloading some files locally to update the air date. To get round this I decided to write a simple post processing script to set the modified date of downloaded files to the Local Air date. Script is below.

#For Testing
#sonarr_episodefile_episodeairdatesutc="9/11/2017 02:00:00"
#sonarr_episodefile_path="/mnt/user/Media/TV_Shows/This Is Us/Season 02/This Is Us - S02E07 - The Most Disappointed Man.mkv"

#Setting TimeZone to UTC
TZUTC='TZ="UTC"'

#Converting Date from DD/MM/YYYY to MM/DD/YYYY so Date doesn't throw invalid date errors.
convert_date=$(echo "${sonarr_episodefile_episodeairdatesutc}" | awk -v FS=/ -v OFS=/ '{print $2,$1,$3}')
touch_date=$(date -d "${TZUTC} ${convert_date}" '+%c')

#Touching file with Air Date
touch -d "${touch_date}" "${sonarr_episodefile_path}"

This works great and it is touching the files with the local air-date and time relative to my time zone.

The problem i have found is if i use the inbuilt “Change File Date” function it set’s the modified date to local time relative to the network it aired on.

For instance if a show airs at 9pm Local time the inbuilt function will touch the file with 9pm the previous night.

If i use my script it will touch it with 11am the next day due to my different timezone.

From what i have read the network/time translation is done either somewhere in the back end.

Unfortunately i can’t see any environment variable with this information that I could incorporate into my script.

For now i’m just using UTC time which is working well, But if there is a way to solve this it would make my OCD Day.

The network/air time translation to UTC is done before it ever reaches Sonarr (In Skyhook, our TVDB proxy).

You’d need to use the episode air date and the series’ air time, that’s what Sonarr does when it’s set to LocalAirDate.

Cool. Is the series air time passed through as a variable? I can see sonarr_episodefile_episodeairdatesutc and sonarr_episodefile_episodeairdates but sonarr_episodefile_episodeairdates just has a date and not time.

The weird thing is if i set “Change File Date” to UTC it marks the modified date as my Local Time. (My Script does this as well)

But if i set it “Local Air Date” then it Mark’s it as the correct Air Time relative to the airing.

1
I’m sure i’m missing something simple but i can’t seem to work it out.

Ok i worked out that i can get the Air Time from the API using Curl but I’ve decided to abandon the idea and stick with UTC time converted to my local time.

If the air time changes it is reflected in the UTC time but not if you use the Air Time.

Might I say you guys have done an amazing job with the API and env variables.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.