Exemplo n.º 1
0
 public static async Task SaveText(this Photo photo, int i, FilesystemTools filesystemTools, DirectoryInfo dir, CancellationToken token, ILog log)
 {
     if (!string.IsNullOrWhiteSpace(photo.Text))
     {
         var textFile = filesystemTools.CreateFile(dir, $"{i} {photo.Id}.txt", CreateMode.OverwriteExisting);
         await File.WriteAllTextAsync(textFile.FullName, photo.Text, token);
     }
 }
Exemplo n.º 2
0
        public static IEnumerable <IDownload> ToDownloads(this Audio audio, int i, FilesystemTools filesystemTools, DirectoryInfo dir, ILog log)
        {
            var trackName = audio.GetName();

            if (audio.Url != null)
            {
                yield return(new Download(audio.Url, dir, $"{i} {trackName}.mp3"));
            }
            else
            {
                filesystemTools.CreateFile(dir, $"{i} {trackName}.mp3.deleted", CreateMode.OverwriteExisting);
            }
        }
Exemplo n.º 3
0
        public static IEnumerable <IDownload> ToDownloads(this Video video, int i, FilesystemTools filesystemTools, DirectoryInfo dir, ILog log)
        {
            var vkUrl = video.Files?.Mp4_1080
                        ?? video.Files?.Mp4_720
                        ?? video.Files?.Mp4_480
                        ?? video.Files?.Mp4_360
                        ?? video.Files?.Mp4_240;

            if (vkUrl != null)
            {
                yield return(new Download(vkUrl, dir, video.Title));
            }
            else if (video.Files?.External != null)
            {
                log.Warn($"Video {video.Id} [{video.Title}] is external");
                yield return(new Download(video.Files.External, dir, video.Title));
            }
            else
            {
                log.Warn($"Video {video.Id} [{video.Title}] has no links. Trying to compose vk url");
                var file = filesystemTools.CreateFile(dir, $"{i} {video.Id}.txt", CreateMode.OverwriteExisting);
                File.WriteAllText(file.FullName, $"https://vk.com/video{video.OwnerId}_{video.Id}");
            }
        }
Exemplo n.º 4
0
 public static async Task SaveHumanReadableText(this IReadOnlyList <Comment> comments, FilesystemTools filesystemTools, DirectoryInfo dir, CancellationToken token, ILog log)
 {
     var data     = string.Join("\n\n", comments.Select(c => c.Serialize()));
     var textFile = filesystemTools.CreateFile(dir, $"comments.txt", CreateMode.OverwriteExisting);
     await File.WriteAllTextAsync(textFile.FullName, data, token);
 }
Exemplo n.º 5
0
 public static async Task SaveHumanReadableText(this Link link, int i, FilesystemTools filesystemTools, DirectoryInfo dir, CancellationToken token, ILog log)
 {
     var textFile = filesystemTools.CreateFile(dir, $"{i} {link.Title}.txt", CreateMode.OverwriteExisting);
     await File.WriteAllTextAsync(textFile.FullName, link.Serialize(), token);
 }