public bool CanSkip(PandoraStation station) { // remove any skip history records older than an hour foreach (Queue<DateTime> currHistory in stationSkipHistory.Values) { while (currHistory.Count > 0 && DateTime.Now - currHistory.Peek() > new TimeSpan(1, 0, 0)) currHistory.Dequeue(); } // remove any daily skip history older than a day while (globalSkipHistory.Count > 0 && DateTime.Now - globalSkipHistory.Peek() > new TimeSpan(24, 0, 0)) globalSkipHistory.Dequeue(); // if the current station has no skip history, add it if (!stationSkipHistory.ContainsKey(station.Id)) stationSkipHistory.Add(station.Id, new Queue<DateTime>()); // if we are allowed to skip, record the current time and finish if (IsGlobalSkipAllowed() && IsStationSkipAllowed(station)) { return true; } // too bad, no skip for you! return false; }
private bool IsStationSkipAllowed(PandoraStation station) { if (AllowedStationsSkipsPerHour == null) return true; if (stationSkipHistory[station.Id].Count < AllowedStationsSkipsPerHour) return true; return false; }
public void Skip(PandoraStation station) { if (!CanSkip(station)) throw new PandoraException("User is not currently allowed to skip tracks."); // log the current time as a skip event stationSkipHistory[station.Id].Enqueue(DateTime.Now); globalSkipHistory.Enqueue(DateTime.Now); }
public PandoraSongFeedback RateSong(PandoraSession session, PandoraStation station, PandoraSong song, PandoraRating rating, WebProxy proxy) { if (session == null || session.User == null) throw new PandoraException("User must be logged in to make this request."); PandoraSongFeedback feedbackObj = (PandoraSongFeedback)ExecuteRequest(new AddFeedbackRequest(session, station.Token, song.Token, rating == PandoraRating.Love), proxy); song.Rating = rating; return feedbackObj; }
public PandoraSongFeedback RateSong(PandoraSession session, PandoraStation station, PandoraSong song, PandoraRating rating) { return RateSong(session, station, song, rating, null); }
/// <summary> /// Retrieves a playlist for the given station. /// </summary> public List<PandoraSong> GetSongs(PandoraSession session, PandoraStation station, WebProxy proxy) { if (session == null || session.User == null) throw new PandoraException("User must be logged in to make this request."); GetPlaylistResponse response = (GetPlaylistResponse)ExecuteRequest(new GetPlaylistRequest(session, station.Token), proxy); return response.Songs; }
/// <summary> /// Retrieves a playlist for the given station. /// </summary> public List<PandoraSong> GetSongs(PandoraSession session, PandoraStation station) { return GetSongs(session, station, null); }