Пример #1
0
        public UGSearch(IReadOnlyCollection <IWebElement> divList)
        {
            List <IWebElement>    asList = new List <IWebElement>(divList);
            List <UGSearchResult> all    = new List <UGSearchResult>();

            if (asList.Count != 0)
            {
                asList.RemoveAt(0); // Remove header
                string currentArtist = "";
                foreach (IWebElement div in asList)
                {
                    string artistMaybe = div.FindElements(By.XPath("./*"))[0].Text.Trim();
                    if (artistMaybe.Length > 0)
                    {
                        currentArtist = artistMaybe;
                    }
                    if (!UGSearchResult.PaidOnly(div))
                    {
                        all.Add(new UGSearchResult(currentArtist, div));
                    }
                }
                all.Sort(HumanRankReviews);
            }
            this.allResults = all;
        }
Пример #2
0
        public static bool PaidOnly(IWebElement div)
        {
            var    columns = UGSearchResult.GetColumns(div);
            string type    = columns[3].Text.Trim().ToLower();

            return(type == "official" || type == "pro");
        }
Пример #3
0
 private int HumanRankReviews(UGSearchResult first, UGSearchResult second)
 {
     // Special human bayesian judgment call case
     if (first.rating == 4 && second.rating == 5 &&
         second.numRatings < 5 && first.numRatings > 30)
     {
         return(-1); // Give precedence to lots of reviews over a few 5s
     }
     if (first.rating == second.rating)
     {
         return(first.numRatings > second.numRatings ? -1 : 1); // Same stars, take with more reviews
     }
     return(first.rating > second.rating ? -1 : 1);             // Just go by number of stars
 }
Пример #4
0
        public UGSearchResult(string artist, IWebElement div)
        {
            this.artist = artist;
            var columns    = UGSearchResult.GetColumns(div);
            var nameCell   = columns[1];
            var ratingCell = columns[2];
            var typeCell   = columns[3];

            if (this.HasRating(ratingCell))
            {
                this.numRatings = this.GetNumRatings(ratingCell);
                this.rating     = this.GetRating(ratingCell);
            }
            this.songAndVer      = nameCell.Text.Trim();
            this.href            = nameCell.FindElement(By.TagName("a")).GetProperty("href");
            this.canStoreContent = this.TextFormattedContent(typeCell);
        }
Пример #5
0
        public UGTab GetTab(UGSearchResult searchResult)
        {
            string tab;

            if (!searchResult.canStoreContent)
            {
                tab = "Cannot store in text format, see: " + searchResult.href;
            }
            else
            {
                this.browser.Navigate().GoToUrl(searchResult.href);
                tab = browser.FindElementByTagName("code").Text;
            }
            return(new UGTab(searchResult.artist,
                             searchResult.songAndVer,
                             searchResult.rating,
                             searchResult.numRatings,
                             tab));
        }
Пример #6
0
        public List <UGTab> GetAllTabs(List <BasicSong> allTracks, UGType type)
        {
            Directory.CreateDirectory(DIR_NAME);
            Console.WriteLine($"Getting {allTracks.Count} tabs");
            List <UGTab> tabs = new List <UGTab>();

            try
            {
                foreach (BasicSong track in allTracks)
                {
                    string fullTrack = $"{track.artist} - {track.title}";
                    Console.WriteLine($"Searching for tabs for {fullTrack}");
                    UGSearch       searchResults = this.GetSearchResult(track, type);
                    UGSearchResult bestCandidate = searchResults.GetBestResult();
                    Console.WriteLine($"Getting tab for {fullTrack}");
                    if (bestCandidate == null)
                    {
                        Console.WriteLine($"No tab found for {fullTrack}");
                        File.AppendAllText($"{DIR_NAME}/NOT_FOUND.txt", fullTrack + "\n");
                    }
                    else
                    {
                        UGTab tab = this.GetTab(bestCandidate);
                        tabs.Add(tab);
                        File.WriteAllText($"{DIR_NAME}/{this.FileSafeFileName(tab)}", tab.tab);
                    }
                }
                browser.Quit();
                return(tabs);
            }
            catch
            {
                browser.Quit();
                throw;
            }
        }