private void NowPlaying(LastfmRequest request)
 {
     try {
         request.BeginSend(OnNowPlayingResponse);
     }
     catch (Exception e) {
         Log.Warning("Audioscrobbler NowPlaying failed",
                     String.Format("Failed to post NowPlaying: {0}", e), false);
     }
 }
        private void TransmitQueue()
        {
            // save here in case we're interrupted before we complete
            // the request.  we save it again when we get an OK back
            // from the server
            queue.Save();

            next_interval = DateTime.MinValue;

            if (!connected)
            {
                return;
            }

            current_scrobble_request = new LastfmRequest("track.scrobble", RequestType.Write, ResponseFormat.Json);
            IList <IQueuedTrack> tracks = queue.GetTracks();

            for (int i = 0; i < tracks.Count; i++)
            {
                IQueuedTrack track = tracks[i];

                string str_track_number = String.Empty;
                if (track.TrackNumber != 0)
                {
                    str_track_number = track.TrackNumber.ToString();
                }

                bool chosen_by_user = (track.TrackAuth.Length == 0);

                current_scrobble_request.AddParameter(String.Format("timestamp[{0}]", i), track.StartTime.ToString());
                current_scrobble_request.AddParameter(String.Format("track[{0}]", i), track.Title);
                current_scrobble_request.AddParameter(String.Format("artist[{0}]", i), track.Artist);
                current_scrobble_request.AddParameter(String.Format("album[{0}]", i), track.Album);
                current_scrobble_request.AddParameter(String.Format("trackNumber[{0}]", i), str_track_number);
                current_scrobble_request.AddParameter(String.Format("duration[{0}]", i), track.Duration.ToString());
                current_scrobble_request.AddParameter(String.Format("mbid[{0}]", i), track.MusicBrainzId);
                current_scrobble_request.AddParameter(String.Format("chosenByUser[{0}]", i), chosen_by_user ? "1" : "0");
            }

            Log.DebugFormat("Last.fm scrobbler sending '{0}'", current_scrobble_request.ToString());

            state = State.Transmitting;
            current_async_result = current_scrobble_request.BeginSend(OnScrobbleResponse, tracks.Count);
            state = State.WaitingForResponse;
            if (!(current_async_result.AsyncWaitHandle.WaitOne(TIME_OUT, false)))
            {
                Log.Warning("Audioscrobbler upload failed", "The request timed out and was aborted", false);
                next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS);
                hard_failures++;
                state = State.Idle;
            }
        }
示例#3
0
        private void TransmitQueue()
        {
            // save here in case we're interrupted before we complete
            // the request.  we save it again when we get an OK back
            // from the server
            queue.Save();

            next_interval = DateTime.MinValue;

            if (!connected)
            {
                return;
            }

            state = State.Transmitting;
            current_scrobble_request = new LastfmRequest("track.scrobble", RequestType.Write, ResponseFormat.Json);

            int trackCount = 0;

            while (true)
            {
                IQueuedTrack track = queue.GetNextTrack();
                if (track == null ||
                    // Last.fm can technically handle up to 50 songs in one request
                    // but let's not use the top limit
                    trackCount == 40)
                {
                    break;
                }

                try {
                    current_scrobble_request.AddParameters(GetTrackParameters(track, trackCount));
                    trackCount++;
                } catch (MaxSizeExceededException) {
                    break;
                }
            }

            Log.DebugFormat("Last.fm scrobbler sending '{0}'", current_scrobble_request.ToString());

            current_async_result = current_scrobble_request.BeginSend(OnScrobbleResponse, trackCount);
            state = State.WaitingForResponse;
            if (!(current_async_result.AsyncWaitHandle.WaitOne(TIME_OUT, false)))
            {
                Log.Warning("Audioscrobbler upload failed", "The request timed out and was aborted", false);
                next_interval = DateTime.Now + new TimeSpan(0, 0, RETRY_SECONDS);
                hard_failures++;
                state = State.Idle;
            }
        }
        private void TransmitQueue()
        {
            // save here in case we're interrupted before we complete
            // the request.  we save it again when we get an OK back
            // from the server
            queue.Save ();

            next_interval = DateTime.MinValue;

            if (!connected) {
                return;
            }

            state = State.Transmitting;
            current_scrobble_request = new LastfmRequest ("track.scrobble", RequestType.Write, ResponseFormat.Json);

            int trackCount = 0;
            while (true) {
                IQueuedTrack track = queue.GetNextTrack ();
                if (track == null ||
                    // Last.fm can technically handle up to 50 songs in one request
                    // but let's not use the top limit
                    trackCount == 40) {
                    break;
                 }

                try {
                    current_scrobble_request.AddParameters (GetTrackParameters (track, trackCount));
                    trackCount++;
                } catch (MaxSizeExceededException) {
                    break;
                }
            }

            Log.DebugFormat ("Last.fm scrobbler sending '{0}'", current_scrobble_request.ToString ());

            current_async_result = current_scrobble_request.BeginSend (OnScrobbleResponse, trackCount);
            state = State.WaitingForResponse;
            if (!(current_async_result.AsyncWaitHandle.WaitOne (TIME_OUT, false))) {
                Log.Warning ("Audioscrobbler upload failed", "The request timed out and was aborted", false);
                next_interval = DateTime.Now + new TimeSpan (0, 0, RETRY_SECONDS);
                hard_failures++;
                state = State.Idle;
            }
        }
 private void NowPlaying(LastfmRequest request)
 {
     try {
         request.BeginSend (OnNowPlayingResponse);
     }
     catch (Exception e) {
         Log.Warning ("Audioscrobbler NowPlaying failed",
             String.Format("Failed to post NowPlaying: {0}", e), false);
     }
 }
        private void TransmitQueue ()
        {
            // save here in case we're interrupted before we complete
            // the request.  we save it again when we get an OK back
            // from the server
            queue.Save ();

            next_interval = DateTime.MinValue;

            if (!connected) {
                return;
            }

            current_scrobble_request = new LastfmRequest ("track.scrobble", RequestType.Write, ResponseFormat.Json);
            IList<IQueuedTrack> tracks = queue.GetTracks ();

            for (int i = 0; i < tracks.Count; i++) {
                IQueuedTrack track = tracks[i];

                string str_track_number = String.Empty;
                if (track.TrackNumber != 0) {
                    str_track_number = track.TrackNumber.ToString();
                }

                bool chosen_by_user = (track.TrackAuth.Length == 0);

                current_scrobble_request.AddParameter (String.Format ("timestamp[{0}]", i), track.StartTime.ToString ());
                current_scrobble_request.AddParameter (String.Format ("track[{0}]", i), track.Title);
                current_scrobble_request.AddParameter (String.Format ("artist[{0}]", i), track.Artist);
                current_scrobble_request.AddParameter (String.Format ("album[{0}]", i), track.Album);
                current_scrobble_request.AddParameter (String.Format ("trackNumber[{0}]", i), str_track_number);
                current_scrobble_request.AddParameter (String.Format ("duration[{0}]", i), track.Duration.ToString ());
                current_scrobble_request.AddParameter (String.Format ("mbid[{0}]", i), track.MusicBrainzId);
                current_scrobble_request.AddParameter (String.Format ("chosenByUser[{0}]", i), chosen_by_user ? "1" : "0");
            }

            Log.DebugFormat ("Last.fm scrobbler sending '{0}'", current_scrobble_request.ToString ());

            state = State.Transmitting;
            current_async_result = current_scrobble_request.BeginSend (OnScrobbleResponse, tracks.Count);
            state = State.WaitingForResponse;
            if (!(current_async_result.AsyncWaitHandle.WaitOne (TIME_OUT, false))) {
                Log.Warning ("Audioscrobbler upload failed", "The request timed out and was aborted", false);
                next_interval = DateTime.Now + new TimeSpan (0, 0, RETRY_SECONDS);
                hard_failures++;
                state = State.Idle;
            }
        }