Пример #1
0
        public void Execute(IJobExecutionContext context)
        {
            SpotifyModel sm = new SpotifyModel();
            _auth = new ImplicitGrantAuth
            {
                RedirectUri = "http://localhost:8000",
                ClientId = "26d287105e31491889f3cd293d85bfea",
                Scope =
                    Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead |
                    Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate,
                State = "XSS"
            };
            _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;

            _auth.StartHttpServer(8000);
            _auth.DoAuth();

            _spotifyLocal = new SpotifyLocalAPI();

            if (!SpotifyLocalAPI.IsSpotifyRunning())
            {
                return;
            }
            if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning())
            {
                return;
            }

            bool successful = _spotifyLocal.Connect();
            if (successful)
            {
                UpdateInfos();
                SpotifyModel spotifyModel = new SpotifyModel();
                var dictDetails = GetDictionaryDetails(_currentTrack.TrackResource.Name).Keys.ToList();
                if (Winner)
                {
                    dictDetails.Sort();
                    var winner = dictDetails[0];
                    var temp = "";
                    if (_currentTrack.TrackType != "ad")
                    {
                        temp = _currentTrack.TrackResource.Name + " - " + _currentTrack.ArtistResource.Name;
                    }
                    while (!temp.Equals(winner))
                    {
                        _spotifyLocal.Skip();
                        UpdateInfos();
                        temp = _currentTrack.TrackResource.Name + " - " + _currentTrack.ArtistResource.Name;
                        Thread.Sleep(100);
                    }
                    Winner = false;
                    spotifyModel.Truncate();
                }
            }
        }
Пример #2
0
 public JsonResult VoteSkip(string SongRecommendation, string SongThatWasPlaying)
 {
     _spotifyLocal = new SpotifyLocalAPI();
     bool successful = _spotifyLocal.Connect();
     string ip = Request.UserHostAddress;
     SpotifyModel spotifyModel = new SpotifyModel();
     if (successful && spotifyModel.IsValidVote(ip))
     {
         spotifyModel.CreateVoteEntry(SongRecommendation, DateTime.Now, SongThatWasPlaying, ip);
     }
     return Json(true, JsonRequestBehavior.AllowGet);
 }
Пример #3
0
        public SpotifyModel GetSpotifyModel()
        {
            _auth = new ImplicitGrantAuth
            {
                RedirectUri = "http://localhost:8000",
                ClientId = "26d287105e31491889f3cd293d85bfea",
                Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibrarayRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate,
                State = "XSS"
            };
            _auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;

            _auth.StartHttpServer(8000);
            _auth.DoAuth();

            SpotifyModel sm = new SpotifyModel();
            _spotifyLocal = new SpotifyLocalAPI();

            if (!SpotifyLocalAPI.IsSpotifyRunning())
            {
                return sm;
            }
            if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning())
            {
                return sm;
            }

            bool successful = _spotifyLocal.Connect();
            if (successful)
            {
                UpdateInfos();
                _spotifyLocal.ListenForEvents = true;
                sm.IsPlaying = true;
                try
                {
                    sm.SongTitle = _currentTrack.TrackResource.Name;
                    sm.VotedItemsDictionary = GetDictionaryDetails(sm.SongTitle);
                    sm.SongArtist = _currentTrack.ArtistResource.Name;

                    Bitmap derp = new Bitmap(_currentTrack.GetAlbumArt(AlbumArtSize.Size320));
                    Byte[] imgFile;
                    var stream = new MemoryStream();
                    derp.Save(stream, ImageFormat.Png);
                    imgFile = stream.ToArray();
                    sm.SongAlbumArt = _currentTrack.GetAlbumArtUrl(AlbumArtSize.Size320);
                    sm.IsPlaying = true;
                    stream.Close();
                    sm.Tracks = GetPlaylists();
                    int index = 0;
                    foreach (var track in sm.Tracks)
                    {
                        if (track.title.Equals(_currentTrack.TrackResource.Name))
                        {
                            break;
                        }
                        index++;
                    }
                    if (index == 0)
                        index++;
                    sm.PreviousSongAlbumArt = sm.Tracks[index - 1].albumArt;
                    sm.PreviousSongTitle = sm.Tracks[index - 1].title;
                    sm.PreviousSongArtist = sm.Tracks[index - 1].artist;
                    if (index + 1 >= sm.Tracks.Count)
                        index = 0;
                    else
                        index++;
                    sm.NextSongAlbumArt = sm.Tracks[index].albumArt;
                    sm.NextSongTitle = sm.Tracks[index].title;
                    sm.NextSongArtist = sm.Tracks[index].artist;

                    _auth = null;
                    _spotifyLocal = null;
                    _spotify = null;
                }
                catch (Exception e)
                {
                }
            }

            if (Winner)
            {
                sm.Truncate();
                Winner = false;
            }

            string ip = Request.UserHostAddress;
            sm.IsValidIP = sm.IsValidVote(ip);
            return sm;
        }
Пример #4
0
        public Dictionary<string, int> GetDictionaryDetails(string SongTitle)
        {
            SpotifyModel spotifyModel = new SpotifyModel();
            List<StoredSpotifyData> votes = spotifyModel.GetVotes();

            HashSet<string> _items = new HashSet<string>();
            foreach (var vote in votes)
            {
                _items.Add(vote.SongRecommendation);
            }
            Dictionary<string, int> uniqueCountOfVotes = new Dictionary<string, int>();
            foreach (var _item in _items)
            {
                var count = votes.Count(item => item.SongRecommendation == _item);
                uniqueCountOfVotes.Add(_item, count);
            }
            if (votes.Count > 0 && (DateTime.Now.Millisecond - votes[0].Time.Millisecond > 600000 || !votes[0].SongThatWasPlaying.Equals(SongTitle)))
            {
                Winner = true;
            }
            return uniqueCountOfVotes;
        }