Exemple #1
0
        /// <summary>
        /// Returns a weekly artist chart of a specified week.
        /// </summary>
        /// <param name="span">
        /// A <see cref="WeeklyChartTimeSpan"/>
        /// </param>
        /// <returns>
        /// A <see cref="WeeklyArtistChart"/>
        /// </returns>
        public WeeklyArtistChart GetWeeklyArtistChart(WeeklyChartTimeSpan span)
        {
            RequestParameters p = getParams();

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

            XmlDocument doc = request("user.getWeeklyArtistChart", p);

            XmlNode n = doc.GetElementsByTagName("weeklyartistchart")[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);

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

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

                WeeklyArtistChartItem item =
                    new WeeklyArtistChartItem(new Artist(extract(node, "name"), Session),
                                              rank, playcount, new WeeklyChartTimeSpan(nfrom, nto));

                chart.Add(item);
            }

            return(chart);
        }
Exemple #2
0
        /// <summary>
        /// Returns the latest weekly artist chart.
        /// </summary>
        /// <returns>
        /// A <see cref="WeeklyArtistChart"/>
        /// </returns>
        public WeeklyArtistChart GetWeeklyArtistChart()
        {
            XmlDocument doc = request("tag.getWeeklyArtistChart");

            XmlNode n = doc.GetElementsByTagName("weeklyartistchart")[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);

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

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

                WeeklyArtistChartItem item =
                    new WeeklyArtistChartItem(new Artist(extract(node, "name"), Session),
                                              rank, playcount, new WeeklyChartTimeSpan(nfrom, nto));

                chart.Add(item);
            }

            return(chart);
        }