Esempio n. 1
0
        public static Release QueryRelease(
            IEnumerable <int> lengths,
            DirectoryInfo dirInfo,
            MultipleItemChooser.MultipleChoiseHeuristic heuristic)
        {
            FreedbAPI freedb = new FreedbAPI();

            IEnumerable <int> offsets = DiscID.MakeOffsets(lengths);
            uint   discid             = DiscID.DiscId(offsets);
            string freeDbQuery        = DiscID.FreedbQuery(discid, offsets);

            var result = freedb.Query(freeDbQuery);

            if (result.Code == FreedbAPI.ResponseCodes.CODE_200_ExactMatchFound ||
                result.Code == FreedbAPI.ResponseCodes.CODE_211_InexactMatchFoundListFollows ||
                result.Code == FreedbAPI.ResponseCodes.CODE_210_OkOrMultipleExactMatches)
            {
                MultipleItemChooser chooser   = new MultipleItemChooser(dirInfo.Name, discid, result.Value, heuristic);
                Release             preferred = chooser.ChooseQuery();

                bool found = !Object.ReferenceEquals(preferred, null);

                if (!found && result.Value.Count() > 0)
                {
                    LoggerWriter.WriteLine(Tokens.Info, "Multiple matches found but heuristic could not decide,");
                    LoggerWriter.WriteLine(Tokens.Info, "it might help to set the heuristic to fuzzy or rename");
                    LoggerWriter.WriteLine(Tokens.Info, "the folders so that they contain the artist name.");
                }

                if (found)
                {
                    FreedbAPI.Result <Release> disc = freedb.Read(preferred);

                    if (disc.Code == FreedbAPI.ResponseCodes.CODE_210_OkOrMultipleExactMatches)
                    {
                        return(disc.Value);
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading offsets from mp3s--------------------------------------------------");
            IEnumerable <int> discOffsets = DiscID.MakeOffsets(MP3Tools.LoadFileLenthFromMp3s(
                                                                   args[0],
                                                                   delegate(FileInfo f) { return((int)f.Length); },
                                                                   delegate(FileInfo f) { return(0); }));

            int counter = 0;

            foreach (int offset in discOffsets)
            {
                Console.WriteLine("Marker {0}: Offset: {1}", counter, offset);
                counter++;
            }

            Console.WriteLine("Build freedb query---------------------------------------------------------");
            string query = DiscID.FreedbQuery(DiscID.DiscId(discOffsets), discOffsets);

            Console.WriteLine(query);

            FreedbAPI freedb = new FreedbAPI();

            Console.WriteLine("Get freedb sites-----------------------------------------------------------");
            FreedbAPI.Result <IEnumerable <Site> > sites = freedb.GetSites();
            foreach (var item in sites.Value)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Get freedb categories------------------------------------------------------");
            FreedbAPI.Result <IEnumerable <string> > categories = freedb.GetCategories();
            foreach (var item in categories.Value)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Query----------------------------------------------------------------------");
            FreedbAPI.Result <IEnumerable <Release> > result = freedb.Query(query);
            if (result.Value.Count() > 0)
            {
                foreach (var item in result.Value)
                {
                    Console.WriteLine(item);
                }
            }
            else
            {
                Console.WriteLine("Query unsuccessful: " + result.Code);
                return;
            }

            Console.WriteLine("Read first entry-----------------------------------------------------------");
            FreedbAPI.Result <Release> disc = freedb.Read(result.Value.First());
            if (disc.Value != null)
            {
                Console.WriteLine(disc.Value);
            }
            else
            {
                Console.WriteLine("Unable to retrieve cd entry. Code: " + disc.Code);
            }
        }