コード例 #1
0
ファイル: Form1.cs プロジェクト: philbird/itunes-startstop.me
        /// <summary>
        /// Parse the iTunes XML and then upload the stats to the user account
        /// 
        /// </summary>
        public void ParseiTunesXML()
        {
            startstop.AccessPoint oAccessPoint = new startstop.AccessPoint();
            // Validate the user

            ValidatedUserInfo = oAccessPoint.LoginUser(APIKey, txbUserName.Text, txbPassword.Text);
            // Check to see if the user is validated
            if (ValidatedUserInfo.Validated) // User details invalid
            {

                // We should really access the iTunes XML file, but for now this will. 

                //iTunes classes
                iTunesAppClass itunes = new iTunesAppClass();
                IITLibraryPlaylist mainLibrary = itunes.LibraryPlaylist;
                IITTrackCollection tracks = mainLibrary.Tracks;
                IITFileOrCDTrack currTrack;

                int _numberOfTracks = tracks.Count;



                startstop.UserStatLog oStat = new startstop.UserStatLog();


                // Total number of tracks (This is done here, because, well, we decrement the number of tracks)
                oStat = new startstop.UserStatLog();
                oStat.Count = _numberOfTracks;
                oStat.DetailedStatGuid = cNumberOfTunesInLibraryStatID;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }

                //  oReturnMessage = oDevAPI.ExactStatUpdateForUserWithDayHistory(APIKey, _UserID, cNumberOfTunesInLibraryStatID, tracks.Count, 0,"");
                AddLine("Updated your startstop.me stats with the number of tracks in your iTunes library");

                // Total number of plays
                int _TotalNumberOfPlays = 0;

                // The highest played track
                int _MostPlayedCount = 0;
                string _MostPlayedTrack = "";

                // Number of unplayed tracks
                int _UnplayedTracks = 0;

                // Total time played
                TimeSpan oTimeTimePlayed = new TimeSpan(0, 0, 0);
                TimeSpan oTimeUnplayed = new TimeSpan(0, 0, 0);


                // Here we can go through all the files and update some more stats
                while (_numberOfTracks != 1)
                {
                    // Iterate throught the tracks. 
                    _numberOfTracks--;
                    currTrack = tracks[_numberOfTracks] as IITFileOrCDTrack;

                    // Check this is a song
                    if (currTrack.KindAsString.Contains("audio"))
                    {

                        _TotalNumberOfPlays += currTrack.PlayedCount;

                        string[] _timeSplit = currTrack.Time.Split(':');
                        TimeSpan _tracktime = new TimeSpan();
                        // Minutes and Seconds
                        if (_timeSplit.Length == 2)
                        {

                            _tracktime = new TimeSpan(0, int.Parse(_timeSplit[0]), int.Parse(_timeSplit[1]));
                        }
                        // Hours Minutes and seconds
                        if (_timeSplit.Length == 3)
                        {
                            _tracktime = new TimeSpan(int.Parse(_timeSplit[0]), int.Parse(_timeSplit[1]), int.Parse(_timeSplit[2]));
                        }


                        if (currTrack.PlayedCount > _MostPlayedCount)
                        {
                            _MostPlayedCount = currTrack.PlayedCount;
                            _MostPlayedTrack = currTrack.Name;
                            oMostPlayedSong.SongTitle = currTrack.Name;
                            oMostPlayedSong.AlbumnTitle = currTrack.Album;
                            oMostPlayedSong.Genre = currTrack.Genre;
                            oMostPlayedSong.Notes = "";
                            oMostPlayedSong.ReportingUserID = ValidatedUserInfo.UserID;
                            // Catch if there is an invalid date. 
                            if (currTrack.Year != 0)
                            {
                                oMostPlayedSong.Year = new DateTime(currTrack.Year, 1, 1, 0, 0, 0);
                            }
                        }

                        if (currTrack.Unplayed)
                        {
                            _UnplayedTracks++;
                            oTimeUnplayed = oTimeUnplayed.Add(_tracktime);
                        }
                        else
                        {
                            // Repeat through these to give us the total time
                            for (int i = 0; i < currTrack.PlayedCount; i++)
                            {
                                oTimeTimePlayed = oTimeTimePlayed.Add(_tracktime);
                            }
                        }
                    } // end track kind check. 
                }

                #region update the stats with startstop
                AddLine("Added total number of plays");



                // we should swap all this rhubarb for a dictionary, it doesn't need to be this complex. That way we can iterate through the dictionary. 
                // Anyway, for now, this will work. 



                // Total number of plays
                oStat = new startstop.UserStatLog();
                oStat.Count = _TotalNumberOfPlays;
                oStat.DetailedStatGuid = cTotalNumberOfPlays;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }

                // Unplayed tracks
                oStat = new startstop.UserStatLog();
                oStat.Count = _UnplayedTracks;
                oStat.DetailedStatGuid = cUnplayedTunes;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }

                // Most played tracks
                oStat = new startstop.UserStatLog();
                oStat.Count = _MostPlayedCount;
                oStat.DetailedStatGuid = cMostPlayesOnaSong;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }

                // Amount of time played
                oStat = new startstop.UserStatLog();
                oStat.Count = 0;
                oStat.Note = oTimeTimePlayed.Days + "d " + oTimeTimePlayed.Hours + "h " + oTimeTimePlayed.Minutes + "m";
                oStat.DetailedStatGuid = cTimePlayed;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }


                // Amount of time played
                oStat = new startstop.UserStatLog();
                oStat.Count = 0;
                oStat.Note = oTimeUnplayed.Days + "d " + oTimeUnplayed.Hours + "h " + oTimeUnplayed.Minutes + "m";
                oStat.DetailedStatGuid = cTimeUnPlayed;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }

                // Amount of time played
                oStat = new startstop.UserStatLog();
                oStat.Count = 0;
                oStat.Note = _MostPlayedTrack;
                oStat.DetailedStatGuid = cMostPlayedSong;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStatMusic(APIKey, oStat, oMostPlayedSong);
                }

                oStat = new startstop.UserStatLog();
                oStat.Count = 0;
                oStat.Note = DateTime.Now.ToString();
                oStat.DetailedStatGuid = cLastUpdate;
                oStat.DetailedStatOverviewGUID = cStatOverview;
                oStat.UserGuid = ValidatedUserInfo.UserGUID;
                if (!DebugMode)
                {
                    oAccessPoint.AddUserStat(APIKey, oStat);
                }


                AddLine("All done folks! Visit www.startstop.me to see your stats");
                #endregion
            }
            else
            {
                AddLine("User cannot be logged in");
                MessageBox.Show("Sorry your login details aren't correct");
            }

        }
コード例 #2
0
 /// <remarks/>
 public void AddUserStatMusicAsync(string APIKey, UserStatLog oUserStat, AudioContent oAudioContent, object userState) {
     if ((this.AddUserStatMusicOperationCompleted == null)) {
         this.AddUserStatMusicOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddUserStatMusicOperationCompleted);
     }
     this.InvokeAsync("AddUserStatMusic", new object[] {
                 APIKey,
                 oUserStat,
                 oAudioContent}, this.AddUserStatMusicOperationCompleted, userState);
 }
コード例 #3
0
 /// <remarks/>
 public void AddUserStatMusicAsync(string APIKey, UserStatLog oUserStat, AudioContent oAudioContent) {
     this.AddUserStatMusicAsync(APIKey, oUserStat, oAudioContent, null);
 }
コード例 #4
0
 public MessageResponse AddUserStatMusic(string APIKey, UserStatLog oUserStat, AudioContent oAudioContent) {
     object[] results = this.Invoke("AddUserStatMusic", new object[] {
                 APIKey,
                 oUserStat,
                 oAudioContent});
     return ((MessageResponse)(results[0]));
 }
コード例 #5
0
 /// <remarks/>
 public void AddUserStatAsync(string APIKey, UserStatLog oUserStat) {
     this.AddUserStatAsync(APIKey, oUserStat, null);
 }
コード例 #6
0
 public MessageResponse AddUserStat(string APIKey, UserStatLog oUserStat) {
     object[] results = this.Invoke("AddUserStat", new object[] {
                 APIKey,
                 oUserStat});
     return ((MessageResponse)(results[0]));
 }