Example #1
0
        public static Image GetImage(ref PlayerInstance player)
        {
            var   track = player.Track.Album;
            Regex rgx   = new Regex("[^a-zA-Z0-9 -]");

            track = rgx.Replace(track, "");
            var path = Path.Combine(Directory.GetCurrentDirectory(), $"{track}.png");

            if (File.Exists(path))
            {
                //byte[] imgdata = System.IO.File.ReadAllBytes(path);
                return(Image.FromFile(path));
            }
            else
            {
                var       images    = HTMLHelper.GetImages($"{player.Track.Name} {player.Track.Album} {player.Track.Artist} album artwork", HTMLHelper.Image_source).Result.First();
                WebClient client    = new WebClient();
                var       byteArray = client.DownloadData(images);
                Image     x         = (Bitmap)((new ImageConverter()).ConvertFrom(byteArray));
                x.Save(path);
                using (var ms = new MemoryStream(byteArray))
                {
                    return(Image.FromStream(ms));
                }
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            var width = (100 + scale + 10) < 130 ? 100 + scale + 10 : 130;

            Console.SetWindowSize(width, 25);
            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            player  = new PlayerInstance();
            handler = new EventHandler.ConsoleEventDelegate(ConsoleEventCallback);
            InitializeDiscod();
            try
            {
                FacebookHelper.RenewAccessToken();
            }
            catch
            {
                MessageBox.Show("Can't evaluate Facebook OAuth Token, please check your token in settings (S) or your network connection.", "iTunesListener", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            EventHandler.SetConsoleCtrlHandler(handler, true);
            Task.Run(delegate
            {
                while (true)
                {
                    ActiveDevice = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active).ToList().OrderByDescending(x => x.AudioMeterInformation.MasterPeakValue).FirstOrDefault();
                    Thread.Sleep(1000);
                }
            });
            Task.Run((Action)ActionListenerThread);
            Task.Run((Action)HeaderThread);
            if (Properties.Settings.Default.WebServiceListening)
            {
                Task.Run((Action)WebServiceListener);
            }
            if (Properties.Settings.Default.ChromaSDKEnable)
            {
                Task.Run((Action)ChromaUpdateAsync);
            }

            mainThread = new Thread(new ThreadStart(MainThread));
            mainThread.Start();
        }