From f54dc6b282ef895d6613378ec426fd43ee0c18bb Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 23 Mar 2020 22:40:16 +0100 Subject: [PATCH] Solving another bug with the same public api --- Kyoo/Views/API/SubtitleAPI.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Kyoo/Views/API/SubtitleAPI.cs b/Kyoo/Views/API/SubtitleAPI.cs index 9da62cce..d16435fa 100644 --- a/Kyoo/Views/API/SubtitleAPI.cs +++ b/Kyoo/Views/API/SubtitleAPI.cs @@ -1,4 +1,5 @@ -using Kyoo.Models; +using System; +using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.IO; @@ -23,13 +24,17 @@ namespace Kyoo.Api [HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}.{identifier}.{extension?}")] public IActionResult GetSubtitle(string showSlug, int seasonNumber, int episodeNumber, string identifier, string extension) { - string languageTag = identifier.Substring(0, 3); - bool forced = identifier.Length > 3 && identifier.Substring(4) == "forced"; - Track subtitle = _libraryManager.GetSubtitle(showSlug, seasonNumber, episodeNumber, languageTag, forced); + string languageTag = identifier.Length == 3 ? identifier.Substring(0, 3) : null; + bool forced = identifier.Length > 4 && identifier.Substring(4) == "forced"; + Track subtitle = null; + if (languageTag != null) + subtitle = _libraryManager.GetSubtitle(showSlug, seasonNumber, episodeNumber, languageTag, forced); + if (subtitle == null) { - long.TryParse(identifier.Substring(0, identifier.IndexOf('-')), out long id); + string idString = identifier.IndexOf('-') != -1 ? identifier.Substring(0, identifier.IndexOf('-')) : identifier; + long.TryParse(idString, out long id); subtitle = _libraryManager.GetSubtitleById(id); }