Ejemplo n.º 1
0
        public IRankedList<ITrack> GetMonthlyChart(string username, int year, int month, uint take)
        {
            //TODO: this method definitely needs to rely on some error handling as the throttle limit is met quite easy
            IUserService userService = new UserService(this.Session);

            var startDate = new DateTime(year, month, 1);
            var startTimestamp = new Timestamp(startDate);
            var endDate = new DateTime(year, month + 1, 1).AddSeconds(-1);
            var endTimestamp = new Timestamp(endDate);

            var tracks = new Collection<ITrack>();

            int page = 1;
            int totalPages = 1;

            while (page <= totalPages && page < 50)
            {
                var recentTracks = userService.GetRecentTracks(username, 200, page, startTimestamp, endTimestamp);
                if (totalPages != recentTracks.TotalPages)
                {
                    totalPages = recentTracks.TotalPages;
                }

                foreach (var recentTrack in recentTracks)
                {
                    tracks.Add(recentTrack);
                }

                page++;
            }

            // TODO: refactor all over the place the use of int / uint / long / ulong
            return new RankedListBuilder<ITrack>(tracks).Skim((int)take);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            ISession session = new Session("b505c78debb9adce28d17a0010c76ee8");
            TrackService ts = new TrackService(session);

            var artist = ts.GetInfo("that man will not hang", "mclusky");

            Console.Write("{0} {1} {2} {3}", artist.Duration, artist.Streamable, artist.Duration, artist.Listeners);

            Console.WriteLine();
            Console.WriteLine();

            var us = new UserService(session);
            var u = us.GetInfo("rdcarp");

            Console.WriteLine(u.Age);
            Console.WriteLine(u.Playcount);
            Console.WriteLine(u.RealName);
            Console.WriteLine(u.Playlists);
            Console.WriteLine(u.Country);
            Console.WriteLine(u.Id);

            Console.WriteLine();
            Console.WriteLine();

            RankedListBuilder<string> rlb = new RankedListBuilder<string>();

            rlb.Add("fooo");
            rlb.Add("foo");
            rlb.Add("bar");
            rlb.Add("foo");
            rlb.Add("bar");
            rlb.Add("foo");
            rlb.Add("rich");
            rlb.Add("Noah");
            rlb.Add("Noah");
            rlb.Add("Laura");
            rlb.Add("Laura");
            rlb.Add("Laura");
            rlb.Add("Laura");
            rlb.Add("Noah");

            var rl = rlb.Skim(3);

            foreach (var rankedItem in rl)
            {
                Console.WriteLine("{0} - {1} - {2}", rankedItem.Rank, rankedItem.Item, rankedItem.Weight);
            }

            Console.WriteLine();
            Console.WriteLine();

            var ls = new LibraryService(session);

            //var topTracks = ls.GetMonthlyChart("rdcarp", 2013, 1, 10);

            //foreach (var rankedItem in topTracks)
            //{
            //    Console.WriteLine("{0} - {1} ({2})", rankedItem.Rank, rankedItem.Item.Name, rankedItem.Weight);
            //}

            var artists = ls.GetArtists("rdcarp", 0, 10);
            foreach (var artist1 in artists)
            {
                Console.WriteLine("{0}", artist1.Name);
            }

            Console.ReadKey();
        }