Example #1
0
 public void Close(PluginCloseReason reason)
 {
     //MessageBox.Show("Close(" + reason + ")");
     lyricsReloaded.getLogger().info("Plugin disabled");
     lyricsReloaded.shutdown();
     lyricsReloaded = null;
 }
        public void checkForNewVersion(UpdateCheckerCallback callback)
        {
            Version local = Assembly.GetAssembly(GetType()).GetName().Version;

            LyricsReloaded lr = this;

            Thread updateChecker = new Thread(() => {
                WebClient cl = new WebClient(lr, 5000);
                try
                {
                    bool result         = false;
                    WebResponse respone = cl.get("https://raw.githubusercontent.com/mbfrankz/LyricsReloaded/stable/LyricsReloaded/Properties/AssemblyInfo.cs");
                    if (respone != null)
                    {
                        String content = respone.getContent();
                        if (!String.IsNullOrWhiteSpace(content))
                        {
                            Regex versionRegex = new Regex("AssemblyVersion\\(\"(?<version>[^\\s\\*]+)\"\\)", RegexOptions.Compiled | RegexOptions.Singleline);
                            Match match        = versionRegex.Match(content);
                            if (match.Success)
                            {
                                Version remote = Version.Parse(match.Groups["version"].Value);
                                result         = remote.CompareTo(local) > 0;
                            }
                        }
                    }

                    callback(result);
                }
                catch (Exception e)
                {
                    lr.logger.error("Failed to check for updates: {0}", e.Message);
                }
            })
            {
                IsBackground = true,
                Name         = "LyricsReloaded - Version Check"
            };

            updateChecker.Start();
        }
Example #3
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;
        }
Example #4
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;
        }
Example #5
0
 public WebClient(LyricsReloaded lyricsReloaded, int timeout)
 {
     this.lyricsReloaded = lyricsReloaded;
     this.timeout        = timeout;
 }
Example #6
0
 public void setUp()
 {
     this.lr = new LyricsReloaded(".");
     lr.loadConfigurations();
 }
Example #7
0
 public WebClient(LyricsReloaded lyricsReloaded, int timeout)
 {
     this.lyricsReloaded = lyricsReloaded;
     this.timeout = timeout;
 }