From d67affc4590b1430347706c1bd55fb4fc0e8595d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@gmail.com>
Date: Sat, 29 Oct 2022 15:59:27 +0200
Subject: [PATCH 1/3] Set premiere date

---
 jellyfin_kodi/objects/kodi/queries.py | 4 ++--
 jellyfin_kodi/objects/movies.py       | 1 +
 jellyfin_kodi/objects/obj_map.json    | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/jellyfin_kodi/objects/kodi/queries.py b/jellyfin_kodi/objects/kodi/queries.py
index b4c32cf5..f35f333b 100644
--- a/jellyfin_kodi/objects/kodi/queries.py
+++ b/jellyfin_kodi/objects/kodi/queries.py
@@ -291,7 +291,7 @@ VALUES          (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 add_movie_obj = ["{MovieId}", "{FileId}", "{Title}", "{Plot}", "{ShortPlot}", "{Tagline}",
                  "{Votes}", "{RatingId}", "{Writers}", "{Year}", "{Unique}", "{SortTitle}",
                  "{Runtime}", "{Mpaa}", "{Genre}", "{Directors}", "{Title}", "{Studio}",
-                 "{Trailer}", "{Country}", "{Year}"]
+                 "{Trailer}", "{Country}", "{Premiere}"]
 add_rating = """
 INSERT INTO     rating(rating_id, media_id, media_type, rating_type, rating, votes)
 VALUES          (?, ?, ?, ?, ?, ?)
@@ -405,7 +405,7 @@ WHERE       idMovie = ?
 update_movie_obj = ["{Title}", "{Plot}", "{ShortPlot}", "{Tagline}", "{Votes}", "{RatingId}",
                     "{Writers}", "{Year}", "{Unique}", "{SortTitle}", "{Runtime}",
                     "{Mpaa}", "{Genre}", "{Directors}", "{Title}", "{Studio}", "{Trailer}",
-                    "{Country}", "{Year}", "{MovieId}"]
+                    "{Country}", "{Premiere}", "{MovieId}"]
 update_rating = """
 UPDATE      rating
 SET         media_id = ?, media_type = ?, rating_type = ?, rating = ?, votes = ?
diff --git a/jellyfin_kodi/objects/movies.py b/jellyfin_kodi/objects/movies.py
index 45cf2e07..1a6356c4 100644
--- a/jellyfin_kodi/objects/movies.py
+++ b/jellyfin_kodi/objects/movies.py
@@ -94,6 +94,7 @@ class Movies(KodiDb):
         obj['Video'] = API.video_streams(obj['Video'] or [], obj['Container'])
         obj['Audio'] = API.audio_streams(obj['Audio'] or [])
         obj['Streams'] = API.media_streams(obj['Video'], obj['Audio'], obj['Subtitles'])
+        obj['Premiere'] = Local(obj['Premiere']).split('.')[0].replace('T', " ") or obj['Year']
 
         self.get_path_filename(obj)
         self.trailer(obj)
diff --git a/jellyfin_kodi/objects/obj_map.json b/jellyfin_kodi/objects/obj_map.json
index 557d4331..5da5ce31 100644
--- a/jellyfin_kodi/objects/obj_map.json
+++ b/jellyfin_kodi/objects/obj_map.json
@@ -13,6 +13,7 @@
 		"UniqueId": "ProviderIds/Imdb",
 		"Rating": "CommunityRating",
 		"Year": "ProductionYear",
+        "Premiere": "PremiereDate",
 		"Votes": "VoteCount",
 		"Plot": "Overview",
 		"ShortPlot": "ShortOverview",
@@ -359,4 +360,4 @@
 		"rating": "CommunityRating",
 		"firstaired": "ProductionYear"
 	}
-}
\ No newline at end of file
+}

From c1f79000c731338b0336b7f9e9509ec05969fe03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@gmail.com>
Date: Sat, 29 Oct 2022 16:49:16 +0200
Subject: [PATCH 2/3] Fix syncing when Premiere date is empty

---
 jellyfin_kodi/objects/movies.py    | 3 ++-
 jellyfin_kodi/objects/obj_map.json | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/jellyfin_kodi/objects/movies.py b/jellyfin_kodi/objects/movies.py
index 1a6356c4..6406e094 100644
--- a/jellyfin_kodi/objects/movies.py
+++ b/jellyfin_kodi/objects/movies.py
@@ -94,7 +94,8 @@ class Movies(KodiDb):
         obj['Video'] = API.video_streams(obj['Video'] or [], obj['Container'])
         obj['Audio'] = API.audio_streams(obj['Audio'] or [])
         obj['Streams'] = API.media_streams(obj['Video'], obj['Audio'], obj['Subtitles'])
-        obj['Premiere'] = Local(obj['Premiere']).split('.')[0].replace('T', " ") or obj['Year']
+        if obj['Premiere'] is not None:
+            obj['Premiere'] = obj['Premiere'].split('T')[0]
 
         self.get_path_filename(obj)
         self.trailer(obj)
diff --git a/jellyfin_kodi/objects/obj_map.json b/jellyfin_kodi/objects/obj_map.json
index 5da5ce31..6d530df7 100644
--- a/jellyfin_kodi/objects/obj_map.json
+++ b/jellyfin_kodi/objects/obj_map.json
@@ -13,7 +13,7 @@
 		"UniqueId": "ProviderIds/Imdb",
 		"Rating": "CommunityRating",
 		"Year": "ProductionYear",
-        "Premiere": "PremiereDate",
+        "Premiere": "PremiereDate,ProductionYear",
 		"Votes": "VoteCount",
 		"Plot": "Overview",
 		"ShortPlot": "ShortOverview",

From e9e346b5ed50c3713f3d4fc21fad14a14e7c6595 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= <oddstr13@gmail.com>
Date: Sat, 29 Oct 2022 23:23:07 +0200
Subject: [PATCH 3/3] Fix indentation

---
 .editorconfig                      | 3 +++
 jellyfin_kodi/objects/obj_map.json | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/.editorconfig b/.editorconfig
index ea78396a..5542b65a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -26,3 +26,6 @@ indent_size = 2
 
 [resources/settings.xml]
 indent_style = tab
+
+[jellyfin_kodi/objects/obj_map.json]
+indent_style = tab
diff --git a/jellyfin_kodi/objects/obj_map.json b/jellyfin_kodi/objects/obj_map.json
index 6d530df7..e503bf69 100644
--- a/jellyfin_kodi/objects/obj_map.json
+++ b/jellyfin_kodi/objects/obj_map.json
@@ -13,7 +13,7 @@
 		"UniqueId": "ProviderIds/Imdb",
 		"Rating": "CommunityRating",
 		"Year": "ProductionYear",
-        "Premiere": "PremiereDate,ProductionYear",
+		"Premiere": "PremiereDate,ProductionYear",
 		"Votes": "VoteCount",
 		"Plot": "Overview",
 		"ShortPlot": "ShortOverview",