Fix compatibility with latest Kodi 18
Fix compatibility with latest Kodi 18

file:a/addon.xml -> file:b/addon.xml
--- a/addon.xml
+++ b/addon.xml
@@ -10,7 +10,6 @@
     <extension point="xbmc.addon.metadata">
         <platform>all</platform>
         <language>en es pt fr de ar it ru</language>
-        <reuselanguageinvoker>false</reuselanguageinvoker>
         <summary lang="en_GB">Watch videos from Crunchyroll.com!</summary>
         <summary lang="de_DE">Schaue Videos von Crunchyroll.com!</summary>
         <description lang="en_GB">Crunchyroll is an online video service and community that offers full-length episodes and movies of the very best in Japanese anime and Asian entertainment.</description>

file:a/default.py -> file:b/default.py
--- a/default.py
+++ b/default.py
@@ -32,7 +32,5 @@
 if __name__ == "__main__":
     from resources.lib import crunchyroll
     # start addon
-    crunchyroll.main()
+    crunchyroll.main(sys.argv)
 
-sys.modules.clear()
-

--- a/resources/lib/api.py
+++ b/resources/lib/api.py
@@ -52,10 +52,11 @@
 
     # lets urllib handle cookies
     opener = build_opener(HTTPCookieProcessor(args._cj))
-    opener.addheaders = [("User-Agent",      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"),
+    opener.addheaders = [("User-Agent",      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"),
                          ("Accept-Encoding", "identity"),
                          ("Accept",          "*/*"),
-                         ("Content-Type",    "application/x-www-form-urlencoded")]
+                         ("Content-Type",    "application/x-www-form-urlencoded"),
+                         ("DNT",             "1")]
     install_opener(opener)
 
     # load cookies

--- a/resources/lib/controller.py
+++ b/resources/lib/controller.py
@@ -17,8 +17,6 @@
 
 import re
 import ssl
-import sys
-import json
 import time
 import inputstreamhelper
 
@@ -43,7 +41,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -75,7 +73,7 @@
                        "mode":          "videoplay"},
                       isFolder=False)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -102,7 +100,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -131,7 +129,7 @@
                        "mode":   args.mode},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -150,7 +148,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -190,7 +188,7 @@
                        "mode":   args.mode},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -209,7 +207,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -238,7 +236,7 @@
                        "mode":   args.mode},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -256,7 +254,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -268,7 +266,7 @@
                        "mode":   args.mode},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -284,7 +282,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -307,7 +305,7 @@
                        "mode":          "episodes"},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -325,7 +323,7 @@
     # check for error
     if req["error"]:
         view.add_item(args, {"title": args._addon.getLocalizedString(30061)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         return False
 
     # display media
@@ -360,7 +358,7 @@
                        "mode":          args.mode},
                       isFolder=True)
 
-    view.endofdirectory()
+    view.endofdirectory(args)
     return True
 
 
@@ -375,7 +373,7 @@
     # check for error
     if req["error"]:
         item = xbmcgui.ListItem(getattr(args, "title", "Title not provided"))
-        xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, item)
+        xbmcplugin.setResolvedUrl(int(args._argv[1]), False, item)
         return False
 
     # get stream url
@@ -395,7 +393,7 @@
         item.setProperty("inputstreamaddon", "inputstream.adaptive")
         item.setProperty("inputstream.adaptive.manifest_type", "hls")
         # start playback
-        xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
+        xbmcplugin.setResolvedUrl(int(args._argv[1]), True, item)
 
         # wait for playback
         #xbmcgui.Dialog().notification(args._addonname, args._addon.getLocalizedString(30066), xbmcgui.NOTIFICATION_INFO)

--- a/resources/lib/crunchyroll.py
+++ b/resources/lib/crunchyroll.py
@@ -15,7 +15,6 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import sys
 import random
 import inputstreamhelper
 
@@ -30,10 +29,10 @@
 from . import controller
 
 
-def main():
+def main(argv):
     """Main function for the addon
     """
-    args = model.parse()
+    args = model.parse(argv)
 
     # inputstream adaptive settings
     if hasattr(args, "mode") and args.mode == "hls":
@@ -100,21 +99,21 @@
     if not (username and password):
         # open addon settings
         view.add_item(args, {"title": args._addon.getLocalizedString(30062)})
-        view.endofdirectory()
+        view.endofdirectory(args)
         args._addon.openSettings()
         return False
     else:
         # login
         if api.start(args):
             # list menue
-            xbmcplugin.setContent(int(sys.argv[1]), "tvshows")
+            xbmcplugin.setContent(int(args._argv[1]), "tvshows")
             check_mode(args)
             api.close(args)
         else:
             # login failed
             xbmc.log("[PLUGIN] %s: Login failed" % args._addonname, xbmc.LOGERROR)
             view.add_item(args, {"title": args._addon.getLocalizedString(30060)})
-            view.endofdirectory()
+            view.endofdirectory(args)
             xbmcgui.Dialog().ok(args._addonname, args._addon.getLocalizedString(30060))
             return False
 
@@ -203,7 +202,7 @@
     view.add_item(args,
                   {"title": args._addon.getLocalizedString(30051),
                    "mode":  "drama"})
-    view.endofdirectory()
+    view.endofdirectory(args)
 
 
 def showMainCategory(args, genre):
@@ -241,5 +240,5 @@
                   {"title": args._addon.getLocalizedString(30056),
                    "mode":  "genre",
                    "genre": genre})
-    view.endofdirectory()
-
+    view.endofdirectory(args)
+

--- a/resources/lib/model.py
+++ b/resources/lib/model.py
@@ -23,13 +23,13 @@
     from urllib.parse import parse_qs, unquote_plus
 
 
-def parse():
+def parse(argv):
     """Decode arguments
     """
-    if (sys.argv[2]):
-        return Args(parse_qs(sys.argv[2][1:]))
+    if (argv[2]):
+        return Args(argv, parse_qs(argv[2][1:]))
     else:
-        return Args({})
+        return Args(argv, {})
 
 
 class Args(object):
@@ -38,11 +38,12 @@
     reference to the addon. It is intended to hold all data necessary for the
     script.
     """
-    def __init__(self, kwargs):
+    def __init__(self, argv, kwargs):
         """Initialize arguments object
         Hold also references to the addon which can't be kept at module level.
         """
         self.PY2        = sys.version_info[0] == 2 #: True for Python 2
+        self._argv      = argv
         self._addon     = sys.modules["__main__"]._addon
         self._addonname = sys.modules["__main__"]._plugin
         self._addonid   = sys.modules["__main__"]._plugId

--- a/resources/lib/view.py
+++ b/resources/lib/view.py
@@ -16,7 +16,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import re
-import sys
 try:
     from urllib import quote_plus
 except ImportError:
@@ -35,12 +34,12 @@
          "lastplayed", "album", "artist", "votes", "path", "trailer", "dateadded", "mediatype", "dbid"]
 
 
-def endofdirectory():
+def endofdirectory(args):
     # sort methods are required in library mode
-    xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_NONE)
+    xbmcplugin.addSortMethod(int(args._argv[1]), xbmcplugin.SORT_METHOD_NONE)
 
     # let xbmc know the script is done adding items to the list
-    xbmcplugin.endOfDirectory(handle = int(sys.argv[1]))
+    xbmcplugin.endOfDirectory(handle = int(args._argv[1]))
 
 
 def add_item(args, info, isFolder=True, total_items=0, mediatype="video"):
@@ -82,7 +81,7 @@
                "icon":   info.get("thumb",  "DefaultFolder.png")})
 
     # add item to list
-    xbmcplugin.addDirectoryItem(handle     = int(sys.argv[1]),
+    xbmcplugin.addDirectoryItem(handle     = int(args._argv[1]),
                                 url        = u,
                                 listitem   = li,
                                 isFolder   = isFolder,
@@ -116,7 +115,7 @@
         if value and key in types and not "&" + str(key) + "=" in s:
             s = s + "&" + key + "=" + quote_value(value, args.PY2)
 
-    return sys.argv[0] + "?" + s[1:]
+    return args._argv[0] + "?" + s[1:]
 
 
 def make_infolabel(args, info):