From 6d5a51e831fe6a354557285ad1b823b5e174e709 Mon Sep 17 00:00:00 2001 From: ankenyr Date: Sun, 10 Jul 2022 23:23:20 -0700 Subject: [PATCH] Catching case where the datetime could be null such as when info.json is not present. --- Jellyfin.Plugin.YoutubeMetadata/Utils.cs | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Plugin.YoutubeMetadata/Utils.cs b/Jellyfin.Plugin.YoutubeMetadata/Utils.cs index 0033c6f..7552172 100644 --- a/Jellyfin.Plugin.YoutubeMetadata/Utils.cs +++ b/Jellyfin.Plugin.YoutubeMetadata/Utils.cs @@ -193,7 +193,15 @@ public static MetadataResult YTDLJsonToMovie(YTDLData json) }; result.Item.Name = json.title; result.Item.Overview = json.description; - var date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + var date = new DateTime(1970, 1, 1); + try + { + date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + } + catch + { + + } result.Item.ProductionYear = date.Year; result.Item.PremiereDate = date; result.AddPerson(Utils.CreatePerson(json.uploader, json.channel_id)); @@ -217,7 +225,15 @@ public static MetadataResult YTDLJsonToMusicVideo(YTDLData json) result.Item.Artists = new List { json.artist }; result.Item.Album = json.album; result.Item.Overview = json.description; - var date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + var date = new DateTime(1970, 1, 1); + try + { + date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + } + catch + { + + } result.Item.ProductionYear = date.Year; result.Item.PremiereDate = date; result.AddPerson(Utils.CreatePerson(json.uploader, json.channel_id)); @@ -239,7 +255,15 @@ public static MetadataResult YTDLJsonToEpisode(YTDLData json) }; result.Item.Name = json.title; result.Item.Overview = json.description; - var date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + var date = new DateTime(1970, 1, 1); + try + { + date = DateTime.ParseExact(json.upload_date, "yyyyMMdd", null); + } + catch + { + + } result.Item.ProductionYear = date.Year; result.Item.PremiereDate = date; result.Item.ForcedSortName = date.ToString("yyyyMMdd") + "-" + result.Item.Name;