Exemplo n.º 1
0
        public override async Task ProcessInternal(long id, DirectoryInfo workDir, CancellationToken token, ILog log)
        {
            var vkPlaylists = await vkApiUtils.GetAllPagesAsync(vkApiUtils.Playlists(id), 200, token, log);

            log.Debug($"Audio: {vkPlaylists.Count} playlists");
            var expandTasks = vkPlaylists.Select(p => vkApiUtils.ExpandPlaylist(p, token, log));
            var playlists   = await Task.WhenAll(expandTasks);

            log.Debug($"Audio: {playlists.Sum(p => p.Audio.Count)} in {playlists.Length} playlists");

            var allAudios = await vkApiUtils.GetAllPagesAsync(vkApiUtils.Audios(id), long.MaxValue, token, log);

            var audioInPlaylists = playlists
                                   .SelectMany(p => p.Audio.Select(t => t.Id))
                                   .ToHashSet();
            var uniqueAudios = allAudios
                               .Where(a => !audioInPlaylists.Contains(a.Id.Value))
                               .ToList();
            var defaultPlaylist = new PlaylistWithAudio(uniqueAudios);

            log.Debug($"Audio: {allAudios.Count} total, {defaultPlaylist.Audio.Count} unique in default playlist");

            var allPlaylists = playlists.ToList();

            allPlaylists.Add(defaultPlaylist);

            var allTasks = allPlaylists
                           .OrderBy(p => p.Playlist.CreateTime)
                           .Select(p => playlistHandler.Process(p, workDir, token, log));
            await Task.WhenAll(allTasks);
        }
Exemplo n.º 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;
            }
        }