Ejemplo n.º 1
0
        public void Scrobble(Song[] songs)
        {
            if (!Connected) {
                unsubmitted_songs.AddRange (songs);
            } else if (songs.Length > 0) {
                StringBuilder post_data = new StringBuilder ();

                post_data.Append ("s=" + session);

                int i = 0;
                foreach (Song song in songs) {
                    if (song.Length > 30000) {
                        if (i<MaxSongsPerPost) {
                            post_data.Append ("&a["+i+"]=" + Escape (song.Artist));
                            post_data.Append ("&t["+i+"]=" + Escape (song.Track));
                            post_data.Append ("&i["+i+"]=" + Timestamp (song.StartTime));
                            post_data.Append ("&o["+i+"]=L" + song.TrackAuth);
                            post_data.Append ("&r["+i+"]=");
                            post_data.Append ("&l["+i+"]=" + (int) Math.Round ((double) song.Length / 1000));
                            post_data.Append ("&b["+i+"]=" + Escape (song.Album));
                            post_data.Append ("&n["+i+"]=");
                            post_data.Append ("&m["+i+"]=");
                            i++;
                            } else {
                            break;
                        }
                    }

                }

                FMRequest request = new FMRequest ();
                request.RequestCompleted += new FMRequest.RequestCompletedHandler (OnSubmissionCompleted);
                failed_submitted_songs.Add (request, songs);
                request.DoRequest (submission_url, post_data.ToString ());

                if (i>=MaxSongsPerPost) {
                    Song[] s = new Song[songs.Length-MaxSongsPerPost];
                    songs.CopyTo (s, i);
                    Scrobble (s);
                }
            }
        }