public Episode(string filename) { // we don't need the full path if (filename.Contains("\\")) { filename = filename.Split('\\').ToList().Last(); } StrafeForm.Log("Processing [" + filename + "]"); RawShowName = System.IO.Path.GetFileNameWithoutExtension(filename).ToLower(); string seSubstring = ExtractSE(filename); // eg, S01E01 if (seSubstring == "") { StrafeForm.Log("Can't determine season/episode number"); Error = "Can't determine season/episode number."; } else { StrafeForm.Log("Found SE string: \"" + seSubstring + "\""); // assume everything before the SE string is the show name RawShowName = filename.Substring(0, filename.IndexOf(seSubstring)); } RawShowName = Regex.Replace(RawShowName, @"'", ""); // remove some punctuation RawShowName = Regex.Replace(RawShowName, @"\W", " "); // convert others to spaces RawShowName = Regex.Replace(RawShowName, @"\s+", " "); // consolidate white space RawShowName = RawShowName.Trim(); StrafeForm.Log("Raw show name: \"" + RawShowName + "\""); /* TODO: whenever TheTVDB starts working and I can log in, provide a switch in Config as to which service to get show info from // https://api.thetvdb.com/swagger * for now, we just use TVMaze (which seems to work really well) */ try { TVMaze_Show tvmazeResult = TVMaze.GetShowName(RawShowName); TVMazeId = tvmazeResult.TVMazeId; ShowName = tvmazeResult.ShowName; Year = tvmazeResult.Year; if (Season > 0 || EpisodeNumber > 0) { EpisodeName = TVMaze.GetEpisodeName(TVMazeId, Season, EpisodeNumber); } } catch (TVMazeException tvExc) { Error = tvExc.Message; } }
/// <summary> Query TV Maze and, ideally, return the show's canonical name and id. </summary> public static TVMaze_Show GetShowName(string fileShowName) { ShowMapping showMapping = StrafeForm.Config.ShowMappings.FirstOrDefault(o => o.FileShowName.ToLower() == fileShowName.ToLower() && o.TVSource == ShowMapping.TVSources.TVMaze); if (showMapping != null) { CacheItem showCache = StrafeForm.Cache.Get("http://api.tvmaze.com/shows/" + showMapping.TVMazeId); return(new TVMaze_Show(showCache.JSONResponse.JSON)); } TVMaze_Show result = GetShowName2(fileShowName); StrafeForm.Config.SetTVMazeMapping(fileShowName, result.TVMazeId); StrafeForm.Config.Save(); return(result); }