goose-ws / bash-scripts

A collection of bash scripts I've hacked together over time
MIT License
10 stars 3 forks source link

[Bug] sonarr-update-tba is case sensitive on season and episode searching. #13

Closed K-Money closed 2 months ago

K-Money commented 2 months ago

The below lines 638-641 fail to match if the episode naming convention is "s01e01" rather than "S01E01".

# Define the season and episode numbers epCode="$(grep -Eo "S[[:digit:]]+E[[:digit:]]+" <<<"${file}")" fileSeasonNum="${epCode%E*}" fileSeasonNum="${fileSeasonNum#S}" fileEpisodeNum="${epCode#*E}"

It manifests as a compile error at line 696 since the fileEpisodeNum is blank so this portion encounters the closing ) too soon. jq -M -r ".[] | select(.episodeNumber==${fileEpisodeNum})

I've attached my log output for completeness. log.txt

If I change all of the S to s and E to e in lines 638-641 it works great for me. If there's a way to make the search case insensitive that'd be swell. I did some brief searching but not familiar enough with bash to see an obvious solution for a noob like me.

Thanks for the awesome script!

goose-ws commented 2 months ago

I don't love the idea of making the season/episode lookup case insensitive, as using grep to do it isn't a great way to do it in the first place. But because we have not yet looked up the series ID in Sonarr, it's necessary to parse it from the file name, and I'm just hoping that the S[[:digit:]]+E[[:digit:]]+ regex will match only what I want and nothing else.

Is there any necessary reason your instance lowercases them? It may be safe enough for me to drop the case sensitivity, but I'd like to think on it and do some testing first to see if I notice any increase in erroneous data being picked up.

rr0ss0rr commented 2 months ago

I think you could do [Ss][[:digit:]]+[Ee][[:digit:]]+

K-Money commented 2 months ago

Is there any necessary reason your instance lowercases them?

It's completely an aesthetic thing for me. In the event that I need to go look at the actual files rather than just the sonarr gui then I find it easier visually to scan down the list of filenames and mentally parse them if the numbers are tall and the letters are short.

If it's problematic, I respect that. I always have the option to make the hardcoded tweaks locally and accept the higher risk of false positives to suit my tastes. (:

goose-ws commented 2 months ago

Testing against my library, I don't get any false positives for using lowercase rather than uppercase. I'd rather move away from grep for that search, and see if I can come up with a pure-bash solution that more tightly fits the requirements.

K-Money commented 2 months ago

Thank you!