Make json prefs file valid json.
Use framework functions where possible, set cachetime, use function to create auth header, do not set USERNAME and PASSWORD at the beginning of the script (otherwise those vars will be empty until a user sets them and restarts), add check for OVA/TV and build a correct search URL, do nothing if username/password aren't set.