From ea6a9b39896499f359898c3d4dfab89a3c102489 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@openshell.no>
Date: Tue, 19 Oct 2021 15:06:49 +0200
Subject: [PATCH 1/5] kodi_version default to 18 or 19 based on python version

---
 jellyfin_kodi/helper/utils.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/jellyfin_kodi/helper/utils.py b/jellyfin_kodi/helper/utils.py
index f9ef3c34..38ce9155 100644
--- a/jellyfin_kodi/helper/utils.py
+++ b/jellyfin_kodi/helper/utils.py
@@ -36,7 +36,12 @@ def addon_id():
 def kodi_version():
     # Kodistubs returns empty string, causing Python 3 tests to choke on int()
     # TODO: Make Kodistubs version configurable for testing purposes
-    version_string = xbmc.getInfoLabel('System.BuildVersion') or "19.1 (19.1.0) Git:20210509-85e05228b4"
+    if sys.version_info.major == 2:
+        default_versionstring = "18"
+    else:
+        default_versionstring = "19.1 (19.1.0) Git:20210509-85e05228b4"
+
+    version_string = xbmc.getInfoLabel('System.BuildVersion') or default_versionstring
     return int(version_string.split(' ', 1)[0].split('.', 1)[0])
 
 

From 7dffe005119879b5a620f993b6ffe35aaf15b000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@openshell.no>
Date: Tue, 19 Oct 2021 15:08:50 +0200
Subject: [PATCH 2/5] Avoid circular imports of database

---
 jellyfin_kodi/objects/actions.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/jellyfin_kodi/objects/actions.py b/jellyfin_kodi/objects/actions.py
index c8618c33..06a73d55 100644
--- a/jellyfin_kodi/objects/actions.py
+++ b/jellyfin_kodi/objects/actions.py
@@ -10,7 +10,6 @@ from datetime import timedelta
 
 from kodi_six import xbmc, xbmcgui, xbmcplugin, xbmcaddon
 
-from .. import database
 from ..helper import translate, playutils, api, window, settings, dialog
 from ..dialogs import resume
 from ..helper import LazyLogger
@@ -724,6 +723,7 @@ def on_update(data, server):
 
         return
 
+    from .. import database
     item = database.get_item(kodi_id, media)
 
     if item:
@@ -767,6 +767,7 @@ def on_play(data, server):
         return
 
     if settings('useDirectPaths') == '1' or media == 'song':
+        from .. import database
         item = database.get_item(kodi_id, media)
 
         if item:

From a9c7f1ba09c697b2c79aa556113bfea0573dee4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@openshell.no>
Date: Tue, 19 Oct 2021 15:34:32 +0200
Subject: [PATCH 3/5] Add test to just import all modules

---
 tests/test_imports.py | 107 ++++++++++++++++++++++++++++++++++++++++++
 tox.ini               |   1 +
 2 files changed, 108 insertions(+)
 create mode 100644 tests/test_imports.py

diff --git a/tests/test_imports.py b/tests/test_imports.py
new file mode 100644
index 00000000..7946604a
--- /dev/null
+++ b/tests/test_imports.py
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+from __future__ import division, absolute_import, print_function, unicode_literals
+
+
+def test_import_main_module():
+    import jellyfin_kodi  # noqa: F401
+
+
+def test_import_client():
+    import jellyfin_kodi.client  # noqa: F401
+
+
+def test_import_connect():
+    import jellyfin_kodi.connect  # noqa: F401
+
+
+def test_import_database():
+    import jellyfin_kodi.database
+    import jellyfin_kodi.database.jellyfin_db
+    import jellyfin_kodi.database.queries  # noqa: F401
+
+
+def test_import_dialogs():
+    import jellyfin_kodi.dialogs
+    import jellyfin_kodi.dialogs.context
+    import jellyfin_kodi.dialogs.loginmanual
+    import jellyfin_kodi.dialogs.resume
+    import jellyfin_kodi.dialogs.serverconnect
+    import jellyfin_kodi.dialogs.servermanual
+    import jellyfin_kodi.dialogs.usersconnect  # noqa: F401
+
+
+def test_import_downloader():
+    import jellyfin_kodi.downloader  # noqa: F401
+
+
+def test_import_entrypoint():
+    import jellyfin_kodi.entrypoint
+    import jellyfin_kodi.entrypoint.context
+    # import jellyfin_kodi.entrypoint.default  # FIXME: Messes with sys.argv
+    import jellyfin_kodi.entrypoint.service  # noqa: F401
+
+
+def test_import_full_sync():
+    import jellyfin_kodi.full_sync  # noqa: F401
+
+
+def test_import_helper():
+    import jellyfin_kodi.helper
+    import jellyfin_kodi.helper.api
+    import jellyfin_kodi.helper.exceptions
+    import jellyfin_kodi.helper.lazylogger
+    import jellyfin_kodi.helper.loghandler
+    import jellyfin_kodi.helper.playutils
+    import jellyfin_kodi.helper.translate
+    import jellyfin_kodi.helper.utils
+    import jellyfin_kodi.helper.wrapper
+    import jellyfin_kodi.helper.xmls  # noqa: F401
+
+
+def test_import_jellyfin():
+    import jellyfin_kodi.jellyfin
+    import jellyfin_kodi.jellyfin.api
+    import jellyfin_kodi.jellyfin.client
+    import jellyfin_kodi.jellyfin.configuration
+    import jellyfin_kodi.jellyfin.connection_manager
+    import jellyfin_kodi.jellyfin.credentials
+    import jellyfin_kodi.jellyfin.http
+    import jellyfin_kodi.jellyfin.utils
+    import jellyfin_kodi.jellyfin.ws_client  # noqa: F401
+
+
+def test_import_library():
+    import jellyfin_kodi.library  # noqa: F401
+
+
+def test_import_monitor():
+    import jellyfin_kodi.monitor  # noqa: F401
+
+
+def test_import_objects():
+    import jellyfin_kodi.objects
+    import jellyfin_kodi.objects.actions
+    import jellyfin_kodi.objects.kodi
+    import jellyfin_kodi.objects.kodi.artwork
+    import jellyfin_kodi.objects.kodi.kodi
+    import jellyfin_kodi.objects.kodi.movies
+    import jellyfin_kodi.objects.kodi.music
+    import jellyfin_kodi.objects.kodi.musicvideos
+    import jellyfin_kodi.objects.kodi.queries
+    import jellyfin_kodi.objects.kodi.queries_music
+    import jellyfin_kodi.objects.kodi.queries_texture
+    import jellyfin_kodi.objects.kodi.tvshows
+    import jellyfin_kodi.objects.movies
+    import jellyfin_kodi.objects.music
+    import jellyfin_kodi.objects.musicvideos
+    import jellyfin_kodi.objects.obj
+    import jellyfin_kodi.objects.tvshows
+    import jellyfin_kodi.objects.utils  # noqa: F401
+
+
+def test_import_player():
+    import jellyfin_kodi.player  # noqa: F401
+
+
+def test_import_views():
+    import jellyfin_kodi.views  # noqa: F401
diff --git a/tox.ini b/tox.ini
index a9af6783..e8ea3d1c 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,6 +6,7 @@ extend-ignore =
     I202
 per-file-ignores =
     */__init__.py: F401
+    tests/test_imports.py: F401
 
 [pytest]
 minversion = 4.6

From c72318e19dff9c602b62bcc891d607be552304b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@openshell.no>
Date: Tue, 19 Oct 2021 15:35:17 +0200
Subject: [PATCH 4/5] Fully qualify the imports from jellyfin_kodi.entrypoint

---
 context.py                           | 2 +-
 context_play.py                      | 2 +-
 default.py                           | 2 +-
 jellyfin_kodi/entrypoint/__init__.py | 4 ----
 service.py                           | 2 +-
 5 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/context.py b/context.py
index 0326e073..c1cdbcd0 100644
--- a/context.py
+++ b/context.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
 
 #################################################################################################
 
-from jellyfin_kodi.entrypoint import Context
+from jellyfin_kodi.entrypoint.context import Context
 from jellyfin_kodi.helper import LazyLogger
 
 #################################################################################################
diff --git a/context_play.py b/context_play.py
index c2fcc774..b0744f8c 100644
--- a/context_play.py
+++ b/context_play.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
 
 #################################################################################################
 
-from jellyfin_kodi.entrypoint import Context
+from jellyfin_kodi.entrypoint.context import Context
 from jellyfin_kodi.helper import LazyLogger
 
 #################################################################################################
diff --git a/default.py b/default.py
index ac86b22a..7a25d5f1 100644
--- a/default.py
+++ b/default.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera
 
 #################################################################################################
 
-from jellyfin_kodi.entrypoint import Events
+from jellyfin_kodi.entrypoint.default import Events
 from jellyfin_kodi.helper import LazyLogger
 
 #################################################################################################
diff --git a/jellyfin_kodi/entrypoint/__init__.py b/jellyfin_kodi/entrypoint/__init__.py
index 82e8ff62..22273fd5 100644
--- a/jellyfin_kodi/entrypoint/__init__.py
+++ b/jellyfin_kodi/entrypoint/__init__.py
@@ -6,8 +6,4 @@ from __future__ import division, absolute_import, print_function, unicode_litera
 from ..helper import LazyLogger
 from ..jellyfin import Jellyfin
 
-from .default import Events
-from .service import Service
-from .context import Context
-
 #################################################################################################
diff --git a/service.py b/service.py
index d725b37c..9ffa713b 100644
--- a/service.py
+++ b/service.py
@@ -7,7 +7,7 @@ import threading
 
 from kodi_six import xbmc
 
-from jellyfin_kodi.entrypoint import Service
+from jellyfin_kodi.entrypoint.service import Service
 from jellyfin_kodi.helper.utils import settings
 from jellyfin_kodi.helper import LazyLogger
 

From 862b2274e1193d7ecebc138967f138ced507ac81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@openshell.no>
Date: Tue, 19 Oct 2021 16:29:22 +0200
Subject: [PATCH 5/5] Fix bug in add_movie query introduced by #581

---
 jellyfin_kodi/objects/kodi/queries.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py
index 61081321..b4c32cf5 100644
--- a/jellyfin_kodi/objects/kodi/queries.py
+++ b/jellyfin_kodi/objects/kodi/queries.py
@@ -286,7 +286,7 @@ VALUES          (?, ?, ?, ?)
 add_movie = """
 INSERT INTO     movie(idMovie, idFile, c00, c01, c02, c03, c04, c05, c06, c07,
                 c09, c10, c11, c12, c14, c15, c16, c18, c19, c21, premiered)
-VALUES          (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+VALUES          (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 """
 add_movie_obj = ["{MovieId}", "{FileId}", "{Title}", "{Plot}", "{ShortPlot}", "{Tagline}",
                  "{Votes}", "{RatingId}", "{Writers}", "{Year}", "{Unique}", "{SortTitle}",