Extract rar-archives in their folder

I’ve recently began to use Plex more than the XBMC/Kodi server. And the most irritating thing with Plex is that it can’t handle video files inside compressed archives. I need automatic extraction of recently added movies/tv shows.
I have the movies and tv shows in separate root-folders, so the script loop through all the given folders. I don’t want to run several unrar processes at the same time, so a built in pid check was needed. And I don’t want to extract the same archives over and over.
The script will only begin extracting the archive, if it does not find the first listed file inside the archive.
It might need improvement, but for now it seems working fine.

UPDATED: Added support for downloading subtitles through Subliminal.