Example #1
0
        public static bool PullData(out iTunesInfo info)
        {
            info = default;
            string name = null, author = null, album = null;
            long   trackLength = 0, playerPosition = 0;

            if (!Api.GetCurrentTrackName(ref name))
            {
                return(false);
            }
            if (!Api.GetCurrentTrackAuthor(ref author))
            {
                return(false);
            }
            if (!Api.GetCurrentTrackAlbum(ref album))
            {
                return(false);
            }
            if (!Api.GetCurrentTrackLength(ref trackLength))
            {
                return(false);
            }
            if (!Api.GetCurrentPosition(ref playerPosition))
            {
                return(false);
            }

            var timeLeft = TimeSpan.FromSeconds(trackLength - playerPosition);

            info = new iTunesInfo(name, author, album, timeLeft);

            return(true);
        }
Example #2
0
        static void Main(string[] args)
        {
            if (!Api.Initialize())
            {
                int last = Marshal.GetLastWin32Error();
                Console.WriteLine("ERROR: " + last);
                return;
            }

            using var client = new DiscordRpcClient("784746309226594305");
            client.Initialize();

            Console.WriteLine("Ready!");
            iTunesInfo data = default;

            while (true)
            {
                if (Console.KeyAvailable && Console.ReadKey(false).Key == ConsoleKey.Escape)
                {
                    break;
                }
                if (!iTunesInfo.PullData(out var fresh))
                {
                    break;
                }

                if (fresh.Equals(data))
                {
                    continue;
                }

                data = fresh;

                var presence = new RichPresence
                {
                    State      = data.Author,
                    Details    = data.Name,
                    Timestamps = Timestamps.FromTimeSpan(data.TimeLeft),
                    Assets     = new Assets
                    {
                        LargeImageText = data.Album,
                        LargeImageKey  = "download"
                    }
                };

                client.SetPresence(presence);

                Thread.Sleep(1000);
            }

            Api.UnInitialize();
        }
Example #3
0
 public bool Equals(iTunesInfo other)
 {
     return(Name == other.Name && Author == other.Author && Album == other.Album &&
            TimeLeft.Subtract(other.TimeLeft).Seconds < 20);
 }