示例#1
0
        public List<object> LookupAlbumInfo(bool useCache, bool useCUE, bool useCTDB, CTDBMetadataSearch metadataSearch)
        {
            List<object> Releases = new List<object>();

            CUEMetadata dbmeta = null;

            if (useCache && _localDB != null)
            {
                List<string> fullAudioPaths = this.SourcePaths.ConvertAll(p => CUEToolsLocalDBEntry.NormalizePath(p));
                var myEntry = _localDB.Find(e => e.Equals(this.TOC, fullAudioPaths));
                if (myEntry != null)
                    dbmeta = myEntry.Metadata;
            }

            if (dbmeta != null)
                Releases.Add(new CUEMetadataEntry(dbmeta, TOC, "local"));

            //if (useCache)
            //{
            //    try
            //    {
            //        CUEMetadata cache = CUEMetadata.Load(TOC.TOCID);
            //        if (cache != null)
            //            Releases.Add(new CUEMetadataEntry(cache, TOC, "local"));
            //    }
            //    catch (Exception ex)
            //    {
            //        System.Diagnostics.Trace.WriteLine(ex.Message);
            //    }
            //}

            if (useCUE)
            {
                if (dbmeta == null || !dbmeta.Contains(cueMetadata))
                {
                    if (cueMetadata.Contains(taglibMetadata) || !taglibMetadata.Contains(cueMetadata))
                        Releases.Add(new CUEMetadataEntry(new CUEMetadata(cueMetadata), TOC, "cue"));
                }
                if (dbmeta == null || !dbmeta.Contains(taglibMetadata))
                {
                    if (!cueMetadata.Contains(taglibMetadata))
                        Releases.Add(new CUEMetadataEntry(new CUEMetadata(taglibMetadata), TOC, "tags"));
                }
            }

            if (useCache && _localDB != null)
            {
                foreach (var entry in _localDB)
                    if (entry.DiscID == TOC.TOCID && entry.Metadata != null && (dbmeta == null || !dbmeta.Contains(entry.Metadata)))
                        Releases.Add(new CUEMetadataEntry(entry.Metadata, TOC, "local"));
            }

            bool ctdbFound = false;
            if (useCTDB)
            {
                ShowProgress("Looking up album via CTDB...", 0.0, null, null);
                var ctdb = new CUEToolsDB(TOC, proxy);
                ctdb.ContactDB(_config.advanced.CTDBServer, "CUETools " + CUEToolsVersion, null, false, false, metadataSearch);
                foreach (var meta in ctdb.Metadata)
                {
                    CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                    metadata.FillFromCtdb(meta, TOC.FirstAudio - 1);
                    CDImageLayout toc = TOC; //  TocFromCDEntry(meta);
                    Releases.Add(new CUEMetadataEntry(metadata, toc, meta.source));
                    ctdbFound = true;
                }
            }

            if (!ctdbFound && metadataSearch == CTDBMetadataSearch.Extensive)
            {
                ShowProgress("Looking up album via Freedb...", 0.0, null, null);

                FreedbHelper m_freedb = new FreedbHelper();
                m_freedb.Proxy = proxy;
                m_freedb.UserName = _config.advanced.FreedbUser;
                m_freedb.Hostname = _config.advanced.FreedbDomain;
                m_freedb.ClientName = "CUETools";
                m_freedb.Version = CUEToolsVersion;
                m_freedb.SetDefaultSiteAddress("freedb.org");

                QueryResult queryResult;
                QueryResultCollection coll;
                string code = string.Empty;
                try
                {
                    CDEntry cdEntry = null;
                    code = m_freedb.Query(AccurateRipVerify.CalculateCDDBQuery(_toc), out queryResult, out coll);
                    if (code == FreedbHelper.ResponseCodes.CODE_200)
                    {
                        ShowProgress("Looking up album via Freedb... " + queryResult.Discid, 0.5, null, null);
                        code = m_freedb.Read(queryResult, out cdEntry);
                        if (code == FreedbHelper.ResponseCodes.CODE_210)
                        {
                            CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                            metadata.FillFromFreedb(cdEntry, TOC.FirstAudio - 1);
                            CDImageLayout toc = TocFromCDEntry(cdEntry);
                            Releases.Add(new CUEMetadataEntry(metadata, toc, "freedb"));
                        }
                    }
                    else
                        if (code == FreedbHelper.ResponseCodes.CODE_210 ||
                            code == FreedbHelper.ResponseCodes.CODE_211)
                        {
                            int i = 0;
                            foreach (QueryResult qr in coll)
                            {
                                ShowProgress("Looking up album via freedb... " + qr.Discid, (++i + 0.0) / coll.Count, null, null);
                                CheckStop();
                                code = m_freedb.Read(qr, out cdEntry);
                                if (code == FreedbHelper.ResponseCodes.CODE_210)
                                {
                                    CUEMetadata metadata = new CUEMetadata(TOC.TOCID, (int)TOC.AudioTracks);
                                    metadata.FillFromFreedb(cdEntry, TOC.FirstAudio - 1);
                                    CDImageLayout toc = TocFromCDEntry(cdEntry);
                                    Releases.Add(new CUEMetadataEntry(metadata, toc, "freedb"));
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    if (ex is StopException)
                        throw ex;
                }
            }

            ShowProgress("", 0, null, null);
            return Releases;
        }
示例#2
0
        private void Lookup(object o)
        {
            ICDRipper audioSource = o as ICDRipper;
            int mbresults_count = 0; // have to cache results.Count, because it sometimes hangs in it, and we don't want UI thread to hang.
            string musicbrainzError = "";

            data.Releases.RaiseListChangedEvents = false;

            cueSheet = new CUESheet(_config);
            cueSheet.OpenCD(audioSource);
            cueSheet.Action = CUEAction.Encode;

            this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " CTDB..."; });
            cueSheet.UseCUEToolsDB("CUERipper " + CUESheet.CUEToolsVersion, selectedDriveInfo.drive.ARName, false, loadAllMetadata ? CTDBMetadataSearch.Extensive : _config.advanced.metadataSearch);
            cueSheet.CTDB.UploadHelper.onProgress += new EventHandler<Krystalware.UploadHelper.UploadProgressEventArgs>(UploadProgress);
            this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " AccurateRip..."; });
            cueSheet.UseAccurateRip();

            General.SetCUELine(cueSheet.Attributes, "REM", "DISCID", AccurateRipVerify.CalculateCDDBId(audioSource.TOC), false);

            try
            {
                CUEMetadata cache = CUEMetadata.Load(audioSource.TOC.TOCID);
                if (cache != null)
                    data.Releases.Add(new CUEMetadataEntry(cache, audioSource.TOC, "local"));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }

            foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
            {
                data.Releases.Add(CreateCUESheet(audioSource, ctdbMeta));
            }

            if (data.Releases.Count == 0 || loadAllMetadata)
            {
                loadAllMetadata = false;

                //this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " MusicBrainz..."; });

                //ReleaseQueryParameters p = new ReleaseQueryParameters();
                //p.DiscId = audioSource.TOC.MusicBrainzId;
                //Query<Release> results = Release.Query(p);
                //MusicBrainzService.Proxy = _config.GetProxy();
                //MusicBrainzService.XmlRequest += new EventHandler<XmlRequestEventArgs>(MusicBrainz_LookupProgress);

                //try
                //{
                //    foreach (Release release in results)
                //    {
                //        release.GetEvents();
                //        release.GetTracks();
                //        data.Releases.Add(CreateCUESheet(audioSource, release));
                //    }
                //    mbresults_count = results.Count;
                //}
                //catch (Exception ex)
                //{
                //    System.Diagnostics.Trace.WriteLine(ex.Message);
                //    if (!(ex is MusicBrainzNotFoundException))
                //        musicbrainzError = ex.Message;
                //}
                //MusicBrainzService.Proxy = null;
                //MusicBrainzService.XmlRequest -= new EventHandler<XmlRequestEventArgs>(MusicBrainz_LookupProgress);

                this.BeginInvoke((MethodInvoker)delegate() { toolStripStatusLabel1.Text = Properties.Resources.LookingUpVia + " Freedb..."; });

                FreedbHelper m_freedb = new FreedbHelper();
                m_freedb.Proxy = _config.GetProxy();
                m_freedb.UserName = _config.advanced.FreedbUser;
                m_freedb.Hostname = _config.advanced.FreedbDomain;
                m_freedb.ClientName = "CUERipper";
                m_freedb.Version = CUESheet.CUEToolsVersion;
                m_freedb.SetDefaultSiteAddress(Properties.Settings.Default.MAIN_FREEDB_SITEADDRESS);

                QueryResult queryResult;
                QueryResultCollection coll;
                string code = string.Empty;
                try
                {
                    FreeDB_LookupProgress(this);
                    code = m_freedb.Query(AccurateRipVerify.CalculateCDDBQuery(audioSource.TOC), out queryResult, out coll);
                    if (code == FreedbHelper.ResponseCodes.CODE_200)
                    {
                        bool duplicate = false;
                        foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
                            if (ctdbMeta.source == "freedb" && ctdbMeta.id == queryResult.Category + "/" + queryResult.Discid)
                                duplicate = true;
                        if (!duplicate)
                        {
                            FreeDB_LookupProgress(queryResult.Category + "/" + queryResult.Discid);
                            CDEntry cdEntry;
                            code = m_freedb.Read(queryResult, out cdEntry);
                            if (code == FreedbHelper.ResponseCodes.CODE_210)
                            {
                                CUEMetadataEntry r = CreateCUESheet(audioSource, cdEntry);
                                data.Releases.Add(r);
                            }
                        }
                    }
                    else
                        if (code == FreedbHelper.ResponseCodes.CODE_210 ||
                            code == FreedbHelper.ResponseCodes.CODE_211)
                        {
                            foreach (QueryResult qr in coll)
                            {
                                bool duplicate = false;
                                foreach (var ctdbMeta in cueSheet.CTDB.Metadata)
                                    if (ctdbMeta.source == "freedb" && ctdbMeta.id == qr.Category + "/" + qr.Discid)
                                        duplicate = true;
                                if (!duplicate)
                                {
                                    CDEntry cdEntry;
                                    FreeDB_LookupProgress(qr.Category + "/" + qr.Discid);
                                    code = m_freedb.Read(qr, out cdEntry);
                                    if (code == FreedbHelper.ResponseCodes.CODE_210)
                                    {
                                        CUEMetadataEntry r = CreateCUESheet(audioSource, cdEntry);
                                        data.Releases.Add(r);
                                    }
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
            }

            if (data.Releases.Count == 0)
            {
                data.Releases.Add(CreateCUESheet(audioSource));
            }
            _workThread = null;
            if (musicbrainzError != "")
                musicbrainzError = musicbrainzError + ": ";
            while (backgroundWorkerArtwork.IsBusy)
            {
                Thread.Sleep(100);
            }
            this.BeginInvoke((MethodInvoker)delegate()
            {
                SetupControls();
                data.Releases.RaiseListChangedEvents = true;
                data.Releases.ResetBindings();
                //bnComboBoxRelease.SelectedIndex = 0;
                toolStripStatusAr.Enabled = cueSheet.ArVerify.ARStatus == null;
                toolStripStatusAr.Text = cueSheet.ArVerify.ARStatus == null ? cueSheet.ArVerify.WorstTotal().ToString() : "";
                toolStripStatusAr.ToolTipText = "AccurateRip: " + (cueSheet.ArVerify.ARStatus ?? "found") + ".";
                toolStripStatusCTDB.Enabled = cueSheet.CTDB.DBStatus == null;
                toolStripStatusCTDB.Text = cueSheet.CTDB.DBStatus == null ? cueSheet.CTDB.Total.ToString() : "";
                toolStripStatusCTDB.ToolTipText = "CUETools DB: " + (cueSheet.CTDB.DBStatus ?? "found") + ".";
                toolStripStatusLabelMusicBrainz.Enabled = true;
                toolStripStatusLabelMusicBrainz.BorderStyle = mbresults_count > 0 ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner;
                toolStripStatusLabelMusicBrainz.Text = mbresults_count > 0 ? mbresults_count.ToString() : "";
                toolStripStatusLabelMusicBrainz.ToolTipText = "Musicbrainz: " + (mbresults_count > 0 ? mbresults_count.ToString() + " entries found." : (musicbrainzError + "click to submit."));
                if (_config.advanced.coversSearch != CUEConfigAdvanced.CTDBCoversSearch.None)
                    backgroundWorkerArtwork.RunWorkerAsync(new BackgroundWorkerArtworkArgs() { cueSheet = cueSheet, meta = data.selectedRelease });
            });
        }