public override async Task ProcessInternal(long id, DirectoryInfo workDir, CancellationToken token, ILog log)
        {
            var vkAlbums = await vkApiUtils.GetAllPagesAsync(vkApiUtils.PhotoAlbums(id), int.MaxValue, token, log);

            var expandTasks = vkAlbums.Select(album => vkApiUtils.ExpandAlbum(album, token, log));
            var albums      = await Task.WhenAll(expandTasks);

            var allPhotos = await vkApiUtils.GetAllPagesAsync(vkApiUtils.Photos(id), 100, token, log);

            var photosInAlbums = albums
                                 .SelectMany(awp => awp.Photo.Select(photo => photo.Id.Value))
                                 .ToHashSet();
            var uniquePhotos = allPhotos
                               .Where(photo => !photosInAlbums.Contains(photo.Id.Value))
                               .ToList();
            var defaultAlbum = new AlbumWithPhoto(uniquePhotos);

            var allAlbums = albums.ToList();

            if (defaultAlbum.Photo.Any())
            {
                allAlbums.Add(defaultAlbum);
            }

            var allTasks = allAlbums
                           .OrderBy(p => p.Album.Created)
                           .Select(p => albumHandler.Process(p, workDir, token, log));
            await Task.WhenAll(allTasks);
        }
Beispiel #2
0
        public async Task ProcessAttachment(MediaAttachment mediaAttachment, int number, DirectoryInfo workDir, CancellationToken token, ILog log)
        {
            switch (mediaAttachment)
            {
            case VkNet.Model.Attachments.Photo photo:
                await downloadQueueProvider.EnqueueAll(photo.ToDownloads(number, filesystemTools, workDir, log), token);

                await photo.SaveText(number, filesystemTools, workDir, token, log);

                break;

            case VkNet.Model.Attachments.Audio audio:
                await downloadQueueProvider.EnqueueAll(audio.ToDownloads(number, filesystemTools, workDir, log), token);

                await audio.SaveLyrics(number, vkApi, filesystemTools, workDir, token, log);

                break;

            case VkNet.Model.Attachments.Document document:
                await downloadQueueProvider.EnqueueAll(document.ToDownloads(number, filesystemTools, workDir, log), token);

                break;

            case VkNet.Model.Attachments.Poll poll:
                await downloadQueueProvider.EnqueueAll(poll.ToDownloads(number, filesystemTools, workDir, log), token);

                await poll.SaveHumanReadableText(number, filesystemTools, workDir, token, log);

                break;

            case VkNet.Model.Attachments.Link link:
                await downloadQueueProvider.EnqueueAll(link.ToDownloads(number, filesystemTools, workDir, log), token);

                await link.SaveHumanReadableText(number, filesystemTools, workDir, token, log);

                break;

            case VkNet.Model.Attachments.AudioPlaylist audioPlaylist:
                var playlistWithAudio = await vkApiUtils.ExpandPlaylist(audioPlaylist, token, log);

                var playlistHandler = ServiceProvider.GetRequiredService <IHandler <PlaylistWithAudio> >();
                await playlistHandler.Process(playlistWithAudio, workDir, token, log);

                break;

            case VkNet.Model.Attachments.Album album:
                var albumWithPhoto = await vkApiUtils.ExpandAlbum(album, token, log);

                var albumHandler = ServiceProvider.GetRequiredService <IHandler <AlbumWithPhoto> >();
                await albumHandler.Process(albumWithPhoto, workDir, token, log);

                break;

            case VkNet.Model.Attachments.Video video:
                await downloadQueueProvider.EnqueueAll(video.ToDownloads(number, filesystemTools, workDir, log), token);

                break;

            case VkNet.Model.Attachments.Note note:      // note и page похожи
            case VkNet.Model.Attachments.Page page:



            // остальное похоже на хлам
            case VkNet.Model.Attachments.ApplicationContent applicationContent:
            case VkNet.Model.Attachments.AudioMessage audioMessage:
            case VkNet.Model.Attachments.Gift gift:
            case VkNet.Model.Attachments.Graffiti graffiti:
            case VkNet.Model.Attachments.MarketAlbum marketAlbum:
            case VkNet.Model.Attachments.PrettyCards prettyCards:
            case VkNet.Model.Attachments.Sticker sticker:
            case VkNet.Model.Attachments.StringLink stringLink:
            case VkNet.Model.Attachments.WallReply wallReply:
            default:
                log.Warn($"Not yet supported: attachment [{mediaAttachment.GetType().FullName}] {JsonConvert.SerializeObject(mediaAttachment)}");
                break;
            }
        }