示例#1
0
        void UnignoreCertSongs()
        {
            try
            {
                ProgressDisableUI("Unignoring selected ignored songs...");
                List <TblSong> DBSongQueryList = DBCon.TblSong.ToList();
                foreach (object SelItem in lb_IgnoreListBox.SelectedItems)
                {
                    IgnoredSongsList SelectedItem = (IgnoredSongsList)SelItem;
                    TblSong          DBSong       = DBSongQueryList.Where(x => x.Id == SelectedItem.Id).FirstOrDefault();
                    DBSong.Ignored = 0;
                }
                DBCon.SubmitChanges();

                if (!(bool)vApplicationSettings["LastfmReduceConfirmation"])
                {
                    Dispatcher.BeginInvoke(delegate { MessageBox.Show("Your selected ignored songs have successfully been unignored, now it's time to scrobble some songs!", "ScrobbleMe", MessageBoxButton.OK); });
                }
            }
            catch (Exception ex)
            { Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to unignore your selected played songs.\n\nException Message: " + ex.Message, "ScrobbleMe", MessageBoxButton.OK); }); }

            Thread ThreadLoadScrobble = new Thread(() => LoadScrobbleIgnore());

            ThreadLoadScrobble.Start();
            return;
        }
示例#2
0
        //Update and add Scrobble songs
        void LoadScrobbleIgnore()
        {
            try
            {
                ProgressDisableUI("Refreshing played songs...");
                List <TblSong> DBSongQueryList = DBCon.TblSong.ToList();
                foreach (Song DevSong in vMediaLibrary.Songs.ToList().Where(x => x.PlayCount > 0).ToList())
                {
                    //Check for new or existing songs
                    TblSong DBSongItem = DBSongQueryList.Where(x => x.Artist == DevSong.Artist.Name & x.Album == DevSong.Album.Name & x.Title == DevSong.Name & x.Track == DevSong.TrackNumber & x.Genre == DevSong.Genre.Name & x.Duration == DevSong.Duration.ToString()).FirstOrDefault();
                    if (DBSongItem == null)
                    {
                        if (!String.IsNullOrWhiteSpace(DevSong.Artist.Name) && !String.IsNullOrWhiteSpace(DevSong.Album.Name) && !String.IsNullOrWhiteSpace(DevSong.Name))
                        {
                            TblSong AddSong = new TblSong();
                            AddSong.Artist   = DevSong.Artist.Name;
                            AddSong.Album    = DevSong.Album.Name;
                            AddSong.Title    = DevSong.Name;
                            AddSong.Track    = DevSong.TrackNumber;
                            AddSong.Genre    = DevSong.Genre.Name;
                            AddSong.Duration = DevSong.Duration.ToString();
                            AddSong.Plays    = DevSong.PlayCount;
                            DBCon.TblSong.InsertOnSubmit(AddSong);
                        }
                    }
                    else
                    {
                        //Update the songs playcount
                        if (DBSongItem.Plays != DevSong.PlayCount)
                        {
                            DBSongItem.Plays = DevSong.PlayCount;
                        }

                        //Scrobble count above play check/fix
                        if (DBSongItem.Scrobbles > DevSong.PlayCount)
                        {
                            DBSongItem.Scrobbles = DevSong.PlayCount;
                            DBSongItem.Plays     = DevSong.PlayCount;
                        }
                    }
                }
                DBCon.SubmitChanges();
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to update all your played songs.\n\nException Message: " + ex.Message, "ScrobbleMe", MessageBoxButton.OK); });
                ProgressEnableUI();
                return;
            }

            //Read and list Scrobble songs
            try
            {
                ProgressDisableUI("Loading played songs...");
                Dispatcher.BeginInvoke(delegate { lb_ScrobbleListBox.Items.Clear(); });

                List <TblSong> DBSongQueryList = DBCon.TblSong.ToList().Where(x => x.Plays > 0 & x.Plays > x.Scrobbles & x.Ignored == 0).OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Track).ToList();
                //Sort songs to scrobble
                if (!(bool)vApplicationSettings["LastfmScrobbleArtistOrder"])
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBSongQueryList = DBSongQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Title).ToList();
                    }
                    else
                    {
                        DBSongQueryList = DBSongQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Track).ToList();
                    }
                }
                else
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBSongQueryList = DBSongQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Title).ToList();
                    }
                    else
                    {
                        DBSongQueryList = DBSongQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Track).ToList();
                    }
                }

                Dispatcher.BeginInvoke(delegate
                {
                    foreach (TblSong DBSong in DBSongQueryList.Take(200))
                    {
                        string TrackNumber = "";
                        if (DBSong.Track != 0)
                        {
                            TrackNumber = "|" + DBSong.Track;
                        }
                        lb_ScrobbleListBox.Items.Add(new ScrobbleSongsList()
                        {
                            Id = DBSong.Id, Stats = TrackNumber + "|P" + DBSong.Plays + "/S" + DBSong.Scrobbles + "|", Artist = DBSong.Artist, Title = DBSong.Title, Album = DBSong.Album
                        });
                    }

                    ShellTile ShellTile = ShellTile.ActiveTiles.FirstOrDefault();
                    if (DBSongQueryList.Count == 0)
                    {
                        txt_ScrobbleStats.Text        = "Total songs found on this phone: " + vMediaLibrary.Songs.Count.ToString() + "\nLatest scrobble: " + vApplicationSettings["LastfmScrobbled"].ToString() + "\n\nThere were no songs found to scrobble, now is a great time to play some new songs to scrobble.\n\nIf you are using Windows Phone 8 you can use the 'Xbox Music' player to play songs to scrobble.\n\nWhen you are using Windows Mobile 10 'Groove Music' is sadly enough not supported so you will have to use a third party music player like 'Find My Music Too' or 'Finsic Music Player‏'";
                        lb_ScrobbleListBox.Visibility = Visibility.Collapsed;

                        if (ShellTile != null)
                        {
                            vStandardTileData.Title = "";
                            ShellTile.Update(vStandardTileData);
                        }
                    }
                    else
                    {
                        txt_ScrobbleStats.Text = "Total songs found on this phone: " + vMediaLibrary.Songs.Count.ToString() + "\nPlayed songs to scrobble to Last.fm: " + DBSongQueryList.Count.ToString() + "\nLatest scrobble: " + vApplicationSettings["LastfmScrobbled"].ToString();
                        //if (lb_ScrobbleListBox.Items.Count > 0) { lb_ScrobbleListBox.ScrollIntoView(lb_ScrobbleListBox.Items[0]); }
                        lb_ScrobbleListBox.Visibility = Visibility.Visible;

                        if ((bool)vApplicationSettings["ScrobbleTileCount"] && ShellTile != null)
                        {
                            vStandardTileData.Title = DBSongQueryList.Count.ToString();
                            ShellTile.Update(vStandardTileData);
                        }
                    }
                });
            }
            catch (Exception ex)
            { Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to refresh all your played songs.\n\nException Message: " + ex.Message, "ScrobbleMe", MessageBoxButton.OK); }); }

            //Read and list Ignored songs
            try
            {
                ProgressDisableUI("Loading ignored songs...");
                Dispatcher.BeginInvoke(delegate { lb_IgnoreListBox.Items.Clear(); });

                List <TblSong> DBIgnoreQueryList = DBCon.TblSong.ToList().Where(x => x.Ignored == 1).OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Track).ToList();
                //Sort songs to ignore
                if (!(bool)vApplicationSettings["LastfmScrobbleArtistOrder"])
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBIgnoreQueryList = DBIgnoreQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Title).ToList();
                    }
                    else
                    {
                        DBIgnoreQueryList = DBIgnoreQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Track).ToList();
                    }
                }
                else
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBIgnoreQueryList = DBIgnoreQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Title).ToList();
                    }
                    else
                    {
                        DBIgnoreQueryList = DBIgnoreQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Track).ToList();
                    }
                }

                Dispatcher.BeginInvoke(delegate
                {
                    foreach (TblSong DBSong in DBIgnoreQueryList)
                    {
                        string TrackNumber = "";
                        if (DBSong.Track != 0)
                        {
                            TrackNumber = "|" + DBSong.Track;
                        }
                        lb_IgnoreListBox.Items.Add(new IgnoredSongsList()
                        {
                            Id = DBSong.Id, Stats = TrackNumber + "|P" + DBSong.Plays + "/S" + DBSong.Scrobbles + "|", Artist = DBSong.Artist, Title = DBSong.Title, Album = DBSong.Album
                        });
                    }

                    if (DBIgnoreQueryList.Count == 0)
                    {
                        txt_IgnoreStats.Text        = "There were no ignored songs found, if you don't want some songs to scrobble you can ignore them on the scrobble tab by selecting songs and click on the 'Ignore' button.";
                        lb_IgnoreListBox.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        txt_IgnoreStats.Text = "Total ignored songs found on this phone: " + DBIgnoreQueryList.Count.ToString() + "\nTap on the songs that you want to unignore:";
                        //if (lb_IgnoreListBox.Items.Count > 0) { lb_IgnoreListBox.ScrollIntoView(lb_IgnoreListBox.Items[0]); }
                        lb_IgnoreListBox.Visibility = Visibility.Visible;
                    }
                });
            }
            catch (Exception ex)
            { Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to refresh all your ignored songs.\n\nException Message: " + ex.Message, "ScrobbleMe", MessageBoxButton.OK); }); }

            ProgressEnableUI();
            Dispatcher.BeginInvoke(delegate { HideLoadSplashScreen(); });
            return;
        }
示例#3
0
        async void ScrobbleSongs()
        {
            try
            {
                //Check for songs to scrobble
                ProgressDisableUI("Checking scrobble songs...");
                List <TblSong> DBSongQueryList = DBCon.TblSong.ToList().Where(x => x.Plays > 0 & x.Plays > x.Scrobbles & x.Ignored == 0).ToList();

                //Check if there are songs to scrobble
                if (DBSongQueryList.Count == 0)
                {
                    if (!(bool)vApplicationSettings["LastfmReduceConfirmation"])
                    {
                        Dispatcher.BeginInvoke(delegate { MessageBox.Show("There were no songs found to scrobble, now it's time to play some new songs!", "ScrobbleMe", MessageBoxButton.OK); });
                    }
                    ProgressEnableUI();
                    return;
                }

                //Sort songs to scrobble
                if (!(bool)vApplicationSettings["LastfmScrobbleArtistOrder"])
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBSongQueryList = DBSongQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Title).ToList();
                    }
                    else
                    {
                        DBSongQueryList = DBSongQueryList.OrderBy(x => x.Artist).ThenBy(x => x.Album).ThenBy(x => x.Track).ToList();
                    }
                }
                else
                {
                    if ((bool)vApplicationSettings["LastfmScrobbleSongOrder"])
                    {
                        DBSongQueryList = DBSongQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Title).ToList();
                    }
                    else
                    {
                        DBSongQueryList = DBSongQueryList.OrderByDescending(x => x.Artist).ThenByDescending(x => x.Album).ThenByDescending(x => x.Track).ToList();
                    }
                }

                //Last.fm scrobble song
                int SubmitCountTotal = 0;
                int SubmitCountBatch = 0;
                int SubmitCountMax   = 0;

                string   SubmitResult   = "";
                string   SubmitErrorMsg = "";
                DateTime SubmitUnixTime = DateTime.UtcNow.AddMinutes(-(int)vApplicationSettings["LastfmDelayTimeInt"]);

                //Submit to Last.fm #1
                string LastFMApiKey    = "a62159e276986acf81f6990148b06ae3"; //Yes, I know I didn't remove the api key.
                string LastFMApiSecret = "fa570ce8eeb81a3e1685b0e8a27d6517"; //Yes, I know I didn't remove the api key.
                string LastFMMethod    = "track.scrobble";

                List <int> ScrobbleBatchListId = new List <int>();
                Dictionary <string, string> ScrobbleBatchList = new Dictionary <string, string>();
                ScrobbleBatchList.Add("api_key", LastFMApiKey);
                ScrobbleBatchList.Add("method", LastFMMethod);
                ScrobbleBatchList.Add("sk", vApplicationSettings["LastfmSessionKey"].ToString());

                //Calculate maximum songs
                foreach (TblSong MaxDBSong in DBSongQueryList)
                {
                    int ScrobbleCount = MaxDBSong.Plays - MaxDBSong.Scrobbles;
                    if ((bool)vApplicationSettings["SkipMultiplePlays"])
                    {
                        ScrobbleCount = 1;
                    }
                    for (int i = 1; i <= ScrobbleCount; i++)
                    {
                        SubmitCountMax++;
                    }
                }

                //Batch scrobble songs
                foreach (TblSong DBSong in DBSongQueryList)
                {
                    int ScrobbleCount = DBSong.Plays - DBSong.Scrobbles;
                    if ((bool)vApplicationSettings["SkipMultiplePlays"])
                    {
                        ScrobbleCount = 1;
                    }
                    for (int i = 1; i <= ScrobbleCount; i++)
                    {
                        //Calculate scrobble time
                        TimeSpan SongSeconds = new TimeSpan(Convert.ToDateTime(DBSong.Duration).Hour, Convert.ToDateTime(DBSong.Duration).Minute, Convert.ToDateTime(DBSong.Duration).Second);
                        SubmitUnixTime = SubmitUnixTime.AddSeconds(-SongSeconds.TotalSeconds);
                        long SubmitUnixTimeTicks = (SubmitUnixTime.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000000;

                        ScrobbleBatchListId.Add(DBSong.Id);
                        ScrobbleBatchList.Add("album[" + SubmitCountBatch + "]", DBSong.Album);
                        ScrobbleBatchList.Add("artist[" + SubmitCountBatch + "]", DBSong.Artist);
                        ScrobbleBatchList.Add("duration[" + SubmitCountBatch + "]", Convert.ToString(SongSeconds.TotalSeconds));
                        ScrobbleBatchList.Add("timestamp[" + SubmitCountBatch + "]", Convert.ToString(SubmitUnixTimeTicks));
                        ScrobbleBatchList.Add("track[" + SubmitCountBatch + "]", DBSong.Title);
                        ScrobbleBatchList.Add("trackNumber[" + SubmitCountBatch + "]", Convert.ToString(DBSong.Track));

                        SubmitCountBatch++;
                        SubmitCountTotal++;

                        if (SubmitCountBatch == 15 || SubmitCountTotal == SubmitCountMax)
                        {
                            ProgressDisableUI("Scrobbling songs: " + SubmitCountTotal + "/" + SubmitCountMax);

                            List <string> ScrobbleBatchListSorted = ScrobbleBatchList.Select(x => x.Key).ToList();
                            ScrobbleBatchListSorted.Sort(StringComparer.Ordinal);

                            //Build Signature String
                            StringBuilder sbSig = new StringBuilder();
                            foreach (string Key in ScrobbleBatchListSorted)
                            {
                                sbSig.Append(Key.ToString() + ScrobbleBatchList[Key]);
                            }
                            sbSig.Append(LastFMApiSecret);

                            //Build Post String
                            StringBuilder sbPost = new StringBuilder();
                            foreach (string Key in ScrobbleBatchListSorted)
                            {
                                sbPost.Append("&" + Key.ToString() + "=" + HttpUtility.UrlEncode(ScrobbleBatchList[Key]));
                            }
                            sbPost.Append("&api_sig=" + HttpUtility.UrlEncode(MD5CryptoServiceProvider.GetMd5String(sbSig.ToString())));

                            XDocument ResponseXml = null;
                            using (HttpClient HttpClientSubmit = new HttpClient())
                            {
                                HttpClientSubmit.DefaultRequestHeaders.Add("User-Agent", "ScrobbleMe");
                                HttpClientSubmit.DefaultRequestHeaders.Add("Accept-Charset", "UTF-8");
                                HttpClientSubmit.DefaultRequestHeaders.Add("Cache-Control", "no-cache, no-store");

                                Uri PostUri = new Uri("https://ws.audioscrobbler.com/2.0/");
                                HttpStringContent PostContent = new HttpStringContent(sbPost.ToString(), Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");

                                ResponseXml = XDocument.Parse((await HttpClientSubmit.PostAsync(PostUri, PostContent)).Content.ToString());
                            }

                            //Submit to Last.fm #2
                            if (ResponseXml.Element("lfm").Attribute("status").Value == "ok")
                            {
                                SubmitResult = "ok";

                                //Mark batch songs as scrobbled
                                foreach (int SongID in ScrobbleBatchListId)
                                {
                                    TblSong DBSongID = DBSongQueryList.Where(x => x.Id == SongID).FirstOrDefault();
                                    DBSongID.Scrobbles = DBSongID.Plays;
                                }
                                DBCon.SubmitChanges();

                                if (Convert.ToUInt32(ResponseXml.Element("lfm").Element("scrobbles").Attribute("ignored").Value) > 0)
                                {
                                    SubmitErrorMsg = " But some songs might have been ignored by Last.fm.";
                                }
                            }
                            else if (!String.IsNullOrEmpty(ResponseXml.Element("lfm").Element("error").Value))
                            {
                                Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to scrobble your songs to Last.fm, please check your Last.fm account settings, try to relog into your account or check your internet connection.\n\nError Message: " + ResponseXml.Element("lfm").Element("error").Value, "ScrobbleMe", MessageBoxButton.OK); });
                                SubmitResult = "failed";
                                break;
                            }

                            SubmitCountBatch = 0;
                            ScrobbleBatchListId.Clear();
                            ScrobbleBatchList.Clear();
                            ScrobbleBatchList.Add("api_key", LastFMApiKey);
                            ScrobbleBatchList.Add("method", LastFMMethod);
                            ScrobbleBatchList.Add("sk", vApplicationSettings["LastfmSessionKey"].ToString());
                        }
                    }
                    ;
                    if (SubmitResult == "failed")
                    {
                        break;
                    }
                }

                if (SubmitResult == "ok")
                {
                    //Set last scrobble date
                    vApplicationSettings["LastfmScrobbled"] = DateTime.Now.ToString("d MMMM yyyy", new System.Globalization.CultureInfo("en-US")) + " at " + DateTime.Now.ToShortTimeString();
                    vApplicationSettings.Save();

                    if (!(bool)vApplicationSettings["LastfmReduceConfirmation"])
                    {
                        Dispatcher.BeginInvoke(delegate { MessageBox.Show("All your played songs have successfully been scrobbled to your Last.fm profile." + SubmitErrorMsg, "ScrobbleMe", MessageBoxButton.OK); });
                    }
                }
            }
            catch (Exception ex)
            { Dispatcher.BeginInvoke(delegate { MessageBox.Show("Failed to scrobble your songs to Last.fm, please check your Last.fm account settings, try to relog into your account or check your internet connection.\n\nException Message: " + ex.Message, "ScrobbleMe", MessageBoxButton.OK); }); }

            if ((bool)vApplicationSettings["LoadLastFMData"])
            {
                await LoadLoved();
                await LoadArtists();

                //await LoadLikes();
            }

            await LoadRecent();

            Thread ThreadLoadScrobble = new Thread(() => LoadScrobbleIgnore());

            ThreadLoadScrobble.Start();
            return;
        }