コード例 #1
0
ファイル: TrackInfo.cs プロジェクト: morpheusxx/Webradio_MP2
        private string GetCover(string title, string artist)
        {
            // Search with GraceNote
            try
            {
                var cover2 = new GracenoteClient("8038400-D6D9583FE60EA28CE621BC0EAD6ED8A0").Search(new SearchCriteria
                {
                    Artist        = artist,
                    TrackTitle    = title,
                    SearchMode    = SearchMode.BestMatchWithCoverArt,
                    SearchOptions = SearchOptions.Cover
                });

                foreach (var a in cover2.Albums.SelectMany(c => c.Artwork.Where(a => a.Uri.AbsoluteUri != string.Empty)))
                {
                    return(a.Uri.AbsoluteUri);
                }
            }
            catch (Exception ex)
            {
                return(string.Empty);
            }

            return(string.Empty);
        }
コード例 #2
0
ファイル: gArtist.cs プロジェクト: blackmetalcoder/CDMolnet
        private List <Skiva> DenSkivan(string artist, string album)
        {
            List <Skiva> S           = new List <Skiva>();
            var          clientCover = new GracenoteClient("687559541-407A6818314DF26BB17DC1E4AB57BD4E");
            var          Cover       = BestMatchSearchWithOptions(clientCover, artist, album);

            foreach (var skiva in Cover.Albums)
            {
                string s = "";
                try
                {
                    //s = skiva.Artwork.First().Uri.AbsoluteUri;
                    s = Cover.Albums.First().Artwork.First().Uri.AbsoluteUri;
                }
                catch (Exception ex)
                {
                    s = "";
                }
                Skiva NySkiva = new Skiva(skiva.Id, skiva.Title, skiva.Year.ToString(), s, skiva.Genre.First());
                foreach (var track in skiva.Tracks)
                {
                    NySkiva.Lat.Add(new Latar(track.Number.ToString(), track.Title, track.Id));
                }
                S.Add(NySkiva);
            }
            return(S);
        }
コード例 #3
0
ファイル: gArtist.cs プロジェクト: blackmetalcoder/CDMolnet
 private static SearchResult BestMatchSearchWithOptions(GracenoteClient client, string artist, string album)
 {
     return(client.Search(new SearchCriteria
     {
         AlbumTitle = album,
         Artist = artist,
         SearchMode = SearchMode.BestMatch,
         SearchOptions = SearchOptions
     }));
 }
コード例 #4
0
ファイル: gArtist.cs プロジェクト: blackmetalcoder/CDMolnet
        private List <Skiva> GetSkivData(string grupp)
        {
            Groups.Clear();
            var client      = new GracenoteClient("687559541-407A6818314DF26BB17DC1E4AB57BD4E");
            var clientCover = new GracenoteClient("687559541-407A6818314DF26BB17DC1E4AB57BD4E");
            int iLoopar     = 0;

            result = client.Search(new SearchCriteria
            {
                Artist = grupp,
                //SearchOptions = SearchOptions,
                Range = new Range(1, 500)
            });
            int iAntal = result.Count;

            if (iAntal > 100)
            {
                iLoopar = 8;
                //iLoopar = iAntal / 20;
            }
            else
            {
                iLoopar = iAntal / 20;
            }

            for (int i = 0; i <= iLoopar; i++)
            {
                var Album = client.Search(new SearchCriteria
                {
                    Artist        = grupp,
                    SearchOptions = SearchOptions,
                    Range         = new Range(i, 20)
                });
                foreach (var skiva in Album.Albums)
                {
                    string s = "";
                    try
                    {
                        s = skiva.Artwork.First().Uri.AbsoluteUri;
                    }
                    catch (Exception ex)
                    {
                        s = "";
                    }
                    Skiva NySkiva = new Skiva(skiva.Id, skiva.Title, skiva.Year.ToString(), s, skiva.Genre.First());
                    this.Groups.Add(NySkiva);
                }
            }
            return(Groups);
        }
コード例 #5
0
		/// <summary>
		/// Search for and download album art in a separate thread
		/// </summary>
		void search(string title, string artist) {
			if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(artist))
				return;		// Not enough information, so give up
			m_Task.Run(delegate(TaskRunner.Task task) {
				if (!string.IsNullOrEmpty(Program.Album.ReleaseId)) {
					// MusicBrainz data - try there first
					Uri art = CoverArtArchive.GetCoverArtUri(Program.Album.ReleaseId);
					if (task.Stop)
						return;
					if (art != null) {
						Status("Downloading cover art from MusicBrainz");
						if(downloadImage(art, task))
							return;
					}
				}
				if (task.Stop)
					return;
				// Not found - try Gracenote
				Status("Searching Gracenote database");
				GracenoteClient Client = new GracenoteClient(Program.GracenoteKey);
				if (task.Stop)
					return;
				SearchResult result = Client.Search(new SearchCriteria() {
					AlbumTitle = title,
					Artist = artist,
					SearchMode = SearchMode.BestMatchWithCoverArt
				});
				var a = result.Albums.FirstOrDefault();
				if (a != null) {
					var i = a.Artwork.FirstOrDefault();
					if (task.Stop)
						return;
					if (i != null) {
						string filename = System.IO.Path.GetTempFileName().Replace(".tmp", ".jpg");
						Status("Downloading album cover");
						i.Download(filename);
						using (Image img = Image.FromFile(filename))
							setImage(img);
						File.Delete(filename);
						Status("");
						return;
					}
				}
				Status("Album not found - drag an image from the web");
				if (task.Stop)
					return;
				System.Diagnostics.Process.Start("http://www.google.co.uk/search?q=" + HttpUtility.UrlEncode("\"" + artist + "\" \"" + title + "\" album cover"));
			});
		}
コード例 #6
0
		/// <summary>
		/// Search button clicked
		/// </summary>
		private void btnOK_Click(object sender, EventArgs e) {
			m_Task.Stop();			// Stop any existing search
			Results.Items.Clear();
			string artist = txtArtist.Text;
			string title = txtTitle.Text;
			m_Task.Run(async delegate(TaskRunner.Task t) {
				int count = 0;			// No of items added
				int insertPoint = 0;	// Where to insert close matches
				try {
					// Build query
					List<string> b = new List<string>();
					if (!string.IsNullOrWhiteSpace(artist))
						b.Add("artist:\"" + artist.Replace("\"", "") + "\"");
					if (!string.IsNullOrWhiteSpace(title))
						b.Add("release:\"" + title.Replace("\"", "") + "\"");
					if (b.Count == 0) {
						Status("No artist or title provided");
						return;
					}
					Status("Searching MusicBrainz database");
					// Get list of releases
					foreach (Release r in (await Release.SearchAsync(string.Join(" AND ", b.ToArray()))).Items) {
						if (t.Stop)
							return;
						try {
							// Get recordings for release (i.e. list of Mediums/Media)
							Release rel = await Release.GetAsync(r.Id, "recordings");
							foreach (Medium m in rel.MediumList.Items) {
								if (t.Stop)
									return;
								// Artists
								string art = string.Join(", ", r.Credits.Select(c => c.Artist.Name).ToArray());
								ListViewItem item = new ListViewItem(new string[] { art, r.Title, r.Date, m.Tracks.Items.Count + ":" + string.Join(",", m.Tracks.Items.Select(tr => tr.Recording.Title)) });
								// Make an AlbumInfo
								item.Tag = new AlbumInfo(art, rel, m);
								if (SoundEx.Equals(artist, art) && SoundEx.Equals(title, r.Title)) {
									// Close match - put near top of list
									Despatch(delegate() { Results.Items.Insert(insertPoint, item); });
									insertPoint++;
								} else {
									// Not so close - put at end
									Despatch(delegate() { Results.Items.Add(item); });
								}
								count++;
							}
						} catch (Hqub.MusicBrainz.API.HttpClientException) {
							// Ignore these exceptions - they seem to happen all the time
						}
					}
				} catch (Hqub.MusicBrainz.API.HttpClientException) {
					// Ignore these exceptions - they seem to happen all the time
				}
				if (count == 0 && !t.Stop) {
					// Nothing found - try Gracenote (NB - no track lengths here)
					Status("Searching Gracenote database");
					GracenoteClient Client = new GracenoteClient(Program.GracenoteKey);
					SearchResult result = Client.Search(new SearchCriteria() {
						AlbumTitle = title,
						Artist = artist
					});
					foreach (Album a in result.Albums) {
						if (t.Stop)
							return;
						ListViewItem item = new ListViewItem(new string[] { a.Artist, a.Title, a.Year.ToString(), a.Tracks.Count() + ":" + string.Join(",", a.Tracks.Select(tr => tr.Title)) });
						item.Tag = new AlbumInfo(a);
						if (SoundEx.Equals(artist, a.Artist) && SoundEx.Equals(title, a.Title))
							Despatch(delegate() { Results.Items.Add(item); });
						else {
							Despatch(delegate() { Results.Items.Insert(insertPoint, item); });
							insertPoint++;
						}
						count++;
					}
				}
				if (!t.Stop) {
					if (count > 0) {
						// Resize columns to fit data
						Invoke((Action)delegate() { Results.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); });
						Status("Search complete");
					} else
						Status("Nothing found");
				}
			});
		}
コード例 #7
0
        /// <summary>
        /// CDDB リードコマンドの実行
        /// </summary>
        /// <param name="cmdArray"></param>
        /// <returns></returns>
        private async Task<string> Read(string[] cmdArray)
        {
            ReadCommand command = null;

            if (ReadCommand.TryCreate(cmdArray, out command) == false)
            {
                return "500 Command syntax error.";
            }

            GracenoteClient client = new GracenoteClient(this.gracenoteClinetId, this.gracenoteEndpoint);

            Album[] albums = await client.GetAlbumInfo(this.gracenoteUserId, command.DiscId);

            return CddbUtil.CreateReadResponse(command, albums);
        }
コード例 #8
0
ファイル: TrackInfo.cs プロジェクト: BigGranu/Webradio_MP2
        private string GetCover(string title, string artist)
        {
            // Search with GraceNote
            try
            {
                var cover2 = new GracenoteClient("8038400-D6D9583FE60EA28CE621BC0EAD6ED8A0").Search(new SearchCriteria
                {
                    Artist = artist,
                    TrackTitle = title,
                    SearchMode = SearchMode.BestMatchWithCoverArt,
                    SearchOptions = SearchOptions.Cover
                });

                foreach (var a in cover2.Albums.SelectMany(c => c.Artwork.Where(a => a.Uri.AbsoluteUri != string.Empty)))
                {
                    return a.Uri.AbsoluteUri;
                }
            }
            catch (Exception ex)
            {
                return string.Empty;
            }

            return string.Empty;
        }
コード例 #9
0
        private async void btnApplyCoverImg_Click(object sender, RoutedEventArgs e)
        {
            if (m_AllFilesHasTagImage)
            {
                await ConfirmBox("Action Rejected", "All files are already has tag image", MessageDialogStyle.Affirmative);

                return;
            }

            var mySettings = new MetroDialogSettings()
            {
                NegativeButtonText = "Close now", AnimateShow = false, AnimateHide = false
            };

            var controller = await this.ShowProgressAsync("Front Image Changing", "Preparing...", settings : mySettings);

            controller.SetIndeterminate();
            controller.SetCancelable(true);
            controller.Maximum = Convert.ToDouble(m_FilesPath.Count);
            double dblCnt = 0.0;

            if (listBox.SelectedItems.Count == 0)
            {
                MessageDialogResult mdr = await ConfirmBox("Do you want to continue?", "Proceed for all files", MessageDialogStyle.AffirmativeAndNegative);

                if (mdr == MessageDialogResult.Affirmative)
                {
                    listBox.SelectAll();
                }
            }

            foreach (SoundSourceFilePathModel selected in listBox.SelectedItems)
            {
                string fPath = m_FilesPath.FirstOrDefault(p => selected.FileName == System.IO.Path.GetFileName(p));

                if (fPath != null)
                {
                    FileInfo fi = new FileInfo(fPath);
                    // 파일에 ReadOnly 걸려있으면 없애버린다.
                    if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        FileAttributes attr = fi.Attributes & ~FileAttributes.ReadOnly;

                        System.IO.File.SetAttributes(fPath, attr);
                    }

                    TagLib.File tlFile     = TagLib.File.Create(fPath);
                    int         pictureLen = tlFile.Tag.Pictures.Length;
                    if (pictureLen == 0)
                    {
                        #region Gracenote 에서 이미지 찾아오는 핵심 루틴
                        GracenoteClient client = new GracenoteClient(GRACENOTE_CLIENT_ID);
                        SearchCriteria  sc     = new SearchCriteria();
                        sc.Artist        = tlFile.Tag.FirstArtist;
                        sc.TrackTitle    = tlFile.Tag.Title;
                        sc.SearchMode    = SearchMode.BestMatchWithCoverArt;
                        sc.SearchOptions = SearchOptions.ArtistImage;
                        SearchResult result = client.Search(sc);
                        if (result.Status.Code == "OK")
                        {
                            if (result.Albums.First().Artwork.Count() > 0)
                            {
                                Uri foundImgUri = result.Albums.First().Artwork.First().Uri;

                                using (WebClient wc = new WebClient())
                                {
                                    byte[]       btImg     = wc.DownloadData(foundImgUri.ToString());
                                    MemoryStream ms        = new MemoryStream(btImg);
                                    Stream       coverStrm = ms;

                                    TagLib.Picture pic = new TagLib.Picture();
                                    pic.Type = TagLib.PictureType.FrontCover;
                                    pic.Data = TagLib.ByteVector.FromStream(coverStrm);

                                    tlFile.Tag.Pictures = new TagLib.IPicture[] { pic };
                                    tlFile.Save();

                                    controller.SetProgress(dblCnt);
                                    controller.SetMessage("Completed : " + System.IO.Path.GetFileName(fPath));
                                }

                                dblCnt += 1.0;
                            }

                            await Task.Delay(50);
                        }
                        #endregion
                    }
                }
            }

            await controller.CloseAsync();

            ListBoxBind();

            SetFooterMsg("List Binding Complete!!", "Total Sound Sources : " + int.Parse(dblCnt.ToString()).ToString());
        }