Ejemplo n.º 1
0
        /// <summary>
        /// Returns a weekly album chart of a specified week.
        /// </summary>
        /// <param name="span">A <see cref="WeeklyChartTimeSpan"/></param>
        /// <returns>A <see cref="WeeklyAlbumChart"/></returns>
        public WeeklyAlbumChart GetWeeklyAlbumChart(WeeklyChartTimeSpan span)
        {
            var parameters = GetParams();

            parameters["from"] = Utilities.DateTimeToUTCTimestamp(span.From).ToString();
            parameters["to"]   = Utilities.DateTimeToUTCTimestamp(span.To).ToString();

            XmlDocument doc = Request("user.getWeeklyAlbumChart", parameters);

            XmlNode n = doc.GetElementsByTagName("weeklyalbumchart")[0];

            var nfrom = Utilities.TimestampToDateTime(long.Parse(n.Attributes[1].InnerText), DateTimeKind.Utc);
            var nto   = Utilities.TimestampToDateTime(long.Parse(n.Attributes[2].InnerText), DateTimeKind.Utc);

            var chart = new WeeklyAlbumChart(new WeeklyChartTimeSpan(nfrom, nto));

            foreach (XmlNode node in doc.GetElementsByTagName("album"))
            {
                var rank      = int.Parse(node.Attributes[0].InnerText);
                var playcount = int.Parse(Extract(node, "playcount"));

                var album    = new Album(Extract(node, "artist"), Extract(node, "name"), Session);
                var timeSpan = new WeeklyChartTimeSpan(nfrom, nto);
                var item     = new WeeklyAlbumChartItem(album, rank, playcount, timeSpan);

                chart.Add(item);
            }

            return(chart);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the weekly album chart for this group in the given <see cref="Lastfm.Services.WeeklyChartTimeSpan"/>.
        /// </summary>
        /// <param name="span">
        /// A <see cref="WeeklyChartTimeSpan"/>
        /// </param>
        /// <returns>
        /// A <see cref="WeeklyAlbumChart"/>
        /// </returns>
        public WeeklyAlbumChart GetWeeklyAlbumChart(WeeklyChartTimeSpan span)
        {
            RequestParameters p = getParams();

            p["from"] = Utilities.DateTimeToUTCTimestamp(span.From).ToString();
            p["to"]   = Utilities.DateTimeToUTCTimestamp(span.To).ToString();

            XmlDocument doc = request("group.getWeeklyAlbumChart", p);

            XmlNode n = doc.GetElementsByTagName("weeklyalbumchart")[0];

            DateTime nfrom = Utilities.TimestampToDateTime(Int64.Parse(n.Attributes[1].InnerText), DateTimeKind.Utc);
            DateTime nto   = Utilities.TimestampToDateTime(Int64.Parse(n.Attributes[2].InnerText), DateTimeKind.Utc);

            WeeklyAlbumChart chart = new WeeklyAlbumChart(new WeeklyChartTimeSpan(nfrom, nto));

            foreach (XmlNode node in doc.GetElementsByTagName("album"))
            {
                int rank      = Int32.Parse(node.Attributes[0].InnerText);
                int playcount = Int32.Parse(extract(node, "playcount"));

                WeeklyAlbumChartItem item =
                    new WeeklyAlbumChartItem(new Album(extract(node, "artist"), extract(node, "name"), Session),
                                             rank, playcount, new WeeklyChartTimeSpan(nfrom, nto));

                chart.Add(item);
            }

            return(chart);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the latest weekly album chart.
        /// </summary>
        /// <returns>
        /// A <see cref="WeeklyAlbumChart"/>
        /// </returns>
        public WeeklyAlbumChart GetWeeklyAlbumChart()
        {
            XmlDocument doc = request("user.getWeeklyAlbumChart");

            XmlNode n = doc.GetElementsByTagName("weeklyalbumchart")[0];

            DateTime nfrom = Utilities.TimestampToDateTime(Int64.Parse(n.Attributes[1].InnerText), DateTimeKind.Utc);
            DateTime nto   = Utilities.TimestampToDateTime(Int64.Parse(n.Attributes[2].InnerText), DateTimeKind.Utc);

            WeeklyAlbumChart chart = new WeeklyAlbumChart(new WeeklyChartTimeSpan(nfrom, nto));

            foreach (XmlNode node in doc.GetElementsByTagName("album"))
            {
                int rank      = Int32.Parse(node.Attributes[0].InnerText);
                int playcount = Int32.Parse(extract(node, "playcount"));

                WeeklyAlbumChartItem item =
                    new WeeklyAlbumChartItem(new Album(extract(node, "artist"), extract(node, "name"), Session),
                                             rank, playcount, new WeeklyChartTimeSpan(nfrom, nto));

                chart.Add(item);
            }

            return(chart);
        }