Ejemplo n.º 1
0
            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;
            }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
            }
Ejemplo n.º 4
0
        public VK.Audio[] Get(VK.UID page, bool needUserDigest, VK.AudioOwnerDigest userDigest, VK.AudioAlbum album = null, int offset = 0, int count = -1)
#endif
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (!page.IsValid)
                throw new ArgumentException("Invalid page UID specified.");
            else if (album != null && album.ID.Page != page)
                throw new ArgumentException("Invalid 'album' specified, this album does not belong to the specified page.");
            else if (album != null && !album.IsValid)
                throw new ArgumentException("Album does not exists.");
            else if (offset < -1)
                throw new ArgumentOutOfRangeException("offset", "Invalid 'offset' value.");

            // Request
            var args = new NameValueCollection();
            if(page != HostSession.UserPage)
                args.Add("owner_id", page.Value.ToString());
            if (album != null)
                args.Add("album_id", album.ID.Ordinal.ToString());
            if (needUserDigest)
                args.Add("need_user", "1");
            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.get", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.get", args);
#endif

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

            // Parse user digest
            if (needUserDigest && response["user"] != null)
                userDigest.Parse(response["user"]);

            // Parse audios
            VK.Audio[] audios = null;
            if (response.GetAttribute("list") == "true")    // Notice: maybe this is incorrect, but currently okay
            {
                audios = new VK.Audio[response.ChildNodes.Count];
                int iCount = 0;
                foreach (XmlElement node in response.ChildNodes)
                {
                    // Ensure it is audio
                    if (node.Name != "audio")
                        throw new VK.APIImplException(HostSession, "audio.get", "Unexpected server reply. "
                            + "Unexpected XML node; expected 'audio', got '" + node.Name + "'.");

                    audios[iCount] = new VK.Audio();
                    audios[iCount++].Parse(node);
                }
            }

            // Done
            return audios;
        }
Ejemplo n.º 5
0
        public void Update(VK.Audio audio)
#endif
        {
            // Call Update(ref VK.Audio[])
            var audios = new VK.Audio[1] { audio };
#if NEWSTYLE
            int updatedCount = await Update(audios);
#else
            int updatedCount = Update(audios);
#endif
            if (updatedCount != 1)
                throw new VK.APIImplException(HostSession, "audio.getById","updatedCount is " + updatedCount + ", expected: 1.");

            // Done
            audio = audios[0];
        }
Ejemplo n.º 6
0
        Clone(VK.Audio audio, VK.UID addToPage, bool cloneTag = true)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if(!audio.ID.IsValid)
                throw new ArgumentException("Invalid Audio identfier specified.");
            else if (!addToPage.IsValid)
                throw new ArgumentException("Invalid page UID specified.");
            else if (!addToPage.IsCommunity && addToPage.Value != HostSession.UserPage.Value)
                throw new ArgumentException("It is not possible to add audios to other's profile pages.");

            // Request
            var args = new NameValueCollection();
            args.Add("owner_id", audio.ID.Page.ToString());
            args.Add("audio_id", audio.ID.Ordinal.ToString());
            if (addToPage != HostSession.UserPage)
                args.Add("group_id", addToPage.AbsoluteValue.ToString());
#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.add", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.add", args);
#endif

            // Check
            uint newAudioLocalId = 0;
            if (response == null || string.IsNullOrEmpty(response.InnerText) || !uint.TryParse(response.InnerText, out newAudioLocalId))
                throw new VK.APIImplException(HostSession, "audio.add", "Unexpected server reply.");

            // Build new Audio object from copied audio cloned
            var audioCloned = new VK.Audio
            {
                Artist = audio.Artist,
                Title = audio.Title,
                DownloadUrl = audio.DownloadUrl,
                Genre = audio.Genre,
                Duration = audio.Duration,
                Tag = cloneTag ? audio.Tag : null,
                KnownLyrics = audio.KnownLyrics,
                ID = new VK.DualID(addToPage, newAudioLocalId),
            };
            return audioCloned;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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();
          }