Rick7C2
September 6, 2017, 7:40pm
1
I am trying to make a script to create dirs and a .strm file with text inside for kodi.
Currently this is my script…
#!/bin/bash
mkdir -p "/downloads/kodi/tv/$sonarr_series_title/Season $sonarr_episodefile_seasonnumber" && echo 'plugin://plugin.video.metalliq/tv/play/$sonarr_series_tvdbid/$sonarr_episodefile_seasonnumber/$sonarr_episodefile_episodenumbers/library' >"/downloads/kodi/tv/$sonarr_series_title/Season $sonarr_episodefile_seasonnumber/$sonarr_series_title - S$sonarr_episodefile_seasonnumberE$sonarr_episodefile_episodenumbers - $sonarr_release_episodeairdates.strm"
The folders are created with correct data but the strm files contents don’t seem to be getting the data from sonarr.
The contents of the strm file are exactly
plugin://plugin.video.metalliq/tv/play/$sonarr_series_tvdbid/$sonarr_episodefile_seasonnumber/$sonarr_episodefile_episodenumbers/library
Instead of passing the actual tvdbid and season episode number.
Why does it work for creating dirs but not for the content in the strm file?
I use this same script with filebot in the past with modified vars and it works fine.
you have double quotes in the mkdir argument, single quotes in the echo statement. I kind of forgot how bash evaluates strings, but I think you need double quotes for it to expand the variables? Someone correct me if I’m wrong.
My diskstation (some flavor of *nix) seems to agree:
Thirrian@DiskStation:~$ test='Hi there!'
Thirrian@DiskStation:~$ echo '$test'
$test
Thirrian@DiskStation:~$ echo "$test"
Hi there!
1 Like
Rick7C2
September 6, 2017, 10:35pm
3
wow I don’t even know how that happened. That was it!
I do have a few more questions though.
How could I get the season number to be two digits? Instead of 1, 01 etc?
Also currently I have to seperate the season and episode vars for them to work S01 E01. Is there a way to make it output S01E01?
Rick7C2
September 7, 2017, 1:40am
4
Ok I have this sofar but still it’s not working as intended
#!/bin/bash
title="$sonarr_series_title"
tvdbid="$sonarr_series_tvdbid"
season=$(printf "%02d\n" "$sonarr_release_seasonnumber")
ep=$(printf "%02d\n" "$sonarr_release_episodenumbers")
airdates="$sonarr_release_episodeairdates"
mkdir -p "/downloads/kodi/tv/$title/Season $season"
echo "plugin://plugin.video.metalliq/tv/play/$tvdbid/$season/$ep/library" >"/downloads/kodi/tv/$title/Season "$season"/$title - S"$season"E"$ep" - "$airdates".strm"
For some reason $season and $ep output “00” for everything now. All I want it to do is output while zero padding single digits.
I’m still learning linux and bash scripting. I used part of this script…
Hey
This is a bit of a how to for a custom script which you can use to mark entries as “seen” in flexget.
You can setup a task with the sonarr flexget integration that purports to get this sort of data from sonarr. But in my early experimentation with sonarr it seems I would need to manually mark stuff as monitored. Also it marks the episode begin number in flexget which is always on the current episode, which would cause it to download again in flexget. Rather than trying to begin from the n…
Also once I finally get this script working right. Is there a way to run it for all completed episodes in sonarr?
No clue what’s wrong with your printf statements…
Not the most elegant, but…
season=$sonarr_release_seasonnumber
ep=$sonarr_release_episodenumbers
if [ $season -lt 10 ]
then
season="0"$season
fi
if [ $ep -lt 10 ]
then
ep="0"$episode
fi
This will pad seasons/episodes below 10 with a leading zero.
Probably not the neatest, I’m sure some guru can rewrite this in 2 lines tops, but hey, it works…
Disclaimer: I have no idea how it will behave with multi-episode files.
Rick7C2
September 8, 2017, 9:28pm
6
Sorry for the late reply. Internet went out before I could post my findings.
I figured why my printfs statements weren’t working.
I copied them from the other script I used as reference and the vars were wrong in it.
I overlooked it when copy pasting.
$sonarr_release_seasonnumber & $sonarr_release_episodenumbers
should be
$sonarr_episodefile_seasonnumber & $sonarr_episodefile_episodenumbers
when used On Download/On Upgrade. As stated here…
One final thing. Is there anyway to run this script for all episodes already downloaded?
If not i’m sure there is a way to do it with bash only. Maybe you could point me in the direction?
I’m thinking using “find” command to list all episodes and a way to save the required data to the above vars and run the above script in a loop for each file?
Gotta do some research.
Thanks @Thirrian for all your help!
Rick7C2
September 9, 2017, 1:16am
7
Ok just got it figured out.
Here is what I did.
Created bash script strmgen.sh
#!/bin/bash
title=`echo "$1" | grep -oP '(?<=TV Shows.).+(?=.Season)'`
airdates=`echo "$1" | grep -oP '(\d\d\d\d-\d\d-\d\d)'`
season=`echo "$1" | grep -oP '(?<=S)\d+'`
ep=`echo "$1" | grep -oP '((?<=E)\d+)'`
title2=`echo $title | sed 's| |%20|g'`
tvdbid=`curl "http://thetvdb.com/api/GetSeries.php?seriesname=$title2" -s | grep -oP '(?<=<id>)\d+(?=</id>)'`
mkdir -p "/downloads/kodi/tv/$title/Season $season"
echo "plugin://plugin.video.metalliq/tv/play/$tvdbid/$season/$ep/library" >"/downloads/kodi/tv/$title/Season "$season"/$title - S"$season"E"$ep" - "$airdates".strm"
##Test
##echo "/downloads/kodi/tv/$title/Season $season"
##echo "plugin://plugin.video.metalliq/tv/play/$tvdbid/$season/$ep/library"
##echo "/downloads/kodi/tv/$title/Season "$season"/$title - S"$season"E"$ep" - "$airdates".strm"
Then I run the find command…
find "/Media Server/TV Shows" -type f -exec /volume1/downloads/scripts/strmgen.sh "{}" \;
Find returns the full path to my media files.
An example…
/Media Server\TV Shows\Adam Ruins Everything\Season 02\Adam Ruins Everything - S02E01 - 2017-07-11 - Adam Ruins Having a Baby WEBDL-1080p.mkv
My script then extracts the data from folder and file names and then grabs the tvdbid from tvdb api.
Now I wonder if it could have been done easier? haha
D’oh! That makes two of us
Glad everything is working now!
1 Like
system
Closed
November 8, 2017, 7:01am
9
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.