コード例 #1
0
        public string GetArtistCountryFromAlbums(string artist, List <string> albums)
        {
            for (int i = 0; i < albums.Count; i++)
            {
                string url = FormatURL(artist, albums[i]);
                Console.WriteLine("Accessing " + url);

                HtmlWeb      web = new HtmlWeb();
                HtmlDocument doc = web.Load(url);
                if (doc == null)
                {
                    Console.WriteLine("Couldn't find page for " + artist); return(null);
                }

                Music.ArtistLocation curArtist = GetArtistDataFromRelease(artist, doc);

                if (curArtist != null)
                {
                    Console.WriteLine("Found country " + curArtist.country);
                    return(curArtist.country);
                }
            }

            return(null);
        }
コード例 #2
0
        public string GetArtistCountry(string artist, string album)
        {
            if (artistData == null)
            {
                artistData = new Dictionary <string, Music.ArtistLocation>();
            }

            if (artistData.ContainsKey(artist))
            {
                Console.WriteLine("Origins of " + artist + " already known: " + artistData[artist].country);
                return(null);
            }

            string url = FormatURL(artist, album);

            Console.WriteLine("Accessing " + url);

            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(url);

            if (doc == null)
            {
                Console.WriteLine("Couldn't find page for " + artist); return(null);
            }

            Music.ArtistLocation curArtist = GetArtistDataFromRelease(artist, doc);

            if (curArtist != null)
            {
                artistData.Add(artist, curArtist);
                return(curArtist.country);
            }

            return(null);
        }
コード例 #3
0
        public Music.ArtistLocation ParseNode(HtmlNode node, string knownCountry)
        {
            Music.ArtistLocation tempArtist = new Music.ArtistLocation("dummy")
            {
                country  = knownCountry,
                location = ""
            };

            HtmlNode flag = node.SelectSingleNode(".//span");

            if (flag != null)
            {
                Console.WriteLine("Country from flag: " + flag.InnerText);
                tempArtist.country = flag.InnerText.Trim();
            }

            string loc       = "";
            string con       = "";
            string innerText = node.InnerText;

            string[] originParts = innerText.Split(",");
            if (originParts.Length > 1)
            {
                for (int i = 1; 1 < originParts.Length - 1; i++)
                {
                    con       = originParts[^ i];
コード例 #4
0
        public override Music.ArtistLocation GetArtistData(string artist, HtmlDocument doc)
        {
            Music.ArtistLocation curArtist = new Music.ArtistLocation(artist);

            HtmlNode metadataContainer = doc.DocumentNode.SelectSingleNode("//div[@id='band_stats']");

            if (metadataContainer == null)
            {
                Console.WriteLine("Couldn't find information for " + artist); return(null);
            }

            HtmlNode metadata = metadataContainer.SelectSingleNode(".//dl[@class='float_left']");

            List <HtmlNode> dt = metadata.SelectNodes(".//dt").ToList();
            List <HtmlNode> dd = metadata.SelectNodes(".//dd").ToList();

            string country  = "";
            string location = "";

            for (int i = 0; i < dt.Count; i++)
            {
                if (dt[i].InnerText == "Country of origin:")
                {
                    HtmlNode link = dd[i].SelectSingleNode(".//a");
                    if (link != null)
                    {
                        Console.Write("Link. ");
                        country = link.InnerText;
                    }
                    else
                    {
                        Console.Write("Not a link. ");
                        country = dd[i].InnerText;
                    }
                    Console.WriteLine("Country: " + country);
                    //curArtist.country = country;
                }
                else if (dt[i].InnerText == "Location:")
                {
                    location = dd[i].InnerText;
                    Console.WriteLine("Location: " + location);
                    //curArtist.location = location;
                }
            }

            if (country != "")
            {
                curArtist.country = country;

                if (location != "")
                {
                    curArtist.location = location;
                }

                return(curArtist);
            }

            return(null);
        }
コード例 #5
0
        public override Music.ArtistLocation GetArtistData(string artist, HtmlDocument doc)
        {
            Music.ArtistLocation curArtist = new Music.ArtistLocation(artist);

            HtmlNode metadataContainer = doc.DocumentNode.SelectSingleNode("//div[@class='metadata-column']");

            if (metadataContainer == null)
            {
                Console.WriteLine("Couldn't find information for " + artist); return(null);
            }

            HtmlNode metadata = metadataContainer.SelectSingleNode(".//dl[@class='catalogue-metadata']");

            List <HtmlNode> dt = metadata.SelectNodes(".//dt").ToList();
            List <HtmlNode> dd = metadata.SelectNodes(".//dd").ToList();

            for (int i = 0; i < dt.Count; i++)
            {
                if (dt[i].InnerText == "Founded In")
                {
                    string founded = dd[i].InnerText;

                    string[] originParts = founded.Split(",");
                    string   country     = originParts[^ 1];
コード例 #6
0
        public override Music.ArtistLocation GetArtistData(string artist, HtmlDocument doc)
        {
            Music.ArtistLocation curArtist = new Music.ArtistLocation(artist);
            string artistLink = "";
            string country    = "";
            string location   = "";

            Music.ArtistLocation tempArtist;

            #region Parsing search page
            HtmlNode searchResultTable = doc.DocumentNode.SelectSingleNode("//table[@class='tbl']");
            if (searchResultTable == null)
            {
                Console.WriteLine("Couldn't find search results for " + artist); return(null);
            }

            List <HtmlNode> tableRows = searchResultTable.SelectSingleNode("//tbody").SelectNodes(".//tr").ToList();

            foreach (HtmlNode row in tableRows)
            {
                List <HtmlNode> tableColumns = row.SelectNodes(".//td").ToList();
                //Console.WriteLine("Sort name: " + tableColumns[1].InnerText);
                if (tableColumns[1].InnerText == artist)
                {
                    artistLink = tableColumns[0].SelectSingleNode(".//a").Attributes["href"].Value;

                    if (tableColumns[4].InnerText != "")
                    {
                        if (tableColumns[4].SelectSingleNode(".//span") != null)
                        {
                            country           = tableColumns[4].InnerText.Trim();
                            curArtist.country = country;
                            //Console.WriteLine("Country: " + country);
                        }
                        //else Console.WriteLine("Area: " + tableColumns[4].InnerText);
                    }

                    break;
                }
            }

            //Console.WriteLine("Found link: " + artistLink);
            //Console.WriteLine("Found country: " + country);
            #endregion

            string artistURL = "https://musicbrainz.org" + artistLink;

            #region Parsing artist page
            HtmlWeb      web  = new HtmlWeb();
            HtmlDocument doc2 = web.Load(artistURL);
            if (doc2 == null)
            {
                Console.WriteLine("Couldn't find page for " + artist); return(null);
            }

            Console.WriteLine("Succesfully navigated to " + artistURL);

            HtmlNode propertiesContainer = doc2.DocumentNode.SelectSingleNode("//dl[@class='properties']");
            if (propertiesContainer == null)
            {
                Console.WriteLine("Couldn't find information for " + artist); return(null);
            }

            HtmlNode areaInfo      = propertiesContainer.SelectSingleNode(".//dd[@class='area']");
            HtmlNode beginAreaInfo = propertiesContainer.SelectSingleNode(".//dd[@class='begin_area']");

            if (areaInfo != null)
            {
                //Console.WriteLine("Parse areaInfo");
                tempArtist = ParseNode(areaInfo, country);
                if (country == "" && tempArtist.country != "")
                {
                    country = tempArtist.country;  curArtist.country = tempArtist.country;
                }
                if (tempArtist.location.Length > location.Length)
                {
                    location = tempArtist.location; curArtist.location = tempArtist.location;
                }
            }

            if (beginAreaInfo != null)
            {
                //Console.WriteLine("Parse beginAreaInfo");
                tempArtist = ParseNode(beginAreaInfo, country);
                if (country == "" && tempArtist.country != "")
                {
                    curArtist.country = tempArtist.country;
                }
                if (tempArtist.location.Length > location.Length)
                {
                    curArtist.location = tempArtist.location;
                }
            }
            #endregion

            if (curArtist.country != "")
            {
                //Console.WriteLine("Country at end: " + curArtist.country);

                if (curArtist.location != "")
                {
                    //Console.WriteLine("Location at end: " + curArtist.location);
                }
                Console.WriteLine("CurArtist at end: " + curArtist.GetLocation());
                return(curArtist);
            }

            return(null);
        }
コード例 #7
0
        public Music.ArtistLocation GetArtistDataFromRelease(string artist, HtmlDocument doc)
        {
            Music.ArtistLocation curArtist = new Music.ArtistLocation(artist);
            string artistLink = "";
            string country    = "";
            string location   = "";

            Music.ArtistLocation tempArtist;

            #region Parsing search page
            HtmlNode searchResultTable = doc.DocumentNode.SelectSingleNode("//table[@class='tbl']");
            if (searchResultTable == null)
            {
                Console.WriteLine("Couldn't find search results for " + artist); return(null);
            }

            List <HtmlNode> tableRows = searchResultTable.SelectSingleNode("//tbody").SelectNodes(".//tr").ToList();

            foreach (HtmlNode row in tableRows)
            {
                List <HtmlNode> tableColumns = row.SelectNodes(".//td").ToList();
                //Console.WriteLine("Sort name: " + tableColumns[1].InnerText);
                if (tableColumns[1].InnerText == artist)
                {
                    artistLink = tableColumns[1].SelectSingleNode(".//a").Attributes["href"].Value;
                    break;
                }
                else if (CheckEqual(artist, tableColumns[1].InnerText))
                {
                    artistLink = tableColumns[1].SelectSingleNode(".//a").Attributes["href"].Value;
                    break;
                }
                else
                {
                    Console.WriteLine("\"" + tableColumns[1].InnerText + "\" does not equal \"" + artist + "\"");
                }
            }

            if (artistLink == "")
            {
                return(null);
            }

            Console.WriteLine("Found link: " + artistLink);
            Console.WriteLine("Found country: " + country);
            #endregion

            string artistURL = "https://musicbrainz.org" + artistLink;

            #region Parsing artist page
            HtmlWeb      web  = new HtmlWeb();
            HtmlDocument doc2 = web.Load(artistURL);
            if (doc2 == null)
            {
                Console.WriteLine("Couldn't find page for " + artist); return(null);
            }

            Console.WriteLine("Succesfully navigated to " + artistURL);

            HtmlNode propertiesContainer = doc2.DocumentNode.SelectSingleNode("//dl[@class='properties']");
            if (propertiesContainer == null)
            {
                Console.WriteLine("Couldn't find information for " + artist); return(null);
            }

            HtmlNode areaInfo      = propertiesContainer.SelectSingleNode(".//dd[@class='area']");
            HtmlNode beginAreaInfo = propertiesContainer.SelectSingleNode(".//dd[@class='begin_area']");

            // Parse begin area first to check where the band was founded
            if (beginAreaInfo != null)
            {
                //Console.WriteLine("Parse areaInfo");
                tempArtist = ParseNode(beginAreaInfo, country);
                if (country == "" && tempArtist.country != "")
                {
                    country = tempArtist.country; curArtist.country = tempArtist.country;
                }
                if (tempArtist.location.Length > location.Length)
                {
                    location = tempArtist.location; curArtist.location = tempArtist.location;
                }
            }

            if (areaInfo != null)
            {
                //Console.WriteLine("Parse beginAreaInfo");
                tempArtist = ParseNode(areaInfo, country);
                if (country == "" && tempArtist.country != "")
                {
                    curArtist.country = tempArtist.country;
                }
                //Only update location if it matches the origin country
                if (tempArtist.location.Length > location.Length && tempArtist.country == curArtist.country)
                {
                    curArtist.location = tempArtist.location;
                }
            }
            #endregion

            if (curArtist.country != "" && curArtist.country != null)
            {
                //Console.WriteLine("Country at end: " + curArtist.country);

                if (curArtist.location != "")
                {
                    //Console.WriteLine("Location at end: " + curArtist.location);
                }
                Console.WriteLine("CurArtist at end: " + curArtist.GetLocation());
                return(curArtist);
            }

            return(null);
        }