private System.IO.Stream GetUnsort(int userid) { KodiObject ret = new KodiObject(KodiHelper.NewMediaContainer("Unsort", true)); if (!ret.Init()) { return(new MemoryStream()); } List <Video> dirs = new List <Video>(); ret.MediaContainer.ViewMode = "65586"; ret.MediaContainer.ViewGroup = "video"; VideoLocalRepository repVids = new VideoLocalRepository(); List <VideoLocal> vids = repVids.GetVideosWithoutEpisode(); foreach (VideoLocal v in vids.OrderByDescending(a => a.DateTimeCreated)) { Video m = new Video(); try { KodiHelper.PopulateVideo(m, v, JMMType.File, userid); if (!string.IsNullOrEmpty(m.Duration)) { dirs.Add(m); } } catch (Exception e) { //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null) } } ret.Childrens = dirs; return(ret.GetStream()); }
private System.IO.Stream GetUnsort(int userid, HistoryInfo info) { PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Video, info, true)); if (!ret.Init()) { return(new MemoryStream()); } List <Video> dirs = new List <Video>(); VideoLocalRepository repVids = new VideoLocalRepository(); List <VideoLocal> vids = repVids.GetVideosWithoutEpisode(); foreach (VideoLocal v in vids.OrderByDescending(a => a.DateTimeCreated)) { Video m = new Video(); try { PlexHelper.PopulateVideo(m, v, JMMType.File, userid); m.GrandparentKey = null; if (!string.IsNullOrEmpty(m.Duration)) { dirs.Add(m, info); } } catch (Exception e) { //Fast fix if file do not exist, and still is in db. (Xml Serialization of video info will fail on null) } } ret.Childrens = dirs; return(ret.GetStream()); }
public static void CheckForAniDBFileUpdate(bool forceRefresh) { if (ServerSettings.AniDB_File_UpdateFrequency == ScheduledUpdateFrequency.Never && !forceRefresh) return; int freqHours = Utils.GetScheduledHours(ServerSettings.AniDB_File_UpdateFrequency); // check for any updated anime info every 12 hours ScheduledUpdateRepository repSched = new ScheduledUpdateRepository(); AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.AniDBFileUpdates); if (sched != null) { // if we have run this in the last 12 hours and are not forcing it, then exit TimeSpan tsLastRun = DateTime.Now - sched.LastUpdate; if (tsLastRun.TotalHours < freqHours) { if (!forceRefresh) return; } } UpdateAniDBFileData(true, false, false); // files which have been hashed, but don't have an associated episode VideoLocalRepository repVidLocals = new VideoLocalRepository(); List<VideoLocal> filesWithoutEpisode = repVidLocals.GetVideosWithoutEpisode(); foreach (VideoLocal vl in filesWithoutEpisode) { CommandRequest_ProcessFile cmd = new CommandRequest_ProcessFile(vl.VideoLocalID, true); cmd.Save(); } // now check for any files which have been manually linked and are less than 30 days old if (sched == null) { sched = new ScheduledUpdate(); sched.UpdateType = (int)ScheduledUpdateType.AniDBFileUpdates; sched.UpdateDetails = ""; } sched.LastUpdate = DateTime.Now; repSched.Save(sched); }
public System.IO.Stream GetFilters(string uid) { JMMUser user = KodiHelper.GetUser(uid); if (user == null) { return(new MemoryStream()); } int userid = user.JMMUserID; KodiObject ret = new KodiObject(KodiHelper.NewMediaContainer("Anime", false)); if (!ret.Init()) { return(new MemoryStream()); } List <Video> dirs = new List <Video>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); List <GroupFilter> allGfs = repGF.GetAll(session); Dictionary <int, HashSet <int> > gstats = StatsCache.Instance.StatUserGroupFilter[userid]; foreach (GroupFilter gg in allGfs.ToArray()) { if ((!StatsCache.Instance.StatUserGroupFilter.ContainsKey(userid)) || (!StatsCache.Instance.StatUserGroupFilter[userid].ContainsKey(gg.GroupFilterID))) { allGfs.Remove(gg); } } AnimeGroupRepository repGroups = new AnimeGroupRepository(); allGfs.Insert(0, new GroupFilter() { GroupFilterName = "All", GroupFilterID = -999 }); foreach (GroupFilter gg in allGfs) { Random rnd = new Random(123456789); Directory pp = new Directory(); pp.Key = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetMetadata/" + userid + "/" + (int)JMMType.GroupFilter + "/" + gg.GroupFilterID); pp.PrimaryExtraKey = pp.Key; pp.Title = gg.GroupFilterName; HashSet <int> groups; groups = gg.GroupFilterID == -999 ? new HashSet <int>(repGroups.GetAllTopLevelGroups(session).Select(a => a.AnimeGroupID)) : gstats[gg.GroupFilterID]; if (groups.Count != 0) { bool repeat; int nn = 0; pp.LeafCount = groups.Count.ToString(); pp.ViewedLeafCount = "0"; do { repeat = true; int grp = groups.ElementAt(rnd.Next(groups.Count)); AnimeGroup ag = repGroups.GetByID(grp); List <AnimeSeries> sers = ag.GetSeries(session); if (sers.Count > 0) { AnimeSeries ser = sers[rnd.Next(sers.Count)]; AniDB_Anime anim = ser.GetAnime(session); if (anim != null) { ImageDetails poster = anim.GetDefaultPosterDetailsNoBlanks(session); ImageDetails fanart = anim.GetDefaultFanartDetailsNoBlanks(session); if (poster != null) { pp.Thumb = poster.GenPoster(); } if (fanart != null) { pp.Art = fanart.GenArt(); } if (poster != null) { repeat = false; } } } nn++; if ((repeat) && (nn == 15)) { repeat = false; } } while (repeat); dirs.Add(pp); } } VideoLocalRepository repVids = new VideoLocalRepository(); List <VideoLocal> vids = repVids.GetVideosWithoutEpisode(); if (vids.Count > 0) { JMMContracts.KodiContracts.Directory pp = new JMMContracts.KodiContracts.Directory(); pp.Key = pp.PrimaryExtraKey = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetMetadata/0/" + (int)JMMType.GroupUnsort + "/0"); pp.Title = "Unsort"; pp.Thumb = KodiHelper.ServerUrl(int.Parse(ServerSettings.JMMServerPort), MainWindow.PathAddressKodi + "/GetSupportImage/plex_unsort.png"); pp.LeafCount = vids.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp); } dirs = dirs.OrderBy(a => a.Title).ToList(); } ret.Childrens = dirs; return(ret.GetStream()); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return(new MemoryStream()); } }
public static void RunImport_IntegrityCheck() { VideoLocalRepository repVidLocals = new VideoLocalRepository(); AniDB_FileRepository repAniFile = new AniDB_FileRepository(); AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository(); AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository(); // files which don't have a valid import folder List<VideoLocal> filesToDelete = repVidLocals.GetVideosWithoutImportFolder(); foreach (VideoLocal vl in filesToDelete) repVidLocals.Delete(vl.VideoLocalID); // files which have not been hashed yet // or files which do not have a VideoInfo record List<VideoLocal> filesToHash = repVidLocals.GetVideosWithoutHash(); Dictionary<int, VideoLocal> dictFilesToHash = new Dictionary<int, VideoLocal>(); foreach (VideoLocal vl in filesToHash) { dictFilesToHash[vl.VideoLocalID] = vl; CommandRequest_HashFile cmd = new CommandRequest_HashFile(vl.FullServerPath, false); cmd.Save(); } List<VideoLocal> filesToRehash = repVidLocals.GetVideosWithoutVideoInfo(); Dictionary<int, VideoLocal> dictFilesToRehash = new Dictionary<int, VideoLocal>(); foreach (VideoLocal vl in filesToHash) { dictFilesToRehash[vl.VideoLocalID] = vl; // don't use if it is in the previous list if (!dictFilesToHash.ContainsKey(vl.VideoLocalID)) { try { CommandRequest_HashFile cmd = new CommandRequest_HashFile(vl.FullServerPath, false); cmd.Save(); } catch (Exception ex) { string msg = string.Format("Error RunImport_IntegrityCheck XREF: {0} - {1}", vl.ToStringDetailed(), ex.ToString()); logger.Info(msg); } } } // files which have been hashed, but don't have an associated episode List<VideoLocal> filesWithoutEpisode = repVidLocals.GetVideosWithoutEpisode(); Dictionary<int, VideoLocal> dictFilesWithoutEpisode = new Dictionary<int, VideoLocal>(); foreach (VideoLocal vl in filesWithoutEpisode) dictFilesWithoutEpisode[vl.VideoLocalID] = vl; // check that all the episode data is populated List<VideoLocal> filesAll = repVidLocals.GetAll(); Dictionary<string, VideoLocal> dictFilesAllExisting = new Dictionary<string, VideoLocal>(); foreach (VideoLocal vl in filesAll) { try { dictFilesAllExisting[vl.FullServerPath] = vl; } catch (Exception ex) { string msg = string.Format("Error RunImport_IntegrityCheck XREF: {0} - {1}", vl.ToStringDetailed(), ex.ToString()); logger.Error(msg); continue; } // check if it has an episode if (dictFilesWithoutEpisode.ContainsKey(vl.VideoLocalID)) { CommandRequest_ProcessFile cmd = new CommandRequest_ProcessFile(vl.VideoLocalID, false); cmd.Save(); continue; } // if the file is not manually associated, then check for AniDB_File info AniDB_File aniFile = repAniFile.GetByHash(vl.Hash); foreach (CrossRef_File_Episode xref in vl.EpisodeCrossRefs) { if (xref.CrossRefSource != (int)CrossRefSource.AniDB) continue; if (aniFile == null) { CommandRequest_ProcessFile cmd = new CommandRequest_ProcessFile(vl.VideoLocalID, false); cmd.Save(); continue; } } if (aniFile == null) continue; // the cross ref is created before the actually episode data is downloaded // so lets check for that bool missingEpisodes = false; foreach (CrossRef_File_Episode xref in aniFile.EpisodeCrossRefs) { AniDB_Episode ep = repAniEps.GetByEpisodeID(xref.EpisodeID); if (ep == null) missingEpisodes = true; } if (missingEpisodes) { // this will then download the anime etc CommandRequest_ProcessFile cmd = new CommandRequest_ProcessFile(vl.VideoLocalID, false); cmd.Save(); continue; } } }
public System.IO.Stream GetFilters(string uid) { int t = 0; int.TryParse(uid, out t); JMMUser user = t > 0 ? PlexHelper.GetJMMUser(uid) : PlexHelper.GetUser(uid); if (user == null) { return(new MemoryStream()); } int userid = user.JMMUserID; HistoryInfo info = new HistoryInfo { Key = PlexHelper.ConstructFiltersUrl(userid), Title = "Anime" }; PlexObject ret = new PlexObject(PlexHelper.NewMediaContainer(MediaContainerTypes.Show, info, false)); if (!ret.Init()) { return(new MemoryStream()); } List <Video> dirs = new List <Video>(); try { using (var session = JMMService.SessionFactory.OpenSession()) { GroupFilterRepository repGF = new GroupFilterRepository(); List <GroupFilter> allGfs = repGF.GetAll(session); Dictionary <int, HashSet <int> > gstats = StatsCache.Instance.StatUserGroupFilter[userid]; foreach (GroupFilter gg in allGfs.ToArray()) { if ((!StatsCache.Instance.StatUserGroupFilter.ContainsKey(userid)) || (!StatsCache.Instance.StatUserGroupFilter[userid].ContainsKey(gg.GroupFilterID))) { allGfs.Remove(gg); } } AnimeGroupRepository repGroups = new AnimeGroupRepository(); allGfs.Insert(0, new GroupFilter() { GroupFilterName = "All", GroupFilterID = -999 }); foreach (GroupFilter gg in allGfs) { Random rnd = new Random(123456789); Directory pp = new Directory { Type = "show" }; pp.Key = PlexHelper.ConstructFilterIdUrl(userid, gg.GroupFilterID); pp.Title = gg.GroupFilterName; HashSet <int> groups; groups = gg.GroupFilterID == -999 ? new HashSet <int>(repGroups.GetAllTopLevelGroups(session).Select(a => a.AnimeGroupID)) : gstats[gg.GroupFilterID]; if (groups.Count != 0) { bool repeat; int nn = 0; pp.LeafCount = groups.Count.ToString(); pp.ViewedLeafCount = "0"; do { repeat = true; int grp = groups.ElementAt(rnd.Next(groups.Count)); AnimeGroup ag = repGroups.GetByID(grp); List <AnimeSeries> sers = ag.GetSeries(session); if (sers.Count > 0) { AnimeSeries ser = sers[rnd.Next(sers.Count)]; AniDB_Anime anim = ser.GetAnime(session); if (anim != null) { ImageDetails poster = anim.GetDefaultPosterDetailsNoBlanks(session); ImageDetails fanart = anim.GetDefaultFanartDetailsNoBlanks(session); if (poster != null) { pp.Thumb = poster.GenPoster(); } if (fanart != null) { pp.Art = fanart.GenArt(); } if (poster != null) { repeat = false; } } } nn++; if ((repeat) && (nn == 15)) { repeat = false; } } while (repeat); dirs.Add(pp, info); } } VideoLocalRepository repVids = new VideoLocalRepository(); List <VideoLocal> vids = repVids.GetVideosWithoutEpisode(); if (vids.Count > 0) { Directory pp = new Directory() { Type = "show" }; pp.Key = PlexHelper.ConstructUnsortUrl(userid); pp.Title = "Unsort"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_unsort.png"); pp.LeafCount = vids.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } var repPlaylist = new PlaylistRepository(); var playlists = repPlaylist.GetAll(); if (playlists.Count > 0) { Directory pp = new Directory() { Type = "show" }; pp.Key = PlexHelper.ConstructPlaylistUrl(userid); pp.Title = "Playlists"; pp.Thumb = PlexHelper.ConstructSupportImageLink("plex_playlists.png"); pp.LeafCount = playlists.Count.ToString(); pp.ViewedLeafCount = "0"; dirs.Add(pp, info); } dirs = dirs.OrderBy(a => a.Title).ToList(); } ret.Childrens = dirs; return(ret.GetStream()); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return(new MemoryStream()); } }