public static Dictionary <int, int> GetPresentArtists(LastfmData <UserTopArtist> aData) { Dictionary <string, int> artistMatch = new Dictionary <string, int> (); Dictionary <int, int> artistIdsAndRank = new Dictionary <int, int> (); List <string> mbids = new List <string> (); foreach (UserTopArtist cArtist in aData) { string tmp = Hyena.StringUtil.SearchKey(cArtist.Name); if (!artistMatch.ContainsKey(tmp)) { artistMatch.Add(tmp, cArtist.Rank); mbids.Add(cArtist.MbId); } } using (var reader = ServiceManager.DbConnection.Query(ARTIST_QUERY, artistMatch.Keys.ToArray(), mbids.ToArray())) { while (reader.Read()) { int cId = (int)(long)reader[0]; string cName = reader[1] as string; if (artistMatch.ContainsKey(cName)) { artistIdsAndRank.Add(cId, artistMatch[cName]); } } } return(artistIdsAndRank); }
public void SetList(LastfmData <RecentTrack> tracks) { tile_view.ClearWidgets(); foreach (RecentTrack track in tracks) { MenuTile tile = new MenuTile(); widget_track_map [tile] = track; tile.PrimaryText = track.Name; tile.SecondaryText = track.Artist; tile.ButtonPressEvent += OnTileActivated; // Unfortunately the recently loved list doesn't include what album the song is on if (!String.IsNullOrEmpty(track.Album)) { AlbumInfo album = new AlbumInfo(track.Album); album.ArtistName = track.Artist; Gdk.Pixbuf pb = artwork_manager == null ? null : artwork_manager.LookupScalePixbuf(album.ArtworkId, 40); if (pb != null) { tile.Pixbuf = pb; } } tile_view.AddNumberedWidget(tile); } tile_view.ShowAll(); }
// TODO generalize this public void SetList(LastfmData <UserTopArtist> artists) { tile_view.ClearWidgets(); foreach (UserTopArtist artist in artists) { MenuTile tile = new MenuTile(); tile.PrimaryText = artist.Name; tile.SecondaryText = String.Format(Catalog.GetString("{0} plays"), artist.PlayCount); tile_view.AddNumberedWidget(tile); } tile_view.ShowAll(); }
/// <summary> /// Query Lastfm for UserTopArtists /// </summary> /// <remarks>Executed via Kernel Scheduler</remarks> public static void QueryLastfm() { Account account = LastfmCore.Account; if (string.IsNullOrEmpty(account.UserName) || !ServiceManager.Get <Network>().Connected) { return; } LastfmUserData userData = new LastfmUserData(account.UserName); LastfmData <UserTopArtist> topArtists = userData.GetTopArtists(TopType.Overall); Log.Debug("RandomByLastfmUserTopArtists: Searching for present artists"); Dictionary <int, int> artists = GetPresentArtists(topArtists); Log.Debug(String.Format("RandomByLastfmUserTopArtists: Found {0} of {1} Artists", artists.Count, topArtists.Count)); foreach (int cArtistId in artists.Keys) { weightedRandom.Add(cArtistId, artists[cArtistId]); } }
public static void Main(string [] args) { DataCore.CachePath = "test_lastfm_cache"; DataCore.UserAgent = "Lastfm.dll test"; string username = "******"; LastfmUserData user = new LastfmUserData(username); ProfileEntry prof = user.Profile; //Console.WriteLine ("data url: {0}", prof.DataUrl); Console.WriteLine("profile url: {0}", user.Profile.Url); Console.WriteLine("real name: {0}", user.Profile.RealName); Console.WriteLine("play count: {0}", prof.PlayCount); Console.WriteLine("gender: {0}", prof.Gender); Console.WriteLine("age: {0}", prof.Age); Console.WriteLine("country: {0}", prof.Country); Console.WriteLine("registered: {0}", prof.Registered); Console.WriteLine("profile url: {0}", user.Profile.Url); LastfmData <UserTopArtist> top_artists = user.GetTopArtists(TopType.Overall); Console.WriteLine("\nTop Artists ({0})", top_artists.Count); foreach (UserTopArtist artist in top_artists) { Console.WriteLine("Artist: {0}\nPlays: {1}", artist.Name, artist.PlayCount); } foreach (TopTag tag in user.TopTags) { Console.WriteLine("top tag: {0}", tag.Name); } user.TopTags.Refresh(); System.IO.Directory.Delete("test_lastfm_cache", true); }
private void UpdateForArtist(string artist_name, LastfmData <SimilarArtist> similar_artists, LastfmData <ArtistTopAlbum> top_albums, LastfmData <ArtistTopTrack> top_tracks) { Banshee.Base.ThreadAssist.ProxyToMain(delegate { album_box.Title = String.Format(album_title_format, artist); track_box.Title = String.Format(track_title_format, artist); similar_artists_view.ClearWidgets(); ClearBox(album_list); ClearBox(track_list); // Similar Artists for (int i = 0; i < Math.Min(20, similar_artists.Count); i++) { SimilarArtistTile tile = new SimilarArtistTile(similar_artists[i]); tile.ShowAll(); similar_artists_view.AddWidget(tile); } if (similar_artists.Count > 0) { no_artists_pane.Hide(); similar_artists_view_sw.ShowAll(); } else { similar_artists_view_sw.Hide(); no_artists_pane.ShowAll(); } for (int i = 0; i < Math.Min(5, top_albums.Count); i++) { ArtistTopAlbum album = top_albums[i]; Button album_button = new Button(); album_button.Relief = ReliefStyle.None; Label label = new Label(); label.ModifyFg(StateType.Normal, Style.Text(StateType.Normal)); label.Ellipsize = Pango.EllipsizeMode.End; label.Xalign = 0; label.Markup = String.Format("{0}. {1}", i + 1, GLib.Markup.EscapeText(album.Name)); album_button.Add(label); album_button.Clicked += delegate { Banshee.Web.Browser.Open(album.Url); }; album_list.PackStart(album_button, false, true, 0); } album_box.ShowAll(); for (int i = 0; i < Math.Min(5, top_tracks.Count); i++) { ArtistTopTrack track = top_tracks[i]; Button track_button = new Button(); track_button.Relief = ReliefStyle.None; HBox box = new HBox(); Label label = new Label(); label.ModifyFg(StateType.Normal, Style.Text(StateType.Normal)); label.Ellipsize = Pango.EllipsizeMode.End; label.Xalign = 0; label.Markup = String.Format("{0}. {1}", i + 1, GLib.Markup.EscapeText(track.Name)); /*if(node.SelectSingleNode("track_id") != null) { * box.PackEnd(new Image(now_playing_arrow), false, false, 0); * track_button.Clicked += delegate { * //PlayerEngineCore.OpenPlay(Globals.Library.GetTrack( * //Convert.ToInt32(node.SelectSingleNode("track_id").InnerText))); * }; * } else {*/ track_button.Clicked += delegate { Banshee.Web.Browser.Open(track.Url); }; //} box.PackStart(label, true, true, 0); track_button.Add(box); track_list.PackStart(track_button, false, true, 0); } track_box.ShowAll(); ready = true; refreshing = false; context_page.SetState(Banshee.ContextPane.ContextState.Loaded); }); }
public void SetList (LastfmData<RecentTrack> tracks) { tile_view.ClearWidgets (); foreach (RecentTrack track in tracks) { MenuTile tile = new MenuTile (); widget_track_map [tile] = track; tile.PrimaryText = track.Name; tile.SecondaryText = track.Artist; tile.ButtonPressEvent += OnTileActivated; // Unfortunately the recently loved list doesn't include what album the song is on if (!String.IsNullOrEmpty (track.Album)) { AlbumInfo album = new AlbumInfo (track.Album); album.ArtistName = track.Artist; Gdk.Pixbuf pb = artwork_manager == null ? null : artwork_manager.LookupScalePixbuf (album.ArtworkId, 40); if (pb != null) { tile.Pixbuf = pb; } } tile_view.AddNumberedWidget (tile); } tile_view.ShowAll (); }
// TODO generalize this public void SetList (LastfmData<UserTopArtist> artists) { tile_view.ClearWidgets (); foreach (UserTopArtist artist in artists) { MenuTile tile = new MenuTile (); tile.PrimaryText = artist.Name; tile.SecondaryText = String.Format (Catalog.GetString ("{0} plays"), artist.PlayCount); tile_view.AddNumberedWidget (tile); } tile_view.ShowAll (); }
private void UpdateForArtist(string artist_name, LastfmData<SimilarArtist> similar_artists, LastfmData<ArtistTopAlbum> top_albums, LastfmData<ArtistTopTrack> top_tracks) { ThreadAssist.ProxyToMain (delegate { album_box.Title = String.Format (album_title_format, artist); track_box.Title = String.Format (track_title_format, artist); similar_artists_view.ClearWidgets (); ClearBox (album_list); ClearBox (track_list); // Similar Artists var artists = similar_artists.Take (20); if (artists.Count () > 0) { int artist_name_max_len = 2 * (int) artists.Select (a => a.Name.Length).Average (); foreach (var similar_artist in artists) { SimilarArtistTile tile = new SimilarArtistTile (similar_artist); tile.PrimaryLabel.WidthChars = artist_name_max_len; tile.PrimaryLabel.Ellipsize = Pango.EllipsizeMode.End; tile.ShowAll (); similar_artists_view.AddWidget (tile); } no_artists_pane.Hide (); similar_artists_view_sw.ShowAll (); } else { similar_artists_view_sw.Hide (); no_artists_pane.ShowAll (); } for (int i = 0; i < Math.Min (5, top_albums.Count); i++) { ArtistTopAlbum album = top_albums[i]; Button album_button = new Button (); album_button.Relief = ReliefStyle.None; Label label = new Label (); label.OverrideColor (StateFlags.Normal, StyleContext.GetColor (StateFlags.Normal)); label.Ellipsize = Pango.EllipsizeMode.End; label.Xalign = 0; label.Markup = String.Format ("{0}. {1}", i+1, GLib.Markup.EscapeText (album.Name)); album_button.Add (label); album_button.Clicked += delegate { Banshee.Web.Browser.Open (album.Url); }; album_list.PackStart (album_button, false, true, 0); } album_box.ShowAll (); for (int i = 0; i < Math.Min (5, top_tracks.Count); i++) { ArtistTopTrack track = top_tracks[i]; Button track_button = new Button (); track_button.Relief = ReliefStyle.None; HBox box = new HBox (); Label label = new Label (); label.OverrideColor (StateFlags.Normal, StyleContext.GetColor (StateFlags.Normal)); label.Ellipsize = Pango.EllipsizeMode.End; label.Xalign = 0; label.Markup = String.Format ("{0}. {1}", i+1, GLib.Markup.EscapeText (track.Name)); /*if(node.SelectSingleNode("track_id") != null) { box.PackEnd(new Image(now_playing_arrow), false, false, 0); track_button.Clicked += delegate { //PlayerEngineCore.OpenPlay(Globals.Library.GetTrack( //Convert.ToInt32(node.SelectSingleNode("track_id").InnerText))); }; } else {*/ track_button.Clicked += delegate { Banshee.Web.Browser.Open (track.Url); }; //} box.PackStart (label, true, true, 0); track_button.Add (box); track_list.PackStart (track_button, false, true, 0); } track_box.ShowAll (); ready = true; refreshing = false; context_page.SetState (Banshee.ContextPane.ContextState.Loaded); }); }
public static Dictionary<int, int> GetPresentArtists(LastfmData<UserTopArtist> aData) { Dictionary<string, int> artistMatch = new Dictionary<string, int> (); Dictionary<int, int> artistIdsAndRank = new Dictionary<int, int> (); List<string> mbids = new List<string> (); foreach (UserTopArtist cArtist in aData) { string tmp = Hyena.StringUtil.SearchKey (cArtist.Name); if (!artistMatch.ContainsKey (tmp)) { artistMatch.Add (tmp, cArtist.Rank); mbids.Add (cArtist.MbId); } } using (var reader = ServiceManager.DbConnection.Query (ARTIST_QUERY, artistMatch.Keys.ToArray (), mbids.ToArray ())) { while (reader.Read ()) { int cId = (int)(long)reader[0]; string cName = reader[1] as string; if (artistMatch.ContainsKey (cName)) { artistIdsAndRank.Add (cId, artistMatch[cName]); } } } return artistIdsAndRank; }