Example #1
0
        public Video GetVideoByDate(List <Video> videos, string name)
        {
            var dateExtracted = StringExtractor.ExtractDate(name);

            if (dateExtracted != null)
            {
                int foundVideosByDateCount = videos.Count(x => x.Releasedate == dateExtracted);
                if (foundVideosByDateCount == 1)
                {
                    return(videos.Single(x => x.Releasedate == dateExtracted));
                }

                var videosFound      = videos.Where(x => x.Releasedate == dateExtracted).ToList();
                var videoFoundResult = GetVideoByNormalization(videosFound, name);
                if (videoFoundResult != null)
                {
                    return(videoFoundResult);
                }
            }

            return(null);
        }
Example #2
0
        private Video GetVideoByFilename(string title, Site site)
        {
            DateTime?releaseDate = StringExtractor.ExtractDate(title);
            string   episode     = StringExtractor.ExtractEpisode(title);

            List <Video> videos = GetVideosBySiteWithCached(site);

            if (releaseDate != null)
            {
                var foundMatchingVideos = videos.Where(x => x.Releasedate == releaseDate.Value).ToList();
                logger.LogDebug("Found videos (by ReleaseDate): " + foundMatchingVideos.Count + " Date: " + releaseDate.Value.ToString("yyyyMMdd"));
                if (!foundMatchingVideos.Any() || foundMatchingVideos.Count >= 6)
                {
                    return(null);
                }
                foreach (var foundMatchingVideo in foundMatchingVideos)
                {
                    logger.LogDebug("Video: " + foundMatchingVideo.Title + " matching: " + title + " ?");

                    if (foundMatchingVideo.Title.Contains(" "))
                    {
                        string firstWord = foundMatchingVideo.Title.Substring(0,
                                                                              foundMatchingVideo.Title.IndexOf(" ", StringComparison.InvariantCulture));
                        if (title.Contains(firstWord))
                        {
                            return(foundMatchingVideo);
                        }
                    }

                    string foundTitle      = foundMatchingVideo.Title.Replace(" ", ".").ToLower();
                    string titleSimplified = title.ToLower().Replace(" ", ".");

                    if (titleSimplified.Contains(foundTitle))
                    {
                        return(foundMatchingVideo);
                    }
                }

                return(null);
            }

            if (!string.IsNullOrEmpty(episode))
            {
                var foundMatchingVideos = videos.Where(x => x.FullTitle.Contains("E" + episode)).ToList();
                logger.LogDebug("Found videos (by Episode): " + foundMatchingVideos.Count + " Episode: E" + episode);
                if (foundMatchingVideos.Any() && foundMatchingVideos.Count < 6)
                {
                    foreach (var foundMatchingVideo in foundMatchingVideos)
                    {
                        var firstwordLength = foundMatchingVideo.Title.IndexOf(" ", StringComparison.InvariantCulture);
                        if (firstwordLength > 0)
                        {
                            var firstWord = foundMatchingVideo.Title.Substring(0, firstwordLength);
                            if (title.Contains(firstWord))
                            {
                                return(foundMatchingVideo);
                            }
                        }
                    }
                }
            }

            return(null);
        }