Пример #1
0
        private void btn_scrobble_Click(object sender, EventArgs e)
        {
            if (ConfirmScrobbleList != null && ConfirmScrobbleList.Count > 0)
            {
                Audioscrobbler audioscrobbler = new Audioscrobbler();



                /* Begin changes by mope-life*/

                //Authenticate with last.fm if we don't already have a session key
                if (ConfigurationManager.AppSettings["LastFM_SessionKey"] == "")
                {
                    if (!audioscrobbler.GetToken())
                    {
                        Close();
                        return;
                    }
                    Login login = new Login();

                    login.webBrowser1.Navigate(audioscrobbler.GetAuthUrl());
                    login.ShowDialog();

                    if (!audioscrobbler.GetSession())
                    {
                        Close();
                        return;
                    }
                }


                /* End changes by mope-life */



                //Sort the too scrobble songs
                ConfirmScrobbleList = ConfirmScrobbleList.OrderBy(x => x.DateSubmitted).ToList();

                //Scrobble the songs to Last.fm
                foreach (EntryObject track in ConfirmScrobbleList)
                {
                    if (track.LengthSeconds < 30)
                    {
                        lbl_ScrobbleStatus.Text = "Not scrobbling: " + track.Artist + " - " + track.Name + " track is too short.";
                        lbl_ScrobbleStatus.Refresh();
                    }
                    else
                    {
                        lbl_ScrobbleStatus.Text = "Now scrobbling: " + track.Artist + " - " + track.Name;
                        lbl_ScrobbleStatus.Refresh();
                    }

                    int ScrobbleCount = track.PlayCount - track.PlayCountHis;
                    for (int i = 1; i <= ScrobbleCount; i++)
                    {
                        Console.WriteLine("Scrobbling: " + track.Artist + " - " + track.Name);
                        track.DateSubmitted = track.DateSubmitted.AddSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["Scrobble_BetweenTime"]));

                        if (!audioscrobbler.SubmitTrack(track.Artist, track.Name, track.Album, track.LengthSeconds, track.DateSubmitted))
                        {
                            Close();
                            return;
                        }
                    }

                    Console.WriteLine("Track added to scrobble history.");
                    PlayedTrackDAO PlayedTrackDAO = new PlayedTrackDAO();
                    PlayedTrackDAO.SaveObject(track.PersistentId, track.DateSubmitted, track.PlayCount);
                }

                Configuration Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                Configuration.AppSettings.Settings["Scrobble_LastDate"].Value = DateTime.Now.ToString();
                Configuration.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");

                _Frontend.InitializeTabs();
                _Frontend.ToolBarStatusText = "Ready, completed scrobbling to Last.fm.";
                Console.WriteLine("Ready, completed scrobbling to Last.fm.");
                Close();
            }
        }
Пример #2
0
        private void btn_scrobble_Click(object sender, EventArgs e)
        {
            if (ConfigurationManager.AppSettings["LastFM_Username"] == "" || ConfigurationManager.AppSettings["LastFM_Password"] == "")
            {
                MessageBox.Show("Please set your username and password in the settings menu.", "ZenseMe");
                Close();
                return;
            }

            if (ConfirmScrobbleList != null && ConfirmScrobbleList.Count > 0)
            {
                //Authenticate with Last.fm
                Audioscrobbler Audioscrobbler = new Audioscrobbler();
                if (!Audioscrobbler.ConnectLastfm())
                {
                    Close();
                    return;
                }

                //Sort the too scrobble songs
                ConfirmScrobbleList = ConfirmScrobbleList.OrderBy(x => x.DateSubmitted).ToList();

                //Scrobble the songs to Last.fm
                foreach (EntryObject track in ConfirmScrobbleList)
                {
                    if (track.LengthSeconds < 30)
                    {
                        lbl_ScrobbleStatus.Text = "Not scrobbling: " + track.Artist + " - " + track.Name + " track is too short.";
                        lbl_ScrobbleStatus.Refresh();
                    }
                    else
                    {
                        lbl_ScrobbleStatus.Text = "Now scrobbling: " + track.Artist + " - " + track.Name;
                        lbl_ScrobbleStatus.Refresh();
                    }

                    int ScrobbleCount = track.PlayCount - track.PlayCountHis;
                    for (int i = 1; i <= ScrobbleCount; i++)
                    {
                        Console.WriteLine("Scrobbling: " + track.Artist + " - " + track.Name);
                        track.DateSubmitted = track.DateSubmitted.AddSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["Scrobble_BetweenTime"]));

                        if (!Audioscrobbler.SubmitTrack(track.Artist, track.Name, track.Album, track.LengthSeconds, track.DateSubmitted))
                        {
                            Close();
                            return;
                        }
                    }

                    Console.WriteLine("Track added to scrobble history.");
                    PlayedTrackDAO PlayedTrackDAO = new PlayedTrackDAO();
                    PlayedTrackDAO.SaveObject(track.PersistentId, track.DateSubmitted, track.PlayCount);
                }

                Configuration Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                Configuration.AppSettings.Settings["Scrobble_LastDate"].Value = DateTime.Now.ToString();
                Configuration.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");

                _Frontend.InitializeTabs();
                _Frontend.ToolBarStatusText = "Ready, completed scrobbling to Last.fm.";
                Console.WriteLine("Ready, completed scrobbling to Last.fm.");
                Close();
            }
        }