public System.IO.Stream Search(string UserId, string limit, string query, bool searchTag) { KodiObject ret = new KodiObject(KodiHelper.NewMediaContainer("Search", false)); ret.MediaContainer.Title2 = "Search Results for '" + query + "'..."; AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); int lim; if (!int.TryParse(limit, out lim)) { lim = 100; } JMMUser user = KodiHelper.GetUser(UserId); if (user == null) { return(new MemoryStream()); } List <Video> ls = new List <Video>(); int cnt = 0; List <AniDB_Anime> animes; if (searchTag) { animes = repAnime.SearchByTag(query); } else { animes = repAnime.SearchByName(query); } foreach (AniDB_Anime anidb_anime in animes) { if (!user.AllowedAnime(anidb_anime)) { continue; } AnimeSeries ser = repSeries.GetByAnimeID(anidb_anime.AnimeID); if (ser != null) { Contract_AnimeSeries cserie = ser.ToContract(ser.GetUserRecord(user.JMMUserID), true); Video v = KodiHelper.FromSerieWithPossibleReplacement(cserie, ser, user.JMMUserID); //proper naming v.OriginalTitle = ""; foreach (AniDB_Anime_Title title in anidb_anime.GetTitles()) { if (title.TitleType == "official" || title.TitleType == "main") { v.OriginalTitle += "{" + title.TitleType + ":" + title.Language + "}" + title.Title + "|"; } } v.OriginalTitle = v.OriginalTitle.Substring(0, v.OriginalTitle.Length - 1); //proper naming end //experiment Characters c = new Characters(); c.CharactersList = new List <Character>(); c.CharactersList = GetCharactersFromAniDB(anidb_anime); v.CharactersList = new List <Characters>(); v.CharactersList.Add(c); //experiment END switch (anidb_anime.AnimeTypeEnum) { case enAnimeType.Movie: v.SourceTitle = "Anime Movies"; break; case enAnimeType.OVA: v.SourceTitle = "Anime Ovas"; break; case enAnimeType.Other: v.SourceTitle = "Anime Others"; break; case enAnimeType.TVSeries: v.SourceTitle = "Anime Series"; break; case enAnimeType.TVSpecial: v.SourceTitle = "Anime Specials"; break; case enAnimeType.Web: v.SourceTitle = "Anime Web Clips"; break; } ls.Add(v); cnt++; if (cnt == lim) { break; } } } ret.MediaContainer.Childrens = ls; return(ret.GetStream()); }