Beispiel #1
0
        static public void SearchTest(string engine, string search, string sort)
        {
            Console.WriteLine("SearchTest: {0}:\"{1}\":{2}", engine, search, sort);
            TorrentSearchEngine tse           = new TorrentSearchEngine("MyTorrents.xml");
            ITorrentSearch      torrentSearch = tse.Create(engine);

            TorrentMatchList matchList = torrentSearch.Search(search, sort, null);
            CultureInfo      mylang    = CultureInfo.CurrentCulture;

            Console.OutputEncoding = Encoding.GetEncoding(mylang.TextInfo.ANSICodePage);
            foreach (TorrentMatch match in matchList)
            {
                Console.WriteLine("Found: {0} (Size:{1:F2} MB))", match.Title, match.Size / (1024 * 1024));
            }
        }
        void _bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            TorrentSearchParameters p   = e.Argument as TorrentSearchParameters;
            TorrentSearchEngine     tse = null;

            try

            {
                tse = new TorrentSearchEngine(Configuration.Instance().Settings["TorrentSearch.Config"] as string);
            }
            catch
            {
                Log.Instance().Print("Mytorrents.xml cofig file loading failed!");
            }
            ITorrentSearch   t         = tse.Create(p.SearchEngine);
            TorrentMatchList matchList = t.Search(p.SearchString, p.SortOrder, null);

            e.Result = matchList;
        }
        public virtual void DoSearch()
        {
            Thread AutoSearch = new Thread(delegate()
            {
                try
                {
                    Log.Instance().Print(string.Format("Automatic search started [{0}]", this.show.Name));
                    Log.Instance().Print(string.Format("Unlocal Episodes [{0}]", this.show.AllUnlocal));
                    Log.Instance().Print(string.Format("Next unlocal Episode [{0}]", this.show.FirstUnlocal));

                    TorrentSearchEngine tse = new TorrentSearchEngine(Configuration.Instance().Settings["TorrentSearch.Config"] as string);
                    var watch = this;
                    ITorrentSearch _searchEngine = tse.Engines.Where(e => e.Name == watch.tracker).First();
                    string CleanTitle            = Regex.Replace(watch.show.OriginalName, "[^0-9a-zA-Z ]+", "");
                    TorrentMatchList matchlist   = _searchEngine.Search(CleanTitle, "Default", null);
                    Log.Instance().Print(string.Format("Search {0} on {1} Sort {2} Count {3}", CleanTitle, _searchEngine.Name, "Default", matchlist.Count));
                    switch (watch.type)
                    {
                    case "New episodes":
                        int t = 0;
                        Log.Instance().Print(string.Format("Searching for episode [{0}]", this.show.FirstUnlocal));
                        foreach (TorrentMatch m in matchlist)
                        {
                            if (m.Title.IndexOf(watch.show.FirstUnlocal) != -1 && m.Title.IndexOf(watch.quality) != -1 && m.Title.IndexOf(watch.source) != -1)
                            {
                                t++;
                                Log.Instance().Print(string.Format("Match {0}", m.Title));
                                bool ok = TorrentEngine.Instance().StartDownloading(m.Url, "", true, m.cookie, m.Id, "", "", watch.folder);
                            }
                        }
                        Log.Instance().Print(string.Format("[{0}] matches found", t));
                        break;

                    case "Missing episodes":
                        IEnumerable <string> eps = watch.show.AllUnlocal.Split('|').ToList();
                        eps     = (watch.includespecials ? eps : eps.Where(e => e.StartsWith("S00") == false).ToList());
                        var ccc = (from m in matchlist from ep in eps where m.Title.Contains(ep) select m).ToList();
                        foreach (TorrentMatch m in matchlist)
                        {
                            foreach (string ep in eps)
                            {
                                int y = 0;
                                Log.Instance().Print(string.Format("Searching for episode [{0}]", ep));
                                if (m.Title.Contains(ep) && m.Title.IndexOf(watch.quality) != -1 && m.Title.IndexOf(watch.source) != -1)
                                {
                                    y++;
                                    Log.Instance().Print(string.Format("Match {0}", m.Title));
                                    bool ok = TorrentEngine.Instance().StartDownloading(m.Url, "", true, m.cookie, m.Id, "", "", watch.folder);
                                }
                                Log.Instance().Print(string.Format("[{0}] matches found for episodes [{1}]", y, m.Title));
                            }
                        }
                        break;
                    }
                }
                catch { }
            })
            {
                IsBackground = true,
                Name         = "MyTorrents Autograbber"
            };

            AutoSearch.Start();
        }