getLogger() public method

public getLogger ( ) : Logger
return Logger
Beispiel #1
0
        // Called from MusicBee
        public PluginInfo Initialise(IntPtr apiPtr)
        {
            //MessageBox.Show("Initialised(" + apiPtr + ")");
            musicBee = new MusicBeeApiInterface();
            musicBee.Initialise(apiPtr);

            info.PluginInfoVersion = PluginInfoVersion;
            info.Name = "Lyrics Reloaded!";
            info.Description = "Lyrics loading done properly!";
            info.Author = "Phillip Schichtel <Quick_Wango>";
            info.TargetApplication = "MusicBee";
            info.Type = PluginType.LyricsRetrieval;
            info.VersionMajor = 1;
            info.VersionMinor = 0;
            info.Revision = 1;
            info.MinInterfaceVersion = 20;
            info.MinApiRevision = 25;
            info.ReceiveNotifications = ReceiveNotificationFlags.StartupOnly;
            info.ConfigurationPanelHeight = 0;

            try
            {
                lyricsReloaded = new LyricsReloaded(musicBee.Setting_GetPersistentStoragePath());
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred during plugin startup: " + e.Message);
                throw;
            }

            try
            {
                lyricsReloaded.loadConfigurations();
            }
            catch (Exception e)
            {
                MessageBox.Show("An error occurred during plugin startup, send this file to the developer:\n\n" +
                                lyricsReloaded.getLogger().getFileInfo().FullName);
                lyricsReloaded.getLogger().error(e.Message);
                throw;
            }

            return info;
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            Console.Title = "LyricsReloaded!";
            Console.OutputEncoding = Encoding.UTF8;
            Console.InputEncoding = Encoding.UTF8;
            Console.CancelKeyPress += (sender, eventArgs) => Console.WriteLine("Bye!");

            String providerName = null;
            String artist = null;
            String title = null;
            String album = null;

            int result = 0;

            int argc = args.Length;

            if (argc > 0)
            {
                providerName = args[0];
            }
            if (argc > 1)
            {
                artist = args[1];
            }
            if (argc > 2)
            {
                title = args[2];
            }
            if (argc > 3)
            {
                album = args[3];
            }

            LyricsReloaded lyricsReloaded = new LyricsReloaded(".");
            lyricsReloaded.loadConfigurations();

            lyricsReloaded.checkForNewVersion(newAvailable =>
            {
                if (newAvailable)
                {
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.Write("A new version is available!");
                    Console.ResetColor();
                    Console.WriteLine();
                }
            });

            if (String.IsNullOrWhiteSpace(providerName))
            {
                Console.WriteLine("The providers:");
                foreach (Provider p in lyricsReloaded.getProviderManager().getProviders())
                {
                    Console.WriteLine(" - {0}", p.getName());
                }
                Console.Write("Enter the provider: ");
                providerName = Console.ReadLine();
                if (providerName != null)
                {
                    providerName = providerName.Trim();
                }
            }
            if (String.IsNullOrWhiteSpace(artist))
            {
                Console.Write("Enter the artist: ");
                artist = Console.ReadLine();
                if (artist != null)
                {
                    artist = artist.Trim();
                }
            }
            if (String.IsNullOrWhiteSpace(title))
            {
                Console.Write("Enter the title: ");
                title = Console.ReadLine();
                if (title != null)
                {
                    title = title.Trim();
                }
            }

            Provider provider = lyricsReloaded.getProviderManager().getProvider(providerName);
            if (provider == null)
            {
                lyricsReloaded.getLogger().error("Provider {0} not found!", providerName);
                result = 1;
            }
            else
            {
                Console.Write("Provider {0}: ", providerName);
                try
                {
                    String lyrics = provider.getLyrics(artist, title, album);
                    if (String.IsNullOrWhiteSpace(lyrics))
                    {
                        Console.WriteLine("failed (not found)");
                        lyricsReloaded.getLogger().error("Lyrics not found!");
                    }
                    else
                    {
                        Console.WriteLine("success\n\n" + lyrics);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("failed (internal error)");
                    Console.WriteLine(e.ToString());
                }
            }

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();

            return result;
        }
Beispiel #3
0
        protected WebResponse executeRequest(HttpWebRequest request)
        {
            // request configration
            string[] acceptEncodingValues = request.Headers.GetValues("Accept-Encoding");
            if (acceptEncodingValues == null || acceptEncodingValues.Length == 0)
            {
                // we support gzip if nothing else was specified.
                request.Headers.Add("Accept-Encoding", "gzip");
            }
            if (request.UserAgent == null)
            {
                request.UserAgent = lyricsReloaded.getDefaultUserAgent();
            }

            request.Accept = "*/*";
            request.Headers.Add("Accept-Encoding", "gzip");

            // load the response
            WebResponse     webResponse;
            String          contentString = null;
            Encoding        encoding      = Encoding.ASCII; // default encoding as the last fallback
            HttpWebResponse response;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    throw new WebException("The operation has timed out.", e);
                }
                else if (e.Status == WebExceptionStatus.ProtocolError || e.Status == WebExceptionStatus.UnknownError)
                {
                    throw new WebException("Ops, something went wrong. (Report this please)", e);
                }
                throw;
            }
            using (response)
            {
                if (response.CharacterSet != null)
                {
                    encoding = Encoding.GetEncoding(response.CharacterSet); // the response encoding specified by the server. this should be enough
                }

                Stream responsesStream = response.GetResponseStream();
                if (responsesStream != null)
                {
                    responsesStream.ReadTimeout = timeout;
                    if (String.Compare(response.ContentEncoding, "gzip", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // gzip compression detected, wrap the stream with a decompressing gzip stream
                        lyricsReloaded.getLogger().debug("gzip compression detected");
                        responsesStream = new GZipStream(responsesStream, CompressionMode.Decompress);
                    }
                    MemoryStream content    = new MemoryStream();
                    const int    bufferSize = 4096;
                    byte[]       buffer     = new byte[bufferSize];
                    int          bytesRead;

                    do
                    {
                        bytesRead = responsesStream.Read(buffer, 0, bufferSize);
                        if (bytesRead <= 0)
                        {
                            break;
                        }
                        content.Write(buffer, 0, bytesRead);
                    }while (bytesRead > 0);
                    responsesStream.Close();

                    contentString = encoding.GetString(content.GetBuffer()); // decode the data with the currently known encoding
                    Match match = ENCODING_REGEX.Match(contentString);       // search for a encoding specified in the content
                    if (match.Success)
                    {
                        try
                        {
                            Encoding tmp = Encoding.GetEncoding(match.Groups[1].ToString()); // try to get a encoding from the name
                            if (!encoding.Equals(tmp))
                            {
                                encoding      = tmp;
                                contentString = encoding.GetString(content.GetBuffer()); // decode again with the newly found encoding
                            }
                        }
                        catch (ArgumentException)
                        {}
                    }
                    content.Close();
                }
                webResponse = new WebResponse(contentString, encoding, response.Headers);
            }

            return(webResponse);
        }