public override LyricsResult ParseResult(string requestArtist, string requestTrackTitle, string result) { XNamespace xmlSpace = XNamespace.Get("http://api.chartlyrics.com/"); XDocument document = XDocument.Parse(result); XElement root = document.Root; string artist = root.Element(xmlSpace.GetName("LyricArtist")).Value.Trim(); string song = root.Element(xmlSpace.GetName("LyricSong")).Value.Trim(); string text = root.Element(xmlSpace.GetName("Lyric")).Value.Trim(); LyricsResult lyricsResult = new LyricsResult(this.Name, artist, song, text); XElement url = root.Element(xmlSpace.GetName("LyricUrl")); if (url != null) { lyricsResult.AdditionalFields["Url"] = url.Value.Trim(); } XElement rank = root.Element(xmlSpace.GetName("LyricRank")); if (rank != null) { lyricsResult.AdditionalFields["Rank"] = rank.Value.Trim(); } XElement covertArtUrl = root.Element(xmlSpace.GetName("LyricCovertArtUrl")); if (rank != null) { lyricsResult.AdditionalFields["CovertArtUrl"] = covertArtUrl.Value.Trim(); } return(lyricsResult); }
/// <summary> /// /// </summary> /// <param name="query"></param> /// <returns></returns> private Object GetSource(String query, String data) { try { if (String.IsNullOrEmpty(query)) { return(null); } if (String.IsNullOrEmpty(data)) { return(null); } Regex regex = new Regex(@"^(artist:)(.*?)(\|album:)(.*?)(\|song:)(.*?)$"); Console.WriteLine(regex.IsMatch("artist:e|album:1|song:5")); if (!regex.IsMatch(data)) { return(null); } Match match = regex.Match(data); String artist = match.Groups[2].Value.Trim(); String album = match.Groups[4].Value.Trim(); String song = match.Groups[6].Value.Trim(); LyricWiki lyricWiki = new LyricWiki(); lyricsResult = lyricWiki.getSong(artist, song); return(lyricsResult); } catch { } return(null); }
public override LyricsResult ParseResult(string requestArtist, string requestTrackTitle, string result) { XNamespace xmlSpace = XNamespace.Get("http://api.chartlyrics.com/"); XDocument document = XDocument.Parse(result); XElement root = document.Root; string artist = root.Element(xmlSpace.GetName("LyricArtist")).Value.Trim(); string song = root.Element(xmlSpace.GetName("LyricSong")).Value.Trim(); string text = root.Element(xmlSpace.GetName("Lyric")).Value.Trim(); var lyricsResult = new LyricsResult(Name, artist, song, text); XElement url = root.Element(xmlSpace.GetName("LyricUrl")); if (url != null) { lyricsResult.AdditionalFields["Url"] = url.Value.Trim(); } XElement rank = root.Element(xmlSpace.GetName("LyricRank")); if (rank != null) { lyricsResult.AdditionalFields["Rank"] = rank.Value.Trim(); } XElement covertArtUrl = root.Element(xmlSpace.GetName("LyricCovertArtUrl")); if (rank != null) { lyricsResult.AdditionalFields["CovertArtUrl"] = covertArtUrl.Value.Trim(); } return lyricsResult; }
public SearchResult GetLyrics(string artist, string song, out string lyrics) { lyrics = string.Empty; LyricsResult result = _lyricsWiki.getSong(artist, song); Encoding iso8859 = Encoding.GetEncoding(ISO_8859); // thanks to davidreis string url = Encoding.UTF8.GetString(iso8859.GetBytes(result.url)); if (String.IsNullOrEmpty(result.lyrics)) { return(SearchResult.NotFound); } if (!String.IsNullOrEmpty(url)) { lyrics = RetrieveSong(url); if (String.IsNullOrEmpty(lyrics)) { return(SearchResult.NotFound); } } else { lyrics = result.lyrics; lyrics = HttpUtility.HtmlDecode(lyrics); } return(SearchResult.Found); }
public override LyricsResult ParseResult(string requestArtist, string requestTrackTitle, string result) { string artist = StringHelper.GetTextBetween(result, "<h2>", "</h2>"); if (!artist.EndsWith(" LYRICS")) throw new Exception(); artist = artist.Substring(0, artist.Length - " LYRICS".Length); string title = StringHelper.GetTextBetween(result, "<b>", "</b>").Trim('"'); string lyrics = StringHelper.GetTextBetween(result, "<!-- start of lyrics -->", "<!-- end of lyrics -->").Trim(); lyrics = lyrics.Replace("<br />", ""); var lyricsResult = new LyricsResult(Name, artist, title, lyrics); return lyricsResult; }
public void UpdateLyrics() { foreach (var currentTrack in this.mSelectedTracks) { var artist = currentTrack.Artist; var song = currentTrack.Name; if (string.IsNullOrEmpty(currentTrack.Location) || string.IsNullOrEmpty(artist) || string.IsNullOrEmpty(song)) { continue; } String[] row = { song, artist, "Processing..." }; var index = (int)this.mForm.Invoke(this.mForm.m_DelegateAddRow, new Object[] { row }); if (currentTrack.Lyrics != null && !this.mOverwrite) { this.mForm.Invoke(this.mForm.m_DelegateUpdateRow, new Object[] { index, ResultCodes.Skipped }); continue; } try { var result = new LyricsResult { lyrics = string.Empty }; if (this.mLyricsWiki.checkSongExists(artist, song)) { result = this.mLyricsWiki.getSong(artist, song); if (this.mOverwrite || currentTrack.Lyrics == null) { SetLyrics(currentTrack, result, index); } } else { result.url = string.Format("http://lyrics.wikia.com/{0}:{1}", artist, song.Replace(" ", "_")); SetLyrics(currentTrack, result, index); } } catch (Exception e) { //throw; MessageBox.Show(e.Message); this.mForm.Invoke(this.mForm.m_DelegateUpdateRow, new Object[] { index, ResultCodes.NotFound }); } } MessageBox.Show(Resources.LyricsUpdater_UpdateLyrics_Completed, Resources.LyricsUpdater_UpdateLyrics_Completed, MessageBoxButtons.OK, MessageBoxIcon.Information); }
public String GetHtmlContent(string searchText, String data, String sense, Object source, Dictionary <String, String> uniqueLinks) { if (source == null) { source = this.GetSource(searchText, data); } if (source == null) { throw new ArgumentNullException("Source is NULL"); } this.lyricsResult = source as LyricsResult; if (source == null) { throw new InvalidCastException("Source is not of correct type"); } bool hasData = false; String html = String.Empty; if (this.lyricsResult != null && !this.lyricsResult.lyrics.Equals("Not found", StringComparison.InvariantCultureIgnoreCase)) { hasData = true; html += " <td id=\"td1\" style=\"width: 100%;vertical-align: top\">"; html += " <table style=\"width: 100%\" cellpadding=\"0\" cellspacing=\"0\">"; html += " <tr>"; html += " <td style=\"border-bottom: solid 1px Silver; width: 100%; color: Black; font-family: Calibri;font-size: 16px;\">"; //html += " <b>L</b>yrics (" + this.lyricsResult.song + ") "; html += " <a href=\"http://www.lyricwiki.org\" style=\"font-size:small;color:green;text-decoration:none;font-family:Calibri\">source: lyricwiki.org"; html += " </a>"; html += " </td>"; html += " </tr>"; html += " <tr>"; html += " <td id=\"lyricBox\" title=\"" + this.lyricsResult.url + "\" style=\"padding-bottom: 3px;font-family: Calibri; font-size: small;\">"; String lyric = this.lyricsResult.lyrics;//this.lyricsResult.GetLyricsHtml(); html += lyric.Substring(0, lyric.Length > 400 ? 400 : lyric.Length); html += " <br />"; html += " <a target=\"_blank\" href=\"" + this.lyricsResult.url + "\">full lyrics »"; html += " </a>"; html += " </td>"; html += " </tr>"; html += " <tr><td style=\"height: 5px\"> </td></tr>"; html += " </table>"; html += " </td>"; } return(hasData ? html : String.Empty); }
public string getLyricSynchron(string artist, string title) { this.artist = artist; this.title = title; try { // Step 1: search title as it is lyricsResult = lyricWiki.getSong(this.artist, this.title); if (isLyric(lyricsResult.lyrics)) { return(lyricsResult.lyrics); } //Thread.Sleep(1000); //// Step 2: search with parentheses and other disturbance removed //optimizeString(ref this.artist, ref this.title); //lyricsResult = lyricWiki.getSongResult(this.artist, this.title); //if (isLyric(lyricsResult.lyrics)) //{ // return lyricsResult.lyrics; //} //Thread.Sleep(1000); //// Step 3: search with altered and strings if any //this.artist = LyricUtil.changeAnd_and_and(this.artist); //this.title = LyricUtil.changeAnd_and_and(this.title); //lyricsResult = lyricWiki.getSongResult(this.artist, this.title); //if (isLyric(lyricsResult.lyrics)) //{ // return lyricsResult.lyrics; //} //Thread.Sleep(3000); // final step: return "Not found" if no lyric found return("Not found"); } catch (Exception e) { //System.Windows.Forms.MessageBox.Show(e.ToString()); //System.Windows.Forms.MessageBox.Show(lyricsResult.); Console.Write(e.Message); return(""); } }
public override LyricsResult ParseResult(string requestArtist, string requestTrackTitle, string result) { string artist = StringHelper.GetTextBetween(result, "<h2>", "</h2>"); if (!artist.EndsWith(" LYRICS")) { throw new Exception(); } artist = artist.Substring(0, artist.Length - " LYRICS".Length); string title = StringHelper.GetTextBetween(result, "<b>", "</b>").Trim('"'); string lyrics = StringHelper.GetTextBetween(result, "<!-- start of lyrics -->", "<!-- end of lyrics -->").Trim(); lyrics = lyrics.Replace("<br />", ""); var lyricsResult = new LyricsResult(Name, artist, title, lyrics); return(lyricsResult); }
private bool SearchForWiki() { DelegateClass del = lyricWiki.getSong; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 9) { // If the user has aborted stop the search and return (false) if (Abort || lyricSearch.SearchHasEnded) { return(false); } else if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); string lyric = lyricsResult.lyrics; Encoding iso8859 = Encoding.GetEncoding("ISO-8859-1"); lyricsResult.lyrics = Encoding.UTF8.GetString(iso8859.GetBytes(lyricsResult.lyrics)); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && IsLyric(lyricsResult.lyrics)) { return(true); } else { noOfTries = 0; return(false); } }
public static String GetLyricsHtml(this LyricsResult lresult) { String lyrichtml = String.Empty; try { String endpoint = lresult.url; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(endpoint); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { String txt = reader.ReadToEnd(); txt = txt.Replace("\r", String.Empty).Replace("\n", String.Empty); Regex regex = new Regex("(<div(\\s+)class=(\"|')lyricbox(\"|')(\\s*)>)(.*?)(<div(\\s*)>)(.*?)(</div>)(.*?)(</div>)"); if (regex.IsMatch(txt)) { lyrichtml = regex.Matches(txt)[0].Groups[6].Value; } } } catch { } return(lyrichtml); }
/// <summary> /// Sets the lyrics taking into account varios factors /// </summary> /// <param name="currentTrack"></param> /// <param name="result"></param> /// <param name="index"></param> private void SetLyrics(IITFileOrCDTrack currentTrack, LyricsResult result, int index) { string lyrics; var isFound = ResultCodes.Found; if (result.lyrics.Equals("instrumental", StringComparison.OrdinalIgnoreCase)) { lyrics = result.lyrics; } else { lyrics = LyricsDecoder.DecodeLyrics(result.url); if (string.IsNullOrEmpty(lyrics)) { isFound = ResultCodes.NotFound; } } if (isFound == ResultCodes.Found) { currentTrack.Lyrics = lyrics; } this.mForm.Invoke(this.mForm.m_DelegateUpdateRow, new Object[] { index, isFound }); }
private bool searchForWiki(string artist, string title) { DelegateClass del = lyricWiki.getSongResult; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 15) { // If the user has aborted stop the search and return (false) if (Abort) { return(false); } if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && isLyric(lyricsResult.lyrics)) { return(true); } else { noOfTries = 0; return(false); } }
/// <summary> /// 获取歌词 /// </summary> /// <param name="artist">表演者</param> /// <param name="title">标题</param> public static Lyrics GetLyrics(string artist, string title) { if (string.IsNullOrEmpty(artist) && string.IsNullOrEmpty(title)) { return(null); } if (title.ToLower().Contains("instrumental")) { return(null); } //获取所有可能的歌词 Parameters parameters = new Parameters(); parameters["Artist"] = Encode(artist); parameters["Title"] = Encode(title); parameters["Flag"] = "2"; foreach (var server in servers) { string url = ConnectionBase.ConstructUrlWithParameters("http://" + server + "/dll/lyricsvr.dll?sh", parameters); string file = new ConnectionBase().Get(url); //分析返回的XML文件 LyricsResult result = null; try { using (MemoryStream stream = new MemoryStream()) using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(file); writer.Flush(); XmlSerializer serializer = new XmlSerializer(typeof(LyricsResult)); stream.Position = 0; result = (LyricsResult)serializer.Deserialize(stream); } } catch { } if (result == null || result.Count == 0) { continue; } //选出最合适的歌词文件 LyricsItem selected = result[0]; double dist = double.MaxValue; string lArtist = artist.ToLower(); string lTitle = title.ToLower(); foreach (var item in result) { string iArtist = item.Artist.ToLower(); string iTitle = item.Title.ToLower(); if (lArtist == iArtist && lTitle == iTitle) { selected = item; break; } else if (lArtist.Length < 100 && lTitle.Length < 100 && iArtist.Length < 100 && iTitle.Length < 100) { int dist1 = Distance(lArtist, iArtist); int dist2 = Distance(lTitle, iTitle); double temp = ((double)(dist1 + dist2)) / (lArtist.Length + lTitle.Length); if (temp < dist) { dist = temp; selected = item; } } } //下载歌词文件 Parameters parameters2 = new Parameters(); parameters2["Id"] = selected.Id.ToString(); parameters2["Code"] = VerifyCode(selected.Artist, selected.Title, selected.Id); string url2 = ConnectionBase.ConstructUrlWithParameters("http://" + server + "/dll/lyricsvr.dll?dl", parameters2); string file2 = new ConnectionBase().Get(url2); //生成Lyrics的实例 if (string.IsNullOrEmpty(file2)) { continue; } try { return(new Lyrics(file2)); } catch { continue; } } return(null); }
static void Main(string[] args) { //NounCollection coll = NounCollection.Instance; //String [] related = null; //Console.WriteLine(coll.Nouns["hello"].GetDescription(0, out related)); //using (StreamWriter writer = new StreamWriter(File.Create(@"\1.txt"))) //{ // for (int index = 0; index < 256; index++) // writer.WriteLine(String.Concat(index, " ", (char)index)); //} //Console.WriteLine((int)'e');//'é'); //BingSearch search = new BingSearch(); //search.SearchWeb("apj kalam"); //Wikipedia wClass = new Wikipedia(new WikiQueryEngine()); //Console.WriteLine(wClass.IsArticleAvailable("Plain white T's")); //SearchSuggestion searchSuggest = wClass.SearchArticles("Plain white T's", 10); //foreach (SearchSuggestionItem sItem in searchSuggest.Section) //{ // Console.WriteLine(sItem.Text + "\n\t" + sItem.Description + "\n" + sItem.Url); //} //Console.WriteLine(wClass.GetArticle("Seattle", false).Introduction); OmukSemantics semantics = new OmukSemantics(); //YSearch search = new YSearch(); //YSearchResultCollection resCollection = search.SearchWeb("me genera serotonina listening to Viva la Vida by Coldplay", 0, 10, ref semantics); BingSearch bsearch = new BingSearch(); bsearch.SearchWeb("Am I Dreaming by Xscape", 0, 10, ref semantics); semantics.PostSearch(); semantics.FormContext(); LyricWiki wiki = new LyricWiki(); LyricsResult lyrics = wiki.getSong("Rihanna", "Umbrella"); Console.WriteLine(lyrics.lyrics); //Console.WriteLine(""); LastFmService service = new LastFmService(); //service.GetArtistInfo( //MusicBrainz mb = new MusicBrainz(); // mb.GetAlbums //Grooveshark gshark = new Grooveshark(); //GSSong[] song = gshark.SearchSong("Sugar", 2); //LyricWiki wiki = new LyricWiki(); //LyricsResult lyrics = wiki.getSong("R.e.m", "Moon river"); //lyrics.GetLyricsHtml(); //SongResult songs = wiki.searchSongs("R.e.m", "Moon river"); //String artist = "Flo rida"; //String album = "Sugar"; //int year = 2009; //String[] albums = null; //String res = wiki.getAlbum(ref artist, ref album, ref year, out albums); //AlbumData[] album = (AlbumData[])wiki.getArtist(ref artist); //LWLyrics lyrics = wiki.GetLyricsForSong("Flo rida", "sugar"); //Console.WriteLine(wiki.IsArtist("rihanna")); //String[] albums = wiki.GetAlbums("rihanna"); //LastFmService service = new LastFmService(); //LFMArtist artist = service.GetArtistInfo("Rihanna"); //List<LFMArtist> albums = service.SearchArtist("Kid Cudi", 0); //Immem immem = new Immem(); //List<ImmemSearchItem> items = immem.SearchMedia("Rihanna good girl gone bad", "music", 0, 10); MusicBrainz mb = new MusicBrainz(); List <MBAlbum> albums = mb.GetAlbums(String.Empty, "Rihanna", "73e5e69d-3554-40d8-8516-00cb38737a1c", 0, 10); List <MBSong> songs = mb.GetSongs("oh Carol", "Neil", "", "", "", 0, 2); //YouTube yt = new YouTube(); //List<YTVideo> videos = yt.SearchVideos("oh carol", 0, 3); //RottenTomatoes rt = new RottenTomatoes(); //String val = rt.GetTomatometerScore("http://www.rottentomatoes.com/m/1009437-heidi/"); /* * Twitter twitter = new Twitter(); * ////twitter.SearchTwitter("i gotta feeling", 0, 10); * TMovieTrendsClass mTrends = new TMovieTrendsClass(); * twitter.GetMovieTrends("The Martian", ref mTrends); * Console.WriteLine(""); */ //twitter.GetMovieTrends("\"the proposal\"",ref mTrends); //twitter.GetMovieTrends("\"year one\"", ref mTrends); //twitter.GetMovieTrends("\"Terminator Salvation\"", ref mTrends); //twitter.GetMovieTrends("\"Next day air\"", ref mTrends); //twitter.GetMovieTrends("\"Imagine That\"", ref mTrends); //twitter.GetMovieTrends("\"Taking of Pelham 1 2 3", ref mTrends); //twitter.GetMovieTrends("Wolverine", ref mTrends); //using (StreamWriter writer = new StreamWriter(File.Create("trend.txt"))) //{ // foreach (KeyValuePair<String, int> keyval in mTrends.Trend) // { // if (keyval.Value > 3) // writer.WriteLine(String.Format("{0} {1}", keyval.Key, keyval.Value)); // } //} //TSearchResultCollection twRes = twitter.SearchTwitter("palm pre", 0, 15); //Eventful evntful = new Eventful (); //EventCollection coll = evntful.SearchEvents("San Jose", 0, 10); //Digg digg = new Digg(); //List<DiggResult> res = digg.SearchDigg("Hello", 0, 10); return; }