Beispiel #1
0
        public List<Contract_VideoLocal> GetVideoLocalsForAnime(int animeID, int userID)
        {
            List<Contract_VideoLocal> contracts = new List<Contract_VideoLocal>();
            try
            {

                VideoLocalRepository repVids = new VideoLocalRepository();
                foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(animeID))
                {
                    contracts.Add(vid.ToContract(userID));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Beispiel #2
0
        public string UpdateAnimeData(int animeID)
        {
            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    JMMService.AnidbProcessor.GetAnimeInfoHTTP(session, animeID, true, false);

                    // also find any files for this anime which don't have proper media info data
                    // we can usually tell this if the Resolution == '0x0'
                    VideoLocalRepository repVids = new VideoLocalRepository();
                    AniDB_FileRepository repFiles = new AniDB_FileRepository();

                    foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(session, animeID))
                    {
                        AniDB_File aniFile = vid.GetAniDBFile(session);
                        if (aniFile == null) continue;

                        if (aniFile.File_VideoResolution.Equals("0x0", StringComparison.InvariantCultureIgnoreCase))
                        {
                            CommandRequest_GetFile cmd = new CommandRequest_GetFile(vid.VideoLocalID, true);
                            cmd.Save(session);
                        }
                    }

                    // update group status information
                    CommandRequest_GetReleaseGroupStatus cmdStatus = new CommandRequest_GetReleaseGroupStatus(animeID, true);
                    cmdStatus.Save(session);
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return "";
        }
Beispiel #3
0
        public List<Contract_GroupVideoQuality> GetGroupVideoQualitySummary(int animeID)
        {
            List<Contract_GroupVideoQuality> vidQuals = new List<Contract_GroupVideoQuality>();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            VideoLocalRepository repVids = new VideoLocalRepository();
            AniDB_FileRepository repAniFile = new AniDB_FileRepository();

            try
            {
                DateTime start = DateTime.Now;
                TimeSpan ts = DateTime.Now - start;

                double totalTiming = 0;
                double timingAnime = 0;
                double timingVids = 0;
                double timingEps = 0;
                double timingAniEps = 0;
                double timingAniFile = 0;
                double timingVidInfo = 0;
                double timingContracts = 0;

                DateTime oStart = DateTime.Now;

                start = DateTime.Now;
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                ts = DateTime.Now - start;
                timingAnime += ts.TotalMilliseconds;

                if (anime == null) return vidQuals;

                start = DateTime.Now;
                List<VideoLocal> vids = repVids.GetByAniDBAnimeID(animeID);
                ts = DateTime.Now - start;
                timingVids += ts.TotalMilliseconds;

                foreach (VideoLocal vid in vids)
                {
                    start = DateTime.Now;
                    List<AnimeEpisode> eps = vid.GetAnimeEpisodes();
                    ts = DateTime.Now - start;
                    timingEps += ts.TotalMilliseconds;

                    if (eps.Count == 0) continue;
                    foreach (AnimeEpisode animeEp in eps)
                    {
                        //AnimeEpisode animeEp = eps[0];
                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode || animeEp.EpisodeTypeEnum == enEpisodeType.Special)
                        {
                            start = DateTime.Now;
                            AniDB_Episode anidbEp = animeEp.AniDB_Episode;
                            ts = DateTime.Now - start;
                            timingAniEps += ts.TotalMilliseconds;

                            // get the anibd file info
                            start = DateTime.Now;
                            AniDB_File aniFile = vid.GetAniDBFile();
                            ts = DateTime.Now - start;
                            timingAniFile += ts.TotalMilliseconds;
                            if (aniFile != null)
                            {
                                start = DateTime.Now;
                                VideoInfo vinfo = vid.VideoInfo;
                                ts = DateTime.Now - start;
                                timingVidInfo += ts.TotalMilliseconds;
                                int bitDepth = 8;
                                if (vinfo != null)
                                {
                                    if (!int.TryParse(vinfo.VideoBitDepth, out bitDepth))
                                        bitDepth = 8;
                                }

                                string vidResAniFile = Utils.GetStandardisedVideoResolution(aniFile.File_VideoResolution);

                                // match based on group / video sorce / video res
                                bool foundSummaryRecord = false;
                                foreach (Contract_GroupVideoQuality contract in vidQuals)
                                {
                                    string contractSource = SimplifyVideoSource(contract.VideoSource);
                                    string fileSource = SimplifyVideoSource(aniFile.File_Source);

                                    string vidResContract = Utils.GetStandardisedVideoResolution(contract.Resolution);

                                    if (contract.GroupName.Equals(aniFile.Anime_GroupName, StringComparison.InvariantCultureIgnoreCase) &&
                                        contractSource.Equals(fileSource, StringComparison.InvariantCultureIgnoreCase) &&
                                        vidResContract.Equals(vidResAniFile, StringComparison.InvariantCultureIgnoreCase) &&
                                        contract.VideoBitDepth == bitDepth)
                                    {
                                        foundSummaryRecord = true;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                        contract.TotalFileSize += vid.FileSize;
                                        contract.TotalRunningTime += aniFile.File_LengthSeconds;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                        {
                                            if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                        }
                                    }
                                }
                                if (!foundSummaryRecord)
                                {
                                    Contract_GroupVideoQuality contract = new Contract_GroupVideoQuality();
                                    contract.FileCountNormal = 0;
                                    contract.FileCountSpecials = 0;
                                    contract.TotalFileSize = 0;
                                    contract.TotalRunningTime = 0;

                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                    contract.TotalFileSize += vid.FileSize;
                                    contract.TotalRunningTime += aniFile.File_LengthSeconds;

                                    contract.GroupName = aniFile.Anime_GroupName;
                                    contract.GroupNameShort = aniFile.Anime_GroupNameShort;
                                    contract.VideoBitDepth = bitDepth;
                                    contract.Resolution = vidResAniFile;
                                    contract.VideoSource = SimplifyVideoSource(aniFile.File_Source);
                                    contract.Ranking = Utils.GetOverallVideoSourceRanking(contract.Resolution, contract.VideoSource, bitDepth);
                                    contract.NormalEpisodeNumbers = new List<int>();
                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                    {
                                        if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                            contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                    }

                                    vidQuals.Add(contract);
                                }
                            }
                            else
                            {
                                // look at the Video Info record
                                VideoInfo vinfo = vid.VideoInfo;
                                if (vinfo != null)
                                {
                                    int bitDepth = 8;
                                    if (vinfo != null)
                                    {
                                        if (!int.TryParse(vinfo.VideoBitDepth, out bitDepth))
                                            bitDepth = 8;
                                    }

                                    string vidResInfo = Utils.GetStandardisedVideoResolution(vinfo.VideoResolution);

                                    bool foundSummaryRecord = false;
                                    foreach (Contract_GroupVideoQuality contract in vidQuals)
                                    {
                                        string vidResContract = Utils.GetStandardisedVideoResolution(contract.Resolution);

                                        if (contract.GroupName.Equals(Constants.NO_GROUP_INFO, StringComparison.InvariantCultureIgnoreCase) &&
                                            contract.VideoSource.Equals(Constants.NO_SOURCE_INFO, StringComparison.InvariantCultureIgnoreCase) &&
                                            vidResContract.Equals(vidResInfo, StringComparison.InvariantCultureIgnoreCase) &&
                                            contract.VideoBitDepth == bitDepth)
                                        {
                                            foundSummaryRecord = true;
                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                            contract.TotalFileSize += vinfo.FileSize;
                                            contract.TotalRunningTime += vinfo.Duration;

                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                            {
                                                if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                    contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                            }
                                        }
                                    }
                                    if (!foundSummaryRecord)
                                    {
                                        Contract_GroupVideoQuality contract = new Contract_GroupVideoQuality();
                                        contract.FileCountNormal = 0;
                                        contract.FileCountSpecials = 0;
                                        contract.TotalFileSize = 0;
                                        contract.TotalRunningTime = 0;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                        contract.TotalFileSize += vinfo.FileSize;
                                        contract.TotalRunningTime += vinfo.Duration;

                                        contract.GroupName = Constants.NO_GROUP_INFO;
                                        contract.GroupNameShort = Constants.NO_GROUP_INFO;
                                        contract.Resolution = vidResInfo;
                                        contract.VideoSource = Constants.NO_SOURCE_INFO;
                                        contract.VideoBitDepth = bitDepth;
                                        contract.Ranking = Utils.GetOverallVideoSourceRanking(contract.Resolution, contract.VideoSource, bitDepth);
                                        contract.NormalEpisodeNumbers = new List<int>();
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                        {
                                            if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                        }
                                        vidQuals.Add(contract);
                                    }
                                }
                            }
                        }
                    }
                }

                start = DateTime.Now;
                foreach (Contract_GroupVideoQuality contract in vidQuals)
                {
                    contract.NormalComplete = contract.FileCountNormal >= anime.EpisodeCountNormal;
                    contract.SpecialsComplete = (contract.FileCountSpecials >= anime.EpisodeCountSpecial) && (anime.EpisodeCountSpecial > 0);

                    contract.NormalEpisodeNumberSummary = "";
                    contract.NormalEpisodeNumbers.Sort();
                    int lastEpNum = 0;
                    int baseEpNum = 0;
                    foreach (int epNum in contract.NormalEpisodeNumbers)
                    {
                        if (baseEpNum == 0)
                        {
                            baseEpNum = epNum;
                            lastEpNum = epNum;
                        }

                        if (epNum == lastEpNum) continue;

                        int epNumDiff = epNum - lastEpNum;
                        if (epNumDiff == 1)
                        {
                            lastEpNum = epNum;
                            continue;
                        }

                        // this means we have missed an episode
                        if (contract.NormalEpisodeNumberSummary.Length > 0)
                            contract.NormalEpisodeNumberSummary += ", ";

                        if (baseEpNum == lastEpNum)
                            contract.NormalEpisodeNumberSummary += string.Format("{0}", baseEpNum);
                        else
                            contract.NormalEpisodeNumberSummary += string.Format("{0}-{1}", baseEpNum, lastEpNum);

                        lastEpNum = epNum;
                        baseEpNum = epNum;

                    }

                    if (contract.NormalEpisodeNumbers.Count > 0)
                    {
                        if (contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1] >= baseEpNum)
                        {
                            // this means we have missed an episode
                            if (contract.NormalEpisodeNumberSummary.Length > 0)
                                contract.NormalEpisodeNumberSummary += ", ";

                            if (baseEpNum == contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1])
                                contract.NormalEpisodeNumberSummary += string.Format("{0}", baseEpNum);
                            else
                                contract.NormalEpisodeNumberSummary += string.Format("{0}-{1}", baseEpNum, contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1]);
                        }
                    }
                }
                ts = DateTime.Now - start;
                timingContracts += ts.TotalMilliseconds;

                ts = DateTime.Now - oStart;
                totalTiming = ts.TotalMilliseconds;

                string msg2 = string.Format("Timing for video quality {0} ({1}) : {2}/{3}/{4}/{5}/{6}/{7}/{8}  (AID: {9})", anime.MainTitle, totalTiming, timingAnime, timingVids,
                            timingEps, timingAniEps, timingAniFile, timingVidInfo, timingContracts, anime.AnimeID);
                logger.Debug(msg2);

                vidQuals.Sort();
                return vidQuals;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return vidQuals;
            }
        }
Beispiel #4
0
        public List<Contract_AnimeSeries> GetSeriesWithoutAnyFiles(int userID)
        {
            List<Contract_AnimeSeries> contracts = new List<Contract_AnimeSeries>();

            VideoLocalRepository repVids = new VideoLocalRepository();
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

            try
            {
                foreach (AnimeSeries ser in repSeries.GetAll())
                {
                    if (repVids.GetByAniDBAnimeID(ser.AniDB_ID).Count == 0)
                    {
                        contracts.Add(ser.ToContract(ser.GetUserRecord(userID)));
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return contracts;
        }
Beispiel #5
0
        public List<Contract_GroupFileSummary> GetGroupFileSummary(int animeID)
        {
            List<Contract_GroupFileSummary> vidQuals = new List<Contract_GroupFileSummary>();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            VideoLocalRepository repVids = new VideoLocalRepository();
            AniDB_FileRepository repAniFile = new AniDB_FileRepository();

            try
            {
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);

                if (anime == null) return vidQuals;

                List<VideoLocal> vids = repVids.GetByAniDBAnimeID(animeID);

                foreach (VideoLocal vid in vids)
                {
                    if (vid.FilePath.Contains(@"[DB]_Naruto_Shippuuden_078-079_[0DFB6FE0]"))
                        Debug.Write("Test");

                    List<AnimeEpisode> eps = vid.GetAnimeEpisodes();

                    if (eps.Count == 0) continue;

                    foreach (AnimeEpisode animeEp in eps)
                    {
                        //AnimeEpisode animeEp = eps[0];
                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode || animeEp.EpisodeTypeEnum == enEpisodeType.Special)
                        {
                            AniDB_Episode anidbEp = animeEp.AniDB_Episode;

                            // get the anibd file info
                            AniDB_File aniFile = vid.GetAniDBFile();
                            if (aniFile != null)
                            {
                                // match based on group / video sorce / video res
                                bool foundSummaryRecord = false;
                                foreach (Contract_GroupFileSummary contract in vidQuals)
                                {
                                    if (contract.GroupName.Equals(aniFile.Anime_GroupName, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        foundSummaryRecord = true;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                        contract.TotalFileSize += aniFile.FileSize;
                                        contract.TotalRunningTime += aniFile.File_LengthSeconds;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                        {
                                            if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                        }
                                    }
                                }
                                if (!foundSummaryRecord)
                                {
                                    Contract_GroupFileSummary contract = new Contract_GroupFileSummary();
                                    contract.FileCountNormal = 0;
                                    contract.FileCountSpecials = 0;
                                    contract.TotalFileSize = 0;
                                    contract.TotalRunningTime = 0;

                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                    contract.TotalFileSize += aniFile.FileSize;
                                    contract.TotalRunningTime += aniFile.File_LengthSeconds;

                                    contract.GroupName = aniFile.Anime_GroupName;
                                    contract.GroupNameShort = aniFile.Anime_GroupNameShort;
                                    contract.NormalEpisodeNumbers = new List<int>();
                                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                    {
                                        if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                            contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                    }

                                    vidQuals.Add(contract);
                                }
                            }
                            else
                            {
                                // look at the Video Info record
                                VideoInfo vinfo = vid.VideoInfo;
                                if (vinfo != null)
                                {
                                    bool foundSummaryRecord = false;
                                    foreach (Contract_GroupFileSummary contract in vidQuals)
                                    {
                                        if (contract.GroupName.Equals("NO GROUP INFO", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            foundSummaryRecord = true;
                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                            contract.TotalFileSize += vinfo.FileSize;
                                            contract.TotalRunningTime += vinfo.Duration;

                                            if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                            {
                                                if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                    contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                            }
                                        }
                                    }
                                    if (!foundSummaryRecord)
                                    {
                                        Contract_GroupFileSummary contract = new Contract_GroupFileSummary();
                                        contract.FileCountNormal = 0;
                                        contract.FileCountSpecials = 0;
                                        contract.TotalFileSize = 0;
                                        contract.TotalRunningTime = 0;

                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode) contract.FileCountNormal++;
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Special) contract.FileCountSpecials++;
                                        contract.TotalFileSize += vinfo.FileSize;
                                        contract.TotalRunningTime += vinfo.Duration;

                                        contract.GroupName = "NO GROUP INFO";
                                        contract.GroupNameShort = "NO GROUP INFO";
                                        contract.NormalEpisodeNumbers = new List<int>();
                                        if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode)
                                        {
                                            if (!contract.NormalEpisodeNumbers.Contains(anidbEp.EpisodeNumber))
                                                contract.NormalEpisodeNumbers.Add(anidbEp.EpisodeNumber);
                                        }
                                        vidQuals.Add(contract);
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (Contract_GroupFileSummary contract in vidQuals)
                {
                    contract.NormalComplete = contract.FileCountNormal >= anime.EpisodeCountNormal;
                    contract.SpecialsComplete = (contract.FileCountSpecials >= anime.EpisodeCountSpecial) && (anime.EpisodeCountSpecial > 0);

                    contract.NormalEpisodeNumberSummary = "";
                    contract.NormalEpisodeNumbers.Sort();
                    int lastEpNum = 0;
                    int baseEpNum = 0;
                    foreach (int epNum in contract.NormalEpisodeNumbers)
                    {
                        if (baseEpNum == 0)
                        {
                            baseEpNum = epNum;
                            lastEpNum = epNum;
                        }

                        if (epNum == lastEpNum) continue;

                        int epNumDiff = epNum - lastEpNum;
                        if (epNumDiff == 1)
                        {
                            lastEpNum = epNum;
                            continue;
                        }

                        // this means we have missed an episode
                        if (contract.NormalEpisodeNumberSummary.Length > 0)
                            contract.NormalEpisodeNumberSummary += ", ";

                        if (baseEpNum == lastEpNum)
                            contract.NormalEpisodeNumberSummary += string.Format("{0}", baseEpNum);
                        else
                            contract.NormalEpisodeNumberSummary += string.Format("{0}-{1}", baseEpNum, lastEpNum);

                        lastEpNum = epNum;
                        baseEpNum = epNum;

                    }

                    if (contract.NormalEpisodeNumbers.Count > 0)
                    {
                        if (contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1] >= baseEpNum)
                        {
                            // this means we have missed an episode
                            if (contract.NormalEpisodeNumberSummary.Length > 0)
                                contract.NormalEpisodeNumberSummary += ", ";

                            if (baseEpNum == contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1])
                                contract.NormalEpisodeNumberSummary += string.Format("{0}", baseEpNum);
                            else
                                contract.NormalEpisodeNumberSummary += string.Format("{0}-{1}", baseEpNum, contract.NormalEpisodeNumbers[contract.NormalEpisodeNumbers.Count - 1]);
                        }
                    }
                }

                vidQuals.Sort();
                return vidQuals;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return vidQuals;
            }
        }
Beispiel #6
0
        public List<Contract_VideoDetailed> GetFilesByGroupAndResolution(int animeID, string relGroupName, string resolution, string videoSource, int videoBitDepth, int userID)
        {
            List<Contract_VideoDetailed> vids = new List<Contract_VideoDetailed>();

            List<Contract_GroupVideoQuality> vidQuals = new List<Contract_GroupVideoQuality>();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            VideoLocalRepository repVids = new VideoLocalRepository();
            AniDB_FileRepository repAniFile = new AniDB_FileRepository();

            try
            {
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return vids;

                foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(animeID))
                {
                    int thisBitDepth = 8;

                    VideoInfo vidInfo = vid.VideoInfo;
                    if (vidInfo != null)
                    {
                        int bitDepth = 0;
                        if (int.TryParse(vidInfo.VideoBitDepth, out bitDepth))
                            thisBitDepth = bitDepth;
                    }

                    List<AnimeEpisode> eps = vid.GetAnimeEpisodes();
                    if (eps.Count == 0) continue;
                    AnimeEpisode animeEp = eps[0];
                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode || animeEp.EpisodeTypeEnum == enEpisodeType.Special)
                    {
                        // get the anibd file info
                        AniDB_File aniFile = vid.GetAniDBFile();
                        if (aniFile != null)
                        {
                            videoSource = SimplifyVideoSource(videoSource);
                            string fileSource = SimplifyVideoSource(aniFile.File_Source);
                            string vidResAniFile = Utils.GetStandardisedVideoResolution(aniFile.File_VideoResolution);

                            // match based on group / video sorce / video res
                            if (relGroupName.Equals(aniFile.Anime_GroupName, StringComparison.InvariantCultureIgnoreCase) &&
                                videoSource.Equals(fileSource, StringComparison.InvariantCultureIgnoreCase) &&
                                resolution.Equals(vidResAniFile, StringComparison.InvariantCultureIgnoreCase) &&
                                thisBitDepth == videoBitDepth)
                            {
                                vids.Add(vid.ToContractDetailed(userID));
                            }

                        }
                        else
                        {
                            string vidResInfo = Utils.GetStandardisedVideoResolution(vidInfo.VideoResolution);

                            // match based on group / video sorce / video res
                            if (relGroupName.Equals(Constants.NO_GROUP_INFO, StringComparison.InvariantCultureIgnoreCase) &&
                                videoSource.Equals(Constants.NO_SOURCE_INFO, StringComparison.InvariantCultureIgnoreCase) &&
                                resolution.Equals(vidResInfo, StringComparison.InvariantCultureIgnoreCase) &&
                                thisBitDepth == videoBitDepth)
                            {
                                vids.Add(vid.ToContractDetailed(userID));
                            }
                        }
                    }
                }
                return vids;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return vids;
            }
        }
Beispiel #7
0
        public List<Contract_VideoDetailed> GetFilesByGroup(int animeID, string relGroupName, int userID)
        {
            List<Contract_VideoDetailed> vids = new List<Contract_VideoDetailed>();

            List<Contract_GroupVideoQuality> vidQuals = new List<Contract_GroupVideoQuality>();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            VideoLocalRepository repVids = new VideoLocalRepository();

            try
            {
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return vids;

                foreach (VideoLocal vid in repVids.GetByAniDBAnimeID(animeID))
                {
                    List<AnimeEpisode> eps = vid.GetAnimeEpisodes();
                    if (eps.Count == 0) continue;
                    AnimeEpisode animeEp = eps[0];
                    if (animeEp.EpisodeTypeEnum == enEpisodeType.Episode || animeEp.EpisodeTypeEnum == enEpisodeType.Special)
                    {
                        // get the anibd file info
                        AniDB_File aniFile = vid.GetAniDBFile();
                        if (aniFile != null)
                        {
                            // match based on group / video sorce / video res
                            if (relGroupName.Equals(aniFile.Anime_GroupName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                vids.Add(vid.ToContractDetailed(userID));
                            }

                        }
                        else
                        {
                            if (relGroupName.Equals(Constants.NO_GROUP_INFO, StringComparison.InvariantCultureIgnoreCase))
                            {
                                vids.Add(vid.ToContractDetailed(userID));
                            }
                        }
                    }
                }
                return vids;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return vids;
            }
        }
Beispiel #8
0
        public List<Contract_AnimeEpisode> GetEpisodesForSeries(int animeSeriesID, int userID)
        {
            List<Contract_AnimeEpisode> eps = new List<Contract_AnimeEpisode>();
            try
            {

                DateTime start = DateTime.Now;
                AnimeEpisodeRepository repEps = new AnimeEpisodeRepository();
                AnimeEpisode_UserRepository repEpUsers = new AnimeEpisode_UserRepository();
                AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository();
                VideoLocalRepository repVids = new VideoLocalRepository();
                CrossRef_File_EpisodeRepository repCrossRefs = new CrossRef_File_EpisodeRepository();

                // get all the data first
                // we do this to reduce the amount of database calls, which makes it a lot faster
                AnimeSeries series = repAnimeSer.GetByID(animeSeriesID);
                if (series == null) return eps;

                List<AnimeEpisode> epList = repEps.GetBySeriesID(animeSeriesID);
                List<AnimeEpisode_User> userRecordList = repEpUsers.GetByUserIDAndSeriesID(userID, animeSeriesID);
                Dictionary<int, AnimeEpisode_User> dictUserRecords = new Dictionary<int, AnimeEpisode_User>();
                foreach (AnimeEpisode_User epuser in userRecordList)
                    dictUserRecords[epuser.AnimeEpisodeID] = epuser;

                AniDB_EpisodeRepository repAniEps = new AniDB_EpisodeRepository();
                List<AniDB_Episode> aniEpList = repAniEps.GetByAnimeID(series.AniDB_ID);
                Dictionary<int, AniDB_Episode> dictAniEps = new Dictionary<int, AniDB_Episode>();
                foreach (AniDB_Episode aniep in aniEpList)
                    dictAniEps[aniep.EpisodeID] = aniep;

                // get all the video local records and cross refs
                List<VideoLocal> vids = repVids.GetByAniDBAnimeID(series.AniDB_ID);
                List<CrossRef_File_Episode> crossRefs = repCrossRefs.GetByAnimeID(series.AniDB_ID);

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetEpisodesForSeries: {0} (Database) in {1} ms", series.GetAnime().MainTitle, ts.TotalMilliseconds);

                start = DateTime.Now;
                foreach (AnimeEpisode ep in epList)
                {
                    if (dictAniEps.ContainsKey(ep.AniDB_EpisodeID))
                    {
                        List<VideoLocal> epVids = new List<VideoLocal>();
                        foreach (CrossRef_File_Episode xref in crossRefs)
                        {
                            if (xref.EpisodeID == dictAniEps[ep.AniDB_EpisodeID].EpisodeID)
                            {
                                // don't add the same file twice, this will occur when
                                // one file appears over more than one episodes
                                Dictionary<string, string> addedFiles = new Dictionary<string, string>();
                                foreach (VideoLocal vl in vids)
                                {
                                    if (string.Equals(xref.Hash, vl.Hash, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (!addedFiles.ContainsKey(xref.Hash.Trim().ToUpper()))
                                        {
                                            addedFiles[xref.Hash.Trim().ToUpper()] = xref.Hash.Trim().ToUpper();
                                            epVids.Add(vl);
                                        }
                                    }
                                }
                            }
                        }

                        AnimeEpisode_User epuser = null;
                        if (dictUserRecords.ContainsKey(ep.AnimeEpisodeID))
                            epuser = dictUserRecords[ep.AnimeEpisodeID];

                        eps.Add(ep.ToContract(dictAniEps[ep.AniDB_EpisodeID], epVids, epuser, null));
                    }
                }

                ts = DateTime.Now - start;
                logger.Info("GetEpisodesForSeries: {0} (Contracts) in {1} ms", series.GetAnime().MainTitle, ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }

            return eps;
        }
Beispiel #9
0
		public void UpdateUsingGroup(ISession session, int animeGroupID)
		{
			try
			{
				DateTime start = DateTime.Now;

				AnimeGroupRepository repGroups = new AnimeGroupRepository();
				AnimeGroup thisgrp = repGroups.GetByID(session, animeGroupID);
				
				if (thisgrp == null) return;

				AdhocRepository repAdHoc = new AdhocRepository();

				// get a list of all the groups including this one and everthing above it the heirarchy
				List<AnimeGroup> allgroups = new List<AnimeGroup>();
				allgroups.Add(thisgrp);

				int? groupID = thisgrp.AnimeGroupParentID;
				while (groupID.HasValue)
				{
					AnimeGroup grpTemp = repGroups.GetByID(session, groupID.Value);
					if (grpTemp != null)
					{
						allgroups.Add(grpTemp);
						groupID = grpTemp.AnimeGroupParentID;
					}
					else
						groupID = null;
				}

				TimeSpan ts = DateTime.Now - start;
				logger.Trace("Updating cached stats for GROUP - STEP 1 ({0}) in {1} ms", thisgrp.GroupName, ts.TotalMilliseconds);
				start = DateTime.Now;

				VideoLocalRepository repVids = new VideoLocalRepository();
				CrossRef_File_EpisodeRepository repXrefs = new CrossRef_File_EpisodeRepository();

				foreach (AnimeGroup grp in allgroups)
				{
					StatGroupCategories[grp.AnimeGroupID] = grp.CategoriesString;
					StatGroupTitles[grp.AnimeGroupID] = grp.TitlesString;
					StatGroupVideoQuality[grp.AnimeGroupID] = grp.VideoQualityString;

					ts = DateTime.Now - start;
					logger.Trace("Updating cached stats for GROUP - STEP 2 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
					start = DateTime.Now;

					DateTime? airDate_Min = null;
					DateTime? airDate_Max = null;
					DateTime? endDate = new DateTime(1980, 1, 1);
					DateTime? seriesCreatedDate = null;
					bool isComplete = false;
					bool hasFinishedAiring = false;
					bool isCurrentlyAiring = false;
					string videoQualityEpisodes = "";

					List<string> audioLanguages = new List<string>();
					List<string> subtitleLanguages = new List<string>();

					bool hasTvDB = true;
					bool hasMAL = true;
					bool hasMovieDB = true;
					bool hasMovieDBOrTvDB = true;

					int seriesCount = 0;
					int epCount = 0;


					foreach (AnimeSeries series in grp.GetAllSeries(session))
					{
						seriesCount++;

						List<VideoLocal> vidsTemp = repVids.GetByAniDBAnimeID(session, series.AniDB_ID);
						List<CrossRef_File_Episode> crossRefs = repXrefs.GetByAnimeID(session, series.AniDB_ID);

						Dictionary<int, List<CrossRef_File_Episode>> dictCrossRefs = new Dictionary<int, List<CrossRef_File_Episode>>();
						foreach (CrossRef_File_Episode xref in crossRefs)
						{
							if (!dictCrossRefs.ContainsKey(xref.EpisodeID))
								dictCrossRefs[xref.EpisodeID] = new List<CrossRef_File_Episode>();
							dictCrossRefs[xref.EpisodeID].Add(xref);
						}

						Dictionary<string, VideoLocal> dictVids = new Dictionary<string, VideoLocal>();
						foreach (VideoLocal vid in vidsTemp)
							dictVids[vid.Hash] = vid;

						// All Video Quality Episodes
						// Try to determine if this anime has all the episodes available at a certain video quality
						// e.g.  the series has all episodes in blu-ray
						// Also look at languages
						Dictionary<string, int> vidQualEpCounts = new Dictionary<string,int>(); // video quality, count of episodes

						foreach (AnimeEpisode ep in series.GetAnimeEpisodes(session))
						{
							if (ep.EpisodeTypeEnum != AniDBAPI.enEpisodeType.Episode) continue;


							List<VideoLocal> epVids = new List<VideoLocal>();
							if (dictCrossRefs.ContainsKey(ep.AniDB_EpisodeID))
							{
								foreach (CrossRef_File_Episode xref in dictCrossRefs[ep.AniDB_EpisodeID])
								{
									if (xref.EpisodeID == ep.AniDB_EpisodeID)
									{
										if (dictVids.ContainsKey(xref.Hash))
											epVids.Add(dictVids[xref.Hash]);
									}
								}
							}

							List<string> qualityAddedSoFar = new List<string>(); // handle mutliple files of the same quality for one episode
							foreach (VideoLocal vid in epVids)
							{
								AniDB_File anifile = vid.GetAniDBFile(session);
								if (anifile == null) continue;

								if (!qualityAddedSoFar.Contains(anifile.File_Source))
								{
									if (!vidQualEpCounts.ContainsKey(anifile.File_Source))
										vidQualEpCounts[anifile.File_Source] = 1;
									else
										vidQualEpCounts[anifile.File_Source]++;

									qualityAddedSoFar.Add(anifile.File_Source);
								}
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 3 ({0}/{1}) in {2} ms",grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;



						AniDB_Anime anime = series.GetAnime(session);

						epCount = epCount + anime.EpisodeCountNormal;

						foreach (KeyValuePair<string, int> kvp in vidQualEpCounts)
						{
							int index = videoQualityEpisodes.IndexOf(kvp.Key, 0, StringComparison.InvariantCultureIgnoreCase);
							if (index > -1) continue; // don't add if we already have it

							if (anime.EpisodeCountNormal == kvp.Value)
							{
								if (videoQualityEpisodes.Length > 0) videoQualityEpisodes += ",";
								videoQualityEpisodes += kvp.Key;
							}

						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 4 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// audio languages
						Dictionary<int, LanguageStat> dicAudio = repAdHoc.GetAudioLanguageStatsByAnime(session, anime.AnimeID);
						foreach (KeyValuePair<int, LanguageStat> kvp in dicAudio)
						{
							foreach (string lanName in kvp.Value.LanguageNames)
							{
								if (!audioLanguages.Contains(lanName))
									audioLanguages.Add(lanName);
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 5 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// subtitle languages
						Dictionary<int, LanguageStat> dicSubtitle = repAdHoc.GetSubtitleLanguageStatsByAnime(session, anime.AnimeID);
						foreach (KeyValuePair<int, LanguageStat> kvp in dicSubtitle)
						{
							foreach (string lanName in kvp.Value.LanguageNames)
							{
								if (!subtitleLanguages.Contains(lanName))
									subtitleLanguages.Add(lanName);
							}
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 6 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// Calculate Air Date 
						DateTime? thisDate = series.AirDate;
						if (thisDate.HasValue)
						{
							if (airDate_Min.HasValue)
							{
								if (thisDate.Value < airDate_Min.Value) airDate_Min = thisDate;
							}
							else
								airDate_Min = thisDate;

							if (airDate_Max.HasValue)
							{
								if (thisDate.Value > airDate_Max.Value) airDate_Max = thisDate;
							}
							else
								airDate_Max = thisDate;
						}

						// calculate end date
						// if the end date is NULL it actually means it is ongoing, so this is the max possible value
						thisDate = series.EndDate;
						if (thisDate.HasValue && endDate.HasValue)
						{
							if (thisDate.Value > endDate.Value) endDate = thisDate;
						}
						else
							endDate = null;

						// Note - only one series has to be finished airing to qualify
						if (series.EndDate.HasValue && series.EndDate.Value < DateTime.Now)
							hasFinishedAiring = true;

						// Note - only one series has to be finished airing to qualify
						if (!series.EndDate.HasValue || series.EndDate.Value > DateTime.Now)
							isCurrentlyAiring = true;

						// We evaluate IsComplete as true if
						// 1. series has finished airing
						// 2. user has all episodes locally
						// Note - only one series has to be complete for the group to be considered complete
						if (series.EndDate.HasValue)
						{
							if (series.EndDate.Value < DateTime.Now && series.MissingEpisodeCount == 0 && series.MissingEpisodeCountGroups == 0)
							{
								isComplete = true;
							}
						}

						// Calculate Series Created Date 
						thisDate = series.DateTimeCreated;
						if (thisDate.HasValue)
						{
							if (seriesCreatedDate.HasValue)
							{
								if (thisDate.Value < seriesCreatedDate.Value) seriesCreatedDate = thisDate;
							}
							else
								seriesCreatedDate = thisDate;
						}

						ts = DateTime.Now - start;
						logger.Trace("Updating cached stats for GROUP/Series - STEP 7 ({0}/{1}) in {2} ms", grp.GroupName, series.AnimeSeriesID, ts.TotalMilliseconds);
						start = DateTime.Now;

						// for the group, if any of the series don't have a tvdb link
						// we will consider the group as not having a tvdb link

						List<CrossRef_AniDB_TvDBV2> tvXrefs = series.GetCrossRefTvDBV2();

						if (tvXrefs == null || tvXrefs.Count == 0) hasTvDB = false;
						if (series.CrossRefMovieDB == null) hasMovieDB = false;
						if (series.CrossRefMAL == null) hasMAL = false;

						if ((tvXrefs == null || tvXrefs.Count == 0) && series.CrossRefMovieDB == null) hasMovieDBOrTvDB = false;
					}


					StatGroupIsComplete[grp.AnimeGroupID] = isComplete;
					StatGroupIsFinishedAiring[grp.AnimeGroupID] = hasFinishedAiring;
					StatGroupIsCurrentlyAiring[grp.AnimeGroupID] = isCurrentlyAiring;
					StatGroupHasTvDB[grp.AnimeGroupID] = hasTvDB;
					StatGroupHasMAL[grp.AnimeGroupID] = hasMAL;
					StatGroupHasMovieDB[grp.AnimeGroupID] = hasMovieDB;
					StatGroupHasMovieDBOrTvDB[grp.AnimeGroupID] = hasMovieDBOrTvDB;
					StatGroupSeriesCount[grp.AnimeGroupID] = seriesCount;
					StatGroupEpisodeCount[grp.AnimeGroupID] = epCount;

					StatGroupVideoQualityEpisodes[grp.AnimeGroupID] = videoQualityEpisodes;

					StatGroupAirDate_Min[grp.AnimeGroupID] = airDate_Min;
					StatGroupAirDate_Max[grp.AnimeGroupID] = airDate_Max;
					StatGroupEndDate[grp.AnimeGroupID] = endDate;
					StatGroupSeriesCreatedDate[grp.AnimeGroupID] = seriesCreatedDate;

					StatGroupUserVoteOverall[grp.AnimeGroupID] = grp.UserVote;
					StatGroupUserVotePermanent[grp.AnimeGroupID] = grp.UserVotePermanent;
					StatGroupUserVoteTemporary[grp.AnimeGroupID] = grp.UserVoteTemporary;
					StatGroupAniDBRating[grp.AnimeGroupID] = grp.AniDBRating;

					ts = DateTime.Now - start;
					logger.Trace("Updating cached stats for GROUP - STEP 8 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
					start = DateTime.Now;

					string Stat_AudioLanguages = "";
					foreach (string audioLan in audioLanguages)
					{
						if (Stat_AudioLanguages.Length > 0) Stat_AudioLanguages += ",";
						Stat_AudioLanguages += audioLan;
					}
					this.StatGroupAudioLanguages[grp.AnimeGroupID] = Stat_AudioLanguages;

					string Stat_SubtitleLanguages = "";
					foreach (string subLan in subtitleLanguages)
					{
						if (Stat_SubtitleLanguages.Length > 0) Stat_SubtitleLanguages += ",";
						Stat_SubtitleLanguages += subLan;
					}
					this.StatGroupSubtitleLanguages[grp.AnimeGroupID] = Stat_SubtitleLanguages;

                    ts = DateTime.Now - start;
                    logger.Trace("Updating cached stats for GROUP - STEP 9 ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
                    start = DateTime.Now;
                    UpdateGroupFilterUsingGroup(grp.AnimeGroupID);
                    UpdatePlexAnimeGroup(session, grp,grp.GetAllSeries());
                    ts = DateTime.Now - start;
                    logger.Trace("Updating cached stats for GROUP - END ({0}) in {1} ms", grp.GroupName, ts.TotalMilliseconds);
                }
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
		}