Beispiel #1
0
        private void SetSongInfo(ref SpotifyWindowInfo spotifyWindowInfo)
        {
            var tags = spotifyWindowInfo.WindowTitle.Split(_windowTitleSeparator, 3, StringSplitOptions.None);

            var isPlaying = spotifyWindowInfo.IsPlaying || !spotifyWindowInfo.IsTitledSpotify;
            var isAd      = tags.Length < 2;

            CurrentTrack = new Track
            {
                Ad            = isAd && isPlaying,
                Playing       = isPlaying,
                Artist        = GetTitleTag(tags, 1),
                Title         = GetTitleTag(tags, 2),
                TitleExtended = GetTitleTag(tags, 3),
            };
        }
Beispiel #2
0
        private void SpotifyStatusSpotifyStandingBy_ReturnsExpectingTrack()
        {
            var expectedTrack = new Track
            {
                Artist = "Spotify"
            };
            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = "Spotify",
                IsPlaying   = false
            };

            var status = new SpotifyStatus(spotifyWindowInfo);

            Assert.Equal(expectedTrack, status.CurrentTrack);
            Assert.Equal("Spotify", status.CurrentTrack.ToString());
        }
        internal void SpotifyStatusSpotifyStandingBy_ReturnsExpectingTrack()
        {
            var expectedTrack = new Track
            {
                Artist = Constants.SPOTIFY
            };
            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = Constants.SPOTIFY,
                IsPlaying   = false
            };

            var status = new SpotifyStatus(spotifyWindowInfo);

            Assert.Equal(expectedTrack, status.CurrentTrack);
            Assert.Equal(Constants.SPOTIFY, status.CurrentTrack.ToString());
        }
Beispiel #4
0
        public ISpotifyStatus GetSpotifyStatus()
        {
            var isSpotifyPlaying = _spotifyAudioSession.IsSpotifyCurrentlyPlaying();
            var processTitle     = GetSpotifyTitle();

            if (string.IsNullOrWhiteSpace(processTitle))
            {
                return(null);
            }

            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = processTitle,
                IsPlaying   = isSpotifyPlaying
            };

            return(new SpotifyStatus(spotifyWindowInfo));
        }
Beispiel #5
0
        public async Task <ISpotifyStatus> GetSpotifyStatus()
        {
            var(processTitle, isSpotifyAudioPlaying) = await GetSpotifyTitle();

            var isWindowTitledSpotify = processTitle.IsNullOrSpotifyIdleState();

            if (string.IsNullOrWhiteSpace(processTitle))
            {
                return(null);
            }

            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = processTitle,
                IsPlaying   = isSpotifyAudioPlaying || !isWindowTitledSpotify
            };

            return(new SpotifyStatus(spotifyWindowInfo));
        }
Beispiel #6
0
        public SpotifyStatus(SpotifyWindowInfo spotifyWindowInfo)
        {
            var tags          = GetDashTags(spotifyWindowInfo.WindowTitle, 2);
            var longTitlePart = GetTitleTag(tags, 2);

            var(titleTags, separatorType) = GetTitleTags(longTitlePart ?? "", 2);

            var isPlaying         = spotifyWindowInfo.IsPlaying;
            var isLookingLikeAnAd = tags.Length < 2 || tags.First() == Constants.SPOTIFY;

            CurrentTrack = new Track
            {
                Ad            = spotifyWindowInfo.IsTitledAd || (isLookingLikeAnAd && isPlaying),
                Playing       = isPlaying,
                Artist        = GetTitleTag(tags, 1),
                Title         = GetTitleTag(titleTags, 1),
                TitleExtended = GetTitleTag(titleTags, 2),
                TitleExtendedSeparatorType = separatorType
            };
        }
Beispiel #7
0
        private void SpotifyStatusSpotifyPlayingAdOrUnknown_ReturnsExpectingTrack(string windowTitle)
        {
            var expectedTrack = new Track
            {
                Artist        = windowTitle,
                Title         = null,
                TitleExtended = null,
                Playing       = true,
                Ad            = true
            };
            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = windowTitle,
                IsPlaying   = true
            };

            var status = new SpotifyStatus(spotifyWindowInfo);

            Assert.Equal(expectedTrack, status.CurrentTrack);
            Assert.Equal(expectedTrack.ToString(), status.CurrentTrack.ToString());
        }
Beispiel #8
0
        private void SpotifyStatusTrackPlaying_ReturnsExpectingTrack(string windowTitle, bool isTitleExtended)
        {
            var expectedTrack = new Track
            {
                Artist        = "Artist Name",
                Title         = "Song Title",
                TitleExtended = isTitleExtended ? "Live" : "",
                Playing       = true,
                Ad            = false
            };
            var spotifyWindowInfo = new SpotifyWindowInfo
            {
                WindowTitle = windowTitle,
                IsPlaying   = true
            };

            var status = new SpotifyStatus(spotifyWindowInfo);

            Assert.Equal(expectedTrack, status.CurrentTrack);
            Assert.Equal(windowTitle, status.CurrentTrack.ToString());
        }
Beispiel #9
0
 public SpotifyStatus(SpotifyWindowInfo spotifyWindowInfo)
 {
     _windowTitleSeparator = new[] { " - " };
     SetSongInfo(ref spotifyWindowInfo);
 }