Exemplo n.º 1
0
        public Video GetVideoByEpisode(List <Video> videos, string name)
        {
            var episodeExtracted = StringExtractor.ExtractEpisode(name);

            if (episodeExtracted != null)
            {
                int foundVideosByEpisodeCount = videos.Count(x => x.FullTitle.Contains(" " + episodeExtracted));
                if (foundVideosByEpisodeCount == 1)
                {
                    return(videos.Single(x => x.FullTitle.Contains(" " + episodeExtracted)));
                }

                var videosFound      = videos.Where(x => x.FullTitle.Contains(" " + episodeExtracted)).ToList();
                var videoFoundResult = GetVideoByNormalization(videosFound, name);
                if (videoFoundResult != null)
                {
                    return(videoFoundResult);
                }
            }

            return(null);
        }
Exemplo n.º 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);
        }