Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="post"></param>
        /// <param name="jPost"></param>
        public static void GenerateAudioPost(ref TumblrPost post, dynamic jPost)
        {
            if (post == null)
            {
                throw new ArgumentNullException(nameof(post));
            }
            if (jPost == null)
            {
                throw new ArgumentNullException(nameof(jPost));
            }

            post = new AudioPost
            {
                Artist     = !string.IsNullOrEmpty((string)jPost.artist) ? jPost.artist : null,
                Album      = !string.IsNullOrEmpty((string)jPost.album) ? jPost.album : null,
                AlbumArt   = !string.IsNullOrEmpty((string)jPost.album_art) ? jPost.album_art : null,
                TrackName  = !string.IsNullOrEmpty((string)jPost.track_name) ? jPost.track_name : null,
                Caption    = !string.IsNullOrEmpty((string)jPost.caption) ? jPost.caption : null,
                AudioType  = !string.IsNullOrEmpty((string)jPost.audio_type) ? jPost.audio_type : null,
                AudioUrl   = !string.IsNullOrEmpty((string)jPost.audio_url) ? jPost.audio_url : null,
                PlaysCount = !string.IsNullOrEmpty((string)jPost.plays) ? jPost.plays : null,
                Player     = !string.IsNullOrEmpty((string)jPost.player) ? jPost.player : null
            };
            IncludeCommonPostFields(ref post, jPost);
        }
Beispiel #2
0
        private AudioPost ParseAudioPost(JObject jObject, HashSet <string> checkedProperties)
        {
            AudioPost newPost = new AudioPost();
            JToken    current;

            if (CheckProperty(jObject, "caption", checkedProperties, out current))
            {
                newPost.Caption = (string)current;
            }
            if (CheckProperty(jObject, "player", checkedProperties, out current))
            {
                newPost.Player = (string)current;
            }
            if (CheckProperty(jObject, "plays", checkedProperties, out current))
            {
                newPost.Plays = (long?)current ?? 0;
            }
            if (CheckProperty(jObject, "album_art", checkedProperties, out current))
            {
                newPost.AlbumArt = (string)current;
            }
            if (CheckProperty(jObject, "artist", checkedProperties, out current))
            {
                newPost.Artist = (string)current;
            }
            if (CheckProperty(jObject, "album", checkedProperties, out current))
            {
                newPost.Album = (string)current;
            }
            if (CheckProperty(jObject, "track_name", checkedProperties, out current))
            {
                newPost.TrackName = (string)current;
            }
            if (CheckProperty(jObject, "track_number", checkedProperties, out current))
            {
                newPost.TrackNumber = (long)current;
            }
            if (CheckProperty(jObject, "year", checkedProperties, out current))
            {
                newPost.Year = (long)current;
            }
            if (CheckProperty(jObject, "audio_url", checkedProperties, out current))
            {
                newPost.AudioUrl = (string)current;
            }
            if (CheckProperty(jObject, "track", checkedProperties, out current))
            {
                newPost.Track = (string)current;
            }
            if (CheckProperty(jObject, "embed", checkedProperties, out current))
            {
                newPost.Embed = (string)current;
            }
            return(newPost);
        }
Beispiel #3
0
    void playAudioClips(string[] audioClipKeys)
    {
        if (audioClipKeys == null || audioClipKeys.Length == 0)
        {
            onFinishedPlayingAudioClips(1);
            return;
        }

        Debug.LogFormat("playAudioClips {0}", audioClipKeys);

        AudioPost audioPost = findAudioPostForAudioClip(audioClipKeys [0]);

        if (audioPost == null)
        {
            onFinishedPlayingAudioClips(-1);
            return;
        }

        audioPost.Play(audioClipKeys[0], (AudioPost soruceAudioPost, int status) => {
            this.playAudioClips(audioClipKeys.Skip(1).ToArray());
        });
    }
Beispiel #4
0
        public async Task <(List <AudioPost> Posts, int TotalCount)> GetWallPosts(int count = 300, int offset = 0, long ownerId = 0)
        {
            (List <AudioPost> Posts, int TotalCount)result = (null, 0);

            try
            {
                var response = await _vk.Wall.Get(ownerId : ownerId, filter : "all", count : count, offset : offset);

                if (response?.Items.IsNullOrEmpty() == false)
                {
                    var audioIds         = new List <string>();
                    var posts            = new List <AudioPost>();
                    var postAudioMatches = new Dictionary <string, IList <string> >();

                    foreach (var newsEntry in response.Items)
                    {
                        var attachments = newsEntry.Attachments;

                        //if there are no attachments of this post, but there is repost history, take attachments from last repost
                        if (attachments.IsNullOrEmpty() && !newsEntry.CopyHistory.IsNullOrEmpty())
                        {
                            attachments = newsEntry.CopyHistory.Last().Attachments;
                        }

                        if (attachments.IsNullOrEmpty())
                        {
                            continue;
                        }

                        var ids = attachments.Where(a => a is VkAudioAttachment).Select(a => $"{a.OwnerId}_{a.Id}").ToList();
                        audioIds.AddRange(ids);

                        var post = new AudioPost();
                        post.Id        = newsEntry.Id.ToString();
                        post.Text      = newsEntry.Text;
                        post.PostUri   = new Uri($"http://vk.com/wall{newsEntry.SourceId}_{post.Id}");
                        post.AuthorUri = new Uri(string.Format("https://vk.com/{0}{1}", newsEntry.Author is VkGroup ? "club" : "id", newsEntry.Author.Id));

                        var imageUrl = newsEntry.Attachments?.OfType <VkPhotoAttachment>().FirstOrDefault()?.SourceMax;
                        if (!string.IsNullOrEmpty(imageUrl))
                        {
                            post.ImageUri = new Uri(imageUrl);
                        }

                        post.Author = newsEntry.Author;
                        post.Date   = newsEntry.Date;
                        posts.Add(post);

                        postAudioMatches.Add(post.Id, ids);
                    }

                    if (audioIds.Count == 0)
                    {
                        return(result);
                    }

                    var tracks = new List <IAudio>();

                    var audioIdsChunks = audioIds.Split(100); //split ids by chunks of 100 ids (api restriction)
                    foreach (var audioIdsChunk in audioIdsChunks)
                    {
                        var resultAudios = await _vk.Audio.GetById(audioIdsChunk.ToList());

                        if (!resultAudios.IsNullOrEmpty())
                        {
                            tracks.AddRange(ProcessTracks(resultAudios));
                        }
                    }

                    foreach (var post in posts)
                    {
                        post.Tracks = tracks.Where(t => postAudioMatches[post.Id].Contains($"{t.OwnerId}_{t.Id}")).ToList();
                    }

                    result.Posts        = posts.Where(p => p.Tracks.Count > 0).ToList();
                    response.TotalCount = response.TotalCount;
                }
            }
            catch (VkInvalidTokenException)
            {
                Messenger.Default.Send(new MessageUserAuthChanged {
                    IsLoggedIn = false
                });
            }

            return(result);
        }