Esempio n. 1
0
        public List <FoundSubtitle> FindSubtitle(SubtitleModel subtitleModel, string path, string filename)
        {
            using (var client = new WebClient())
            {
                var             subtitleFound = false;
                string          data          = null;
                List <HtmlNode> subtitleList  = null;
                var             page          = 1;

                var bestSubtitlesFromAllPages = new List <FoundSubtitle>();

                do
                {
                    var url = $"{_endpoint}/?search={subtitleModel.Title}&nyelv={_lang}&page={page}";
                    data = client.DownloadString(new Uri(url));

                    subtitleList = SubtitleFetcher.GetSubtitles(data);

                    if (subtitleList != null)
                    {
                        var subtitles = FindTheBestOnes(subtitleList, subtitleModel);
                        foreach (var foundSubtitle in subtitles)
                        {
                            //hozzáadom a listához amiket megtaláltunk. azért van erre szükség mert több oldal is lehet a feliratokinfo feliratok listjáa
                            bestSubtitlesFromAllPages.Add(foundSubtitle);
                        }
                    }


                    page++;
                } while (subtitleList != null);

                return(bestSubtitlesFromAllPages);
            }
        }
Esempio n. 2
0
        public static bool GetFeliratokInfoHtml(SubtitleModel subtitleModel, string url, string folderPath,
                                                string filename)
        {
            using (var client = new WebClient())
            {
                var             subtitleFound = false;
                string          data          = null;
                List <HtmlNode> subtitleList  = null;
                var             page          = 1;


                do
                {
                    var route =
                        $"/?search={subtitleModel.ShowName}&soriSorszam=&nyelv={lang}&sorozatnev=&sid=&complexsearch=true&knyelv=0&evad={subtitleModel.SeasonNumber}&epizod={subtitleModel.EpisodeNumber}&cimke=0&minoseg=0&rlsr=0&tab=all&page={page}";
                    data = client.DownloadString(new Uri(url + route));

                    subtitleList  = SubtitleFetcher.GetSubtitles(data);
                    subtitleFound =
                        FindAdherentSubtitleAndDownload(subtitleList, subtitleModel, url, folderPath, filename);

                    page++;
                } while (!subtitleFound && subtitleList != null);

                return(subtitleFound);
            }
        }
Esempio n. 3
0
        public static bool Download(HtmlDocument htmlDocument, string downloadXPath, string endpoint, string folderPath,
                                    string filename, SubtitleModel subtitleModel, bool IsItSrt)
        {
            using (var client = new WebClient())
            {
                var downloadNode = htmlDocument.DocumentNode.SelectSingleNode(downloadXPath).Attributes["href"]
                                   .Value;

                switch (IsItSrt)
                {
                case true:
                    client.DownloadFile(endpoint + downloadNode,
                                        $"{folderPath}\\{filename.Remove(filename.Length - 4, 4)}.srt");
                    return(true);

                case false:
                    var trimmedFolderPath = SubtitleFetcher.TrimFileName(folderPath);
                    var source            = $"{folderPath}\\{trimmedFolderPath}.rar";

                    client.DownloadFile(endpoint + downloadNode, source);


                    var p = new Process();
                    p.StartInfo.CreateNoWindow  = true;
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.FileName        = "\"C:\\Program Files\\WinRAR\\winrar.exe\"";
                    p.StartInfo.Arguments       = string.Format(@"x -s ""{0}"" *.* ""{1}\"" ", source,
                                                                folderPath + "\\" + subFolderName);
                    p.Start();
                    p.WaitForExit();
                    if (File.Exists(source))
                    {
                        File.Delete(source);
                    }

                    MoveSubtitleUp(folderPath, subFolderName, filename, subtitleModel.SeasonNumber,
                                   subtitleModel.EpisodeNumber);

                    return(true);

                default:
                    return(false);
                }
            }
        }
Esempio n. 4
0
        public static void MoveSubtitleUp(string folderPath, string subFolderName, string filename, int season,
                                          int episode)
        {
            if (Directory.Exists(folderPath + "\\" + subFolderName))
            {
                var           directories = Directory.GetDirectories(folderPath + "\\" + subFolderName);
                DirectoryInfo d;
                FileInfo[]    Subtitles;
                if (directories.Length != 0)
                {
                    d         = new DirectoryInfo(directories[0]);
                    Subtitles = d.GetFiles("*.srt");

                    foreach (var subtitle in Subtitles)
                    {
                        var subtitleSeason  = SeriesHelper.GetSeasonNumber(subtitle.ToString());
                        var subtitleEpisode = SeriesHelper.GetEpisodeNumber(subtitle.ToString());
                        if (subtitleSeason == season && episode == subtitleEpisode)
                        {
                            var subname = SubtitleFetcher.TrimFileName(filename);
                            File.Move(subtitle.FullName, folderPath + "\\" + filename + ".srt");
                        }
                    }
                }
                else
                {
                    d         = new DirectoryInfo(folderPath + "\\" + subFolderName);
                    Subtitles = d.GetFiles("*.srt");

                    foreach (var subtitle in Subtitles)
                    {
                        var subtitleSeason  = SeriesHelper.GetSeasonNumber(subtitle.ToString());
                        var subtitleEpisode = SeriesHelper.GetEpisodeNumber(subtitle.ToString());
                        if (subtitleSeason == season && episode == subtitleEpisode)
                        {
                            var subname = SubtitleFetcher.TrimFileName(filename);
                            File.Move(subtitle.FullName, folderPath + "\\" + filename + ".srt");
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        public static bool IsThereSubtitles(string folderPath, string showName, int episodeNum, int seasonNum)
        {
            showName = SubtitleFetcher.TrimFileName(showName).ToLower();
            var fileArray = Directory.GetFiles(folderPath, "*.srt");

            foreach (var file1 in fileArray)
            {
                var file = SubtitleFetcher.TrimFileName(file1).ToLower();
                var downloadedSubSeason  = SeriesHelper.GetSeasonNumber(file);
                var downloadedSubEpisode = SeriesHelper.GetEpisodeNumber(file);
                var downloadedSubName    = SeriesHelper.GetTitle(file);
                if (downloadedSubSeason == seasonNum && downloadedSubEpisode == episodeNum &&
                    downloadedSubName == showName)
                {
                    return(true);
                }
            }

            return(false);
        }