Beispiel #1
0
        public static bool CheckMatching(SubtitleModel subtitleModel, string SeasonFromFeliratokInfo,
                                         string EpisodeFromFeliratokInfo, HtmlNode originalNode)
        {
            var name    = subtitleModel.ShowName.ToLower();
            var trimEnd = new Regex($"({name})(.*?)(\\(.*\\))\\s*(-)\\s.*");

            var nameRegexed = trimEnd.Matches(originalNode.InnerText.ToLower());

            var dash          = string.Empty;
            var namefromgroup = string.Empty;

            try
            {
                dash          = nameRegexed[0].Groups[4].Value;
                namefromgroup = nameRegexed[0].Groups[1].Value;
            }
            catch (ArgumentOutOfRangeException aoore)
            {
            }


            if (subtitleModel.SeasonNumber == int.Parse(SeasonFromFeliratokInfo) && subtitleModel.EpisodeNumber ==
                int.Parse(EpisodeFromFeliratokInfo) &&
                originalNode.InnerText.ToLower().Contains(subtitleModel.Releaser.ToLower()) &&
                originalNode.InnerText.ToLower().Contains(subtitleModel.Quality.ToLower()))
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
    void SubtitleInitialize(string _path)
    {
        setting.IgnoreComments=true;
        setting.IgnoreProcessingInstructions=true;
        //setting.IgnoreWhitespace=true;
        textFile =(TextAsset)Resources.Load(_path);
        xmlDoc.LoadXml(textFile.text);
        XmlNode root =xmlDoc.DocumentElement;
        XmlNodeList x=root.ChildNodes;

        for(int i=0; i<x.Count;i++){
            SubtitleModel model= new SubtitleModel();
            model.Name=x[i].Attributes["name"].Value;
            string a=x[i].FirstChild.InnerText;
            model.PlayTime=float.Parse(a);
            model.Content=x[i].FirstChild.NextSibling.InnerText;

            model.AutoOff=	Boolean.Parse(x[i].Attributes["AutoOff"].Value);
            model.AutoPlay=	Boolean.Parse(x[i].Attributes["AutoPlay"].Value);
            model.Action=x[i].FirstChild.NextSibling.NextSibling.InnerText;
            if (x[i].FirstChild.NextSibling.NextSibling.Attributes["object"]!=null){
            model.ActionTarget=x[i].FirstChild.NextSibling.NextSibling.Attributes["object"].Value;
            }else {

                model.ActionTarget=null;
            }
            //model.AutoOff=x[i].Attributes["AutoOff"].Value;
            subtitleModel.Add(model);
            //y.Add (x[i]); //将XMLmodelslist 对象转换为xmlnodes的list对象
        }
    }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
0
    void SubtitleInitialize(string _path)
    {
        setting.IgnoreComments = true;
        setting.IgnoreProcessingInstructions = true;
        //setting.IgnoreWhitespace=true;
        textFile = (TextAsset)Resources.Load(_path);
        xmlDoc.LoadXml(textFile.text);
        XmlNode     root = xmlDoc.DocumentElement;
        XmlNodeList x    = root.ChildNodes;

        for (int i = 0; i < x.Count; i++)
        {
            SubtitleModel model = new SubtitleModel();
            model.Name = x[i].Attributes["name"].Value;
            string a = x[i].FirstChild.InnerText;
            model.PlayTime = float.Parse(a);
            model.Content  = x[i].FirstChild.NextSibling.InnerText;

            model.AutoOff  = Boolean.Parse(x[i].Attributes["AutoOff"].Value);
            model.AutoPlay = Boolean.Parse(x[i].Attributes["AutoPlay"].Value);
            model.Action   = x[i].FirstChild.NextSibling.NextSibling.InnerText;
            if (x[i].FirstChild.NextSibling.NextSibling.Attributes["object"] != null)
            {
                model.ActionTarget = x[i].FirstChild.NextSibling.NextSibling.Attributes["object"].Value;
            }
            else
            {
                model.ActionTarget = null;
            }
            //model.AutoOff=x[i].Attributes["AutoOff"].Value;
            subtitleModel.Add(model);
            //y.Add (x[i]); //将XMLmodelslist 对象转换为xmlnodes的list对象
        }
    }
Beispiel #6
0
        //public static bool IsThereSubtitles(string folderPath, string showName, int episodeNum, int seasonNum)
        //{
        //    showName = TrimFileName(showName).ToLower();
        //    string[] fileArray = Directory.GetFiles(folderPath);
        //    foreach (var file1 in fileArray)
        //    {
        //        var file = TrimFileName(file1).ToLower();
        //        if (file.EndsWith(".srt"))
        //        {
        //            if (file.Contains(showName) && (file.Contains("S" + seasonNum) || file.Contains("s" + seasonNum) || file.Contains("S0" + seasonNum) || file.Contains("s0" + seasonNum)) &&
        //                (file.Contains("E" + episodeNum) || file.Contains("e" + episodeNum) || file.Contains("E0" + episodeNum) || file.Contains("e0" + episodeNum))) //TODO ÉS SZEZONT ÉS EPIZÓDOT
        //            {
        //                return true;
        //            }
        //        }
        //    }

        //    return false;
        //}


        public static bool DownloadSubtitle(SubtitleModel subtitleModel, string path, string filename)
        {
            if (!SeriesHelper.DoesItContainHun(filename))
            {
                return(FeliratokInfoSeriesDownloader.GetFeliratokInfoHtml(subtitleModel, feliratokInfoEndpoint, path,
                                                                          filename));
            }
            return(false);
        }
Beispiel #7
0
        public static bool FindAdherentSubtitleAndDownload(List <HtmlNode> subtitlesHtmlList,
                                                           SubtitleModel subtitleModel, string url, string folderPath, string filename)
        {
            var subtitleFound = FindForExactMatch(subtitlesHtmlList, subtitleModel, url, folderPath, filename);

            if (subtitleFound)
            {
                return(subtitleFound);
            }
            subtitleFound = FindSeasonPack(subtitlesHtmlList, subtitleModel, url, folderPath, filename);

            return(false);
        }
Beispiel #8
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);
                }
            }
        }
Beispiel #9
0
 private void Awake()
 {
     subtitleModel = GetComponent <SubtitleModel>();
     subtitleView  = GetComponent <SubtitleView>();
 }
Beispiel #10
0
        public List <FoundSubtitle> FindTheBestOnes(List <HtmlNode> subtitleHtmlList, SubtitleModel subtitleModel)
        {
            if (subtitleModel != null && subtitleHtmlList.Count != 0)
            {
                var magyarXPath    = "//div[@class=\'magyar\']";
                var originalXPath  = "//div[@class=\'eredeti\']";
                var downloadXPath  = "//td[@align=\'center\']/a[@href]";
                var htmlDocument   = new HtmlDocument();
                var foundSubtitles = new List <FoundSubtitle>();

                foreach (var subtitleHtml in subtitleHtmlList)
                {
                    htmlDocument.LoadHtml(subtitleHtml.InnerHtml);

                    var magyarNode   = htmlDocument.DocumentNode.SelectSingleNode(magyarXPath);
                    var originalNode = htmlDocument.DocumentNode.SelectSingleNode(originalXPath);

                    if ((magyarNode.InnerText.Contains(subtitleModel.Title) ||
                         originalNode.InnerText.Contains(subtitleModel.Title)) &&
                        (magyarNode.InnerText.Contains(subtitleModel.Quality) ||
                         originalNode.InnerText.Contains(subtitleModel.Quality)) &&
                        (magyarNode.InnerText.Contains(subtitleModel.Releaser) ||
                         originalNode.InnerText.Contains(subtitleModel.Releaser)))
                    {
                        var downloadNode = htmlDocument.DocumentNode.SelectSingleNode(downloadXPath).Attributes["href"]
                                           .Value;

                        foundSubtitles.Add(new FoundSubtitle(magyarNode.InnerText, originalNode.InnerText, downloadNode,
                                                             htmlDocument));
                    }
                }

                return(foundSubtitles);
            }

            return(null);
        }
Beispiel #11
0
 public static bool FindSeasonPack(List <HtmlNode> subtitlesHtmlList, SubtitleModel subtitleModel, string url,
                                   string folderPath, string filename)
 {
     return(false);
 }
Beispiel #12
0
        public static bool FindForExactMatch(List <HtmlNode> subtitlesHtmlList, SubtitleModel subtitleModel, string url,
                                             string folderPath, string filename)
        {
            //S01-02 nélkül keresünk

            if (Directory.Exists(folderPath + "\\" + subFolderName))
            {
                MoveSubtitleUp(folderPath, subFolderName, filename, subtitleModel.SeasonNumber,
                               subtitleModel.EpisodeNumber);
                return(true);
            }

            CheckIfSingleSubAlreadyDownloaded(folderPath, filename);

            var magyarXPath   = "//div[@class=\'magyar\']";
            var originalXPath = "//div[@class=\'eredeti\']";
            var downloadXPath = "//td[@align=\'center\']/a[@href]";
            var htmlDocument  = new HtmlDocument();

            foreach (var subtitleHtml in subtitlesHtmlList)
            {
                htmlDocument.LoadHtml(subtitleHtml.InnerHtml);

                var magyarNode   = htmlDocument.DocumentNode.SelectSingleNode(magyarXPath);
                var originalNode = htmlDocument.DocumentNode.SelectSingleNode(originalXPath);

                var EpisodeFromFeliratokInfo = string.Empty;
                var SeasonFromFeliratokInfo  = string.Empty;

                //A felsőben csak egy kötőjel, megnézi a SOROZATxEPIZÓD stílust, és a leírásos (Season X) stílust is
                if (magyarNode.InnerText == "-")
                {
                    EpisodeFromFeliratokInfo = SeriesHelper.GetEpisodeFromFeliratokInfo1x2(originalNode.InnerText);
                    SeasonFromFeliratokInfo  = SeriesHelper.GetSeasonFromFeliratokInfo1x2(originalNode.InnerText);

                    if (EpisodeFromFeliratokInfo.Length != 0 && SeasonFromFeliratokInfo.Length != 0 &&
                        CheckMatching(subtitleModel, SeasonFromFeliratokInfo, EpisodeFromFeliratokInfo, originalNode))
                    {
                        return(Download(htmlDocument, downloadXPath, url, folderPath, filename, subtitleModel, true));
                    }
                    if (SeasonFromFeliratokInfo.Length == 0)
                    {
                        EpisodeFromFeliratokInfo =
                            subtitleModel.EpisodeNumber.ToString(); //beállítom, hogy a check ne dobjon hibát
                        SeasonFromFeliratokInfo =
                            SeriesHelper.GetSeasonFromFeliratokInfoThird(originalNode.InnerText).ToString();
                        if (SeasonFromFeliratokInfo.Length != 0 && CheckMatching(subtitleModel, SeasonFromFeliratokInfo,
                                                                                 EpisodeFromFeliratokInfo, originalNode))
                        {
                            return(Download(htmlDocument, downloadXPath, url, folderPath, filename, subtitleModel,
                                            false));
                        }
                    }
                }

                //Évadpakk
                //Ekkor van sima neve(felsőben), ezért ráapplikálom a (8. évad) stílust a felsőre,
                //az alsóra meg a (Season 8) félét ha nincs a felsőben találat

                SeasonFromFeliratokInfo = SeriesHelper.GetSeasonFromFeliratokInfoEvad(magyarNode.InnerText).ToString();

                if (int.Parse(SeasonFromFeliratokInfo) != -1)
                {
                    EpisodeFromFeliratokInfo =
                        subtitleModel.EpisodeNumber.ToString(); //beállítom, hogy a check ne dobjon hibát
                    var seasonOnSite = SeriesHelper.GetSeasonFromFeliratokInfoThird(originalNode.InnerText);
                    if (seasonOnSite == subtitleModel.SeasonNumber && CheckMatching(subtitleModel,
                                                                                    SeasonFromFeliratokInfo, EpisodeFromFeliratokInfo, originalNode))
                    {
                        return(Download(htmlDocument, downloadXPath, url, folderPath, filename, subtitleModel, false));
                    }
                }
                else
                {
                    SeasonFromFeliratokInfo = SeriesHelper.GetSeasonFromFeliratokInfoThird(originalNode.InnerText)
                                              .ToString();

                    if (int.Parse(SeasonFromFeliratokInfo) != -1)
                    {
                        EpisodeFromFeliratokInfo =
                            subtitleModel.EpisodeNumber.ToString(); //beállítom, hogy a check ne dobjon hibát
                        if (CheckMatching(subtitleModel, SeasonFromFeliratokInfo, EpisodeFromFeliratokInfo,
                                          originalNode))
                        {
                            return(Download(htmlDocument, downloadXPath, url, folderPath, filename, subtitleModel,
                                            false));
                        }
                    }
                }

                //PONTOS EGYEZÉS
                if (EpisodeFromFeliratokInfo.Length == 0 || SeasonFromFeliratokInfo.Length == 0 ||
                    SeasonFromFeliratokInfo.Length == -1)
                {
                    EpisodeFromFeliratokInfo = SeriesHelper.GetEpisodeFromFeliratokInfo1x2(originalNode.InnerText);
                    SeasonFromFeliratokInfo  = SeriesHelper.GetSeasonFromFeliratokInfo1x2(originalNode.InnerText);

                    if (SeasonFromFeliratokInfo.Length == 0)
                    {
                        EpisodeFromFeliratokInfo = subtitleModel.EpisodeNumber.ToString();
                        SeasonFromFeliratokInfo  = SeriesHelper.GetSeasonFromFeliratokInfoThird(originalNode.InnerText)
                                                   .ToString();
                    }

                    if (CheckMatching(subtitleModel, SeasonFromFeliratokInfo, EpisodeFromFeliratokInfo, originalNode))
                    {
                        return(Download(htmlDocument, downloadXPath, url, folderPath, filename, subtitleModel, true));
                    }
                }
            }

            return(false);
        }