示例#1
0
文件: UserPage.cs 项目: CrackHD/vk9
            internal override bool ParseUpdate(XmlNode node)
            {
                /*
                 response: [{
                    type: 'profile',
                    id: 54986442,
                    first_name: 'Ivan',
                    last_name: 'Gusev',
                    status_audio: {
                        id: 219551350,
                        owner_id: 54986442,
                        artist: 'PJ Harvey',
                        title: 'To Bring You My Love',
                        duration: 2003,
                        url: 'http://cs5214.vk.me/u3878271/audios/d548b6566235.mp3',
                        genre_id: 18
                    }
                    }]
                 */

                var e = node["type"];
                if (e != null && e.InnerText != "profile")
                    throw new NotImplementedException(e.ToString());//TMP

                int id = 0;
                e = node["uid"];
                if (e == null || string.IsNullOrEmpty(e.InnerText) || !int.TryParse(e.InnerText, out id))
                    return false;
                base.ID = new UID(id);

                e = node["first_name"];
                this.FirstName = e != null ? e.InnerText : null;

                e = node["last_name"];
                this.LastName = e != null ? e.InnerText : null;

                e = node["status_audio"];
                if (e != null)
                {
                    var audio = new VK.Audio();
                    if (audio.Parse(e))
                        this.Status = new PageStatus { Audio = audio };
                }

                return true;
            }
示例#2
0
            internal override bool ParseUpdate(XmlNode node)
            {
                /*
                 <group>
                 * <gid>70923428</gid>
                 * <name>4564 уцавр</name>
                 * <screen_name>beat_antology</screen_name>
                 * <is_closed>0</is_closed>
                 * <type>page</type>
                 * <photo>http://cs617730.vk.me/v617730104/833b/gmDdDp6PLGI.jpg</photo>
                 * <photo_medium>http://cs617730.vk.me/v617730104/833a/W6OImDzYLFU.jpg</photo_medium>
                 * <photo_big>http://cs617730.vk.me/v617730104/8339/pYtC28EnGgE.jpg</photo_big>
                 * <status_audio>
                     * <aid>283968493</aid>               audio.getBroadcastList()
                     * <owner_id>250113104</owner_id>
                     * <artist>Ying Yang Twins</artist>
                     * <title>Jigglin</title>
                     * <duration>204</duration>
                     * <url>http://cs1-36v4.vk.me/p16/6cdab3913e11c9.mp3?extra=yH62WekOtZ9k9Egq0totysy-etAoipYMv0DvUNVpsC0Czh5tVzbUEnzqzl1oukCZ45eY_2dZb_-8_imQHYeWiRxnBgtF6RX2wQ</url>
                     * <performer>Ying Yang Twins</performer>
                     * <lyrics_id>5884568</lyrics_id>
                     * <genre>3</genre>
                 * </status_audio>
                </group>
                 */

                int gid = 0;
                var e = node["gid"];
                if (e == null || string.IsNullOrEmpty(e.InnerText) || !int.TryParse(e.InnerText, out gid))
                    return false;
                base.ID = new UID(gid);

                e = node["name"];
                this.Name = e != null ? e.InnerText : null;

                e = node["screen_name"];
                this.ShortUrl = e != null ? e.InnerText : null;

                e = node["deactivated"];
                if (e != node)
                {
                    if (e.InnerText == "deleted")
                        this.PageState = CommunityDeactivation.Deleted;
                    else if (e.InnerText == "banned")
                        this.PageState = CommunityDeactivation.Banned;
                    else
                        throw new NotImplementedException(e.ToString());
                }
                else
                    this.PageState = CommunityDeactivation.Active;

                e = node["photo"];
                this.PhotoSmall = e != null ? new Uri(e.InnerText) : null;

                e = node["photo_medium"];
                this.PhotoMedium = e != null ? new Uri(e.InnerText) : null;

                e = node["photo_big"];
                this.PhotoBig = e != null ? new Uri(e.InnerText) : null;

                e = node["is_closed"];
                this.Type = (CommunityType)byte.Parse(e.InnerText);

                e = node["is_admin"];
                if (e != null)
                {
                    e = node["admin_level"];
                    byte code = 0;
                    if (e != null && byte.TryParse(e.InnerText, out code))
                        this.UserLevel = (CommunityUserLevel)code;
                }
                else
                    this.UserLevel = CommunityUserLevel.User;

                e = node["is_member"];
                this.IsUserMember = e != null ? (e.InnerText != "0") : new Nullable<bool>();

                e = node["status_audio"];
                if (e != null)
                {
                    var audio = new VK.Audio();
                    if (audio.Parse(e))
                        this.Status = new PageStatus { Audio = audio };
                }

                return true;
            }
示例#3
0
        UploadSave(VK.AudioUploadKey uploadKey, string changeArtist = null, string changeTitle = null)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            // Check
            if (string.IsNullOrEmpty(uploadKey._SERVER) || string.IsNullOrEmpty(uploadKey._AUDIO) || string.IsNullOrEmpty(uploadKey._HASH))
                throw new ArgumentNullException();

            // Request
            var args = new NameValueCollection();
            args.Add("server", uploadKey._SERVER);
            args.Add("audio", uploadKey._AUDIO);
            args.Add("hash", uploadKey._HASH);
            if (changeArtist != null)
                args.Add("artist", changeArtist);
            if (changeTitle != null)
                args.Add("title", changeTitle);

#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.save", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.save", args);
#endif

            // Check
            if (response == null || response["audio"] == null)
                throw new VK.APIImplException(HostSession, "audio.save", "Unexpected server reply.");

            // Parse
            var uploadedAudio = new VK.Audio();
            uploadedAudio.Parse(response["audio"]);

            // Done
            return uploadedAudio;
        }
示例#4
0
 Search(string query, bool queryAutoCorrect, bool searchOwnOnly, bool searchByPerformersOnly, VK.AudioSearchResultSort sortMode,
            bool onlyWithLyrics, uint offset, uint count)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (query == null)
                throw new ArgumentNullException("query");

            // Request
            var args = new NameValueCollection();
            args.Add("q", query);
            args.Add("auto_complete", queryAutoCorrect ? "1" : "0");
            args.Add("lyrics", onlyWithLyrics ? "1" : "0");
            args.Add("performer_only", searchByPerformersOnly ? "1" : "0");
            args.Add("sort", ((byte)sortMode).ToString());
            args.Add("search_own", searchOwnOnly ? "1" : "0");
            args.Add("offset", offset.ToString());
            args.Add("count", count.ToString());

#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.search", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.search", args);
#endif

            // Check
            if (response == null)
                throw new VK.APIImplException(HostSession, "audio.search", "Unexpected server reply.");

            uint totalCount = 0;

            // Parse totalCount
            if (response["count"] != null)
            {
                // We have totalCount
                totalCount = uint.Parse(response["count"].InnerText);
                if (count <= 0 || count > totalCount)
                    count = totalCount;
                response.RemoveChild(response["count"]);
            }

            // Parse
            List<VK.Audio> audios = new List<VK.Audio>();
            if (response.GetAttribute("list") == "true")
            {
                foreach (XmlElement node in response.ChildNodes)
                {
                    // Ensure it is what we expect
                    // Ensure it is what we expect
                    if (node.Name != "audio")
                        throw new VK.APIImplException(HostSession, "audio.get", "Unexpected server reply. "
                            + "Unexpected XML node; expected 'audio', got '" + node.Name + "'.");

                    var audio = new VK.Audio();
                    if (audio.Parse(node))
                        audios.Add(audio);
                }
            }

            // Done
            return new ArraySegment<VK.Audio, uint>(audios.ToArray(), totalCount);
        }
示例#5
0
        GetPopular(VK.AudioGenre genre = VK.AudioGenre.Unknown_Any, bool onlyEnglish = false, int offset = -1, int count = -1)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (offset < -1)
                throw new IndexOutOfRangeException("Offset must be positive value or -1.");
            else if (count < -1 || count > 1000 || count == 0)
                throw new ArgumentOutOfRangeException("'count' is negative, zero or exceeds its maximum (1000).");

            // Request
            var args = new NameValueCollection {  { "only_eng", onlyEnglish ? "1" : "0" } };
            if (genre != VK.AudioGenre.Unknown_Any)
                args.Add("genre_id", ((byte)genre).ToString());
            if (offset != -1)
                args.Add("offset", offset.ToString());
            if (count != -1)
                args.Add("count", count.ToString());

#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.getPopular", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.getPopular", args);
#endif

            // Check
            if (response == null)
                throw new VK.APIImplException(HostSession, "audio.getPopular", "Unexpected server reply.");

            // Parse
            List<VK.Audio> audios = new List<VK.Audio>();
            if (response.GetAttribute("list") == "true")
            {
                foreach (XmlElement node in response.ChildNodes)
                {
                    // Ensure it is what we expect
                    if (node.Name != "audio")
                        throw new VK.APIImplException(HostSession, "audio.get", "Unexpected server reply. "
                            + "Unexpected XML node; expected 'audio', got '" + node.Name + "'.");

                    var audio = new VK.Audio();
                    if (audio.Parse(node))
                        audios.Add(audio);
                }
            }

            // Done
            return audios.ToArray();
          }