diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs index 0193e66..9454d4a 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeImageProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Globalization; +using System.IO; using System.Linq; using System.Net.Http; using System.Threading; @@ -59,7 +60,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { var list = new List(); var taApi = TubeArchivistApi.GetInstance(); - var videoTAId = item.Path.Split("/").Last().Split(".").First(); + var videoTAId = Utils.GetVideoNameFromPath(item.Path); var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true); _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting images for video: {0} ({1})", video?.Title, videoTAId)); _logger.LogInformation("{Message}", "Thumb URI: " + video?.VidThumbUrl); diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs index 127d8a6..1285423 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/EpisodeMetadataProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Globalization; +using System.IO; using System.Linq; using System.Net.Http; using System.Threading; @@ -50,7 +51,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { var result = new MetadataResult(); var taApi = TubeArchivistApi.GetInstance(); - var videoTAId = info.Path.Split("/").Last().Split(".").First(); + var videoTAId = Utils.GetVideoNameFromPath(info.Path); var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true); _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting metadata for video: {0} ({1})", video?.Title, videoTAId)); _logger.LogInformation("{Message}", "Received metadata: \n" + JsonConvert.SerializeObject(video)); @@ -79,7 +80,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var results = new List(); var taApi = TubeArchivistApi.GetInstance(); - var videoTAId = searchInfo.Path.Split("/").Last().Split(".").First(); + var videoTAId = Utils.GetVideoNameFromPath(searchInfo.Path); var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true); if (video != null) { diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs index 8c240d5..7247103 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesImageProvider.cs @@ -58,7 +58,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { var list = new List(); var taApi = TubeArchivistApi.GetInstance(); - var channelTAId = item.Path.Split("/").Last(); + var channelTAId = Utils.GetChannelNameFromPath(item.Path); var channel = await taApi.GetChannel(channelTAId).ConfigureAwait(true); _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting images for channel: {0} ({1})", channel?.Name, channelTAId)); _logger.LogInformation("{Message}", "Thumb URI: " + channel?.ThumbUrl); diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs index 3a504c2..8b69f97 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Providers/SeriesMetadataProvider.cs @@ -50,7 +50,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers { var result = new MetadataResult(); var taApi = TubeArchivistApi.GetInstance(); - var channelTAId = info.Path.Split("/").Last(); + var channelTAId = Utils.GetChannelNameFromPath(info.Path); var channel = await taApi.GetChannel(channelTAId).ConfigureAwait(true); _logger.LogInformation("{Message}", string.Format(CultureInfo.CurrentCulture, "Getting metadata for channel: {0} ({1})", channel?.Name, channelTAId)); _logger.LogInformation("{Message}", "Received metadata: \n" + JsonConvert.SerializeObject(channel)); @@ -79,7 +79,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers var results = new List(); var taApi = TubeArchivistApi.GetInstance(); - var channelTAId = searchInfo.Path.Split("/").Last(); + var channelTAId = Utils.GetChannelNameFromPath(searchInfo.Path); var channel = await taApi.GetChannel(channelTAId).ConfigureAwait(true); if (channel != null) { diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Utils/Utils.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Utils/Utils.cs index f2849a5..590b253 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Utils/Utils.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Utils/Utils.cs @@ -1,3 +1,5 @@ +using System.IO; +using System.Linq; using System.Text.RegularExpressions; namespace Jellyfin.Plugin.TubeArchivistMetadata.Utilities @@ -53,5 +55,25 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.Utilities return description; } + + /// + /// Get video name from file path on the disk. + /// + /// File path on disk. + /// + public static string GetVideoNameFromPath(string path) + { + return path.Split(Path.DirectorySeparatorChar).Last().Split(".").First(); + } + + /// + /// Get channel name from directory path on the disk. + /// + /// Directory path on disk. + /// + public static string GetChannelNameFromPath(string path) + { + return path.Split(Path.DirectorySeparatorChar).Last(); + } } }