private MediaContainer GetFromFile(IProvider prov, int userid, string Id, BreadCrumbs info)
 {
     int id;
     if (!int.TryParse(Id, out id))
         return new MediaContainer() { ErrorString = "Invalid File Id" };
     VideoLocal vi = RepoFactory.VideoLocal.GetByID(id);
     BaseObject ret =
         new BaseObject(prov.NewMediaContainer(MediaContainerTypes.File,
             Path.GetFileNameWithoutExtension(vi.FileName ?? ""),
             true, false, info));
     Video v2 = Helper.VideoFromVideoLocal(prov, vi, userid);
     List<Video> dirs = new List<Video>();
     dirs.EppAdd(prov, v2, info, true);
     v2.Thumb = Helper.ConstructSupportImageLink("plex_404.png");
     v2.ParentThumb = Helper.ConstructSupportImageLink("plex_unsort.png");
     if (prov.ConstructFakeIosParent)
         v2.GrandparentKey =
             prov.Proxyfy(prov.ConstructFakeIosThumb(userid, v2.ParentThumb,
                 v2.Art ?? v2.ParentArt ?? v2.GrandparentArt));
     v2.ParentKey = null;
     if (prov.UseBreadCrumbs)
         v2.Key = prov.ShortUrl(ret.MediaContainer.Key);
     ret.MediaContainer.Childrens = dirs;
     return ret.GetStream(prov);
 }
        private MediaContainer GetFromEpisode(IProvider prov, int userid, string Id, BreadCrumbs info)
        {
            int id;
            if (!int.TryParse(Id, out id))
                return new MediaContainer() { ErrorString = "Invalid Episode Id" };
            BaseObject ret =
                new BaseObject(prov.NewMediaContainer(MediaContainerTypes.Episode, "Episode", true, true, info));
            using (var session = DatabaseFactory.SessionFactory.OpenSession())
            {
                List<Video> dirs = new List<Video>();
                ISessionWrapper sessionWrapper = session.Wrap();

                AnimeEpisode e = RepoFactory.AnimeEpisode.GetByID(id);
                if (e == null)
                    return new MediaContainer() { ErrorString = "Invalid Episode Id" };
                KeyValuePair<AnimeEpisode, Contract_AnimeEpisode> ep =
                    new KeyValuePair<AnimeEpisode, Contract_AnimeEpisode>(e,
                        e.GetUserContract(userid));
                if (ep.Value != null && ep.Value.LocalFileCount == 0)
                    return new MediaContainer() { ErrorString = "Episode do not have videolocals" };
                AniDB_Episode aep = ep.Key.AniDB_Episode;
                if (aep == null)
                    return new MediaContainer() { ErrorString = "Invalid Episode AniDB link not found" };
                AnimeSeries ser = RepoFactory.AnimeSeries.GetByID(ep.Key.AnimeSeriesID);
                if (ser == null)
                    return new MediaContainer() { ErrorString = "Invalid Serie" };
                AniDB_Anime anime = ser.GetAnime();
                Contract_AnimeSeries con = ser.GetUserContract(userid);
                if (con == null)
                    return new MediaContainer() { ErrorString = "Invalid Serie, Contract not found" };
                try
                {
                    Video v = Helper.VideoFromAnimeEpisode(prov, con.CrossRefAniDBTvDBV2, ep, userid);
                    if (v != null)
                    {
                        Video nv = ser.GetPlexContract(userid);
                        Helper.AddInformationFromMasterSeries(v, con, ser.GetPlexContract(userid), prov is KodiProvider);
                        if (v.Medias != null && v.Medias.Count > 0)
                        {
                            v.Type = "episode";
                            dirs.EppAdd(prov, v, info, true);
                            if (prov.ConstructFakeIosParent)
                                v.GrandparentKey =
                                    prov.Proxyfy(prov.ConstructFakeIosThumb(userid, v.ParentThumb,
                                        v.Art ?? v.ParentArt ?? v.GrandparentArt));
                            v.ParentKey = null;
                        }
                        if (prov.UseBreadCrumbs)
                            v.Key = prov.ShortUrl(ret.MediaContainer.Key);
                        ret.MediaContainer.Art = Helper.ReplaceSchemeHost(nv.Art ?? nv.ParentArt ?? nv.GrandparentArt);
                    }
                    ret.MediaContainer.Childrens = dirs;
                    return ret.GetStream(prov);
                }
                catch (Exception ex)
                {
                    //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null)
                }
            }
            return new MediaContainer() { ErrorString = "Episode Not Found" };
        }