コード例 #1
0
ファイル: Program.cs プロジェクト: tvdburgt/subtle
        private static async Task DownloadSubtitlesAsync(IEnumerable <SubtitleSelection> subs)
        {
            if (!subs.Any())
            {
                return;
            }

            var downloads = await client.DownloadSubtitlesAsync(subs.Select(s => s.Selection.Id).ToArray());

            foreach (var file in downloads)
            {
                var sub  = subs.First(s => s.Selection.Id == file.Id); // Same subtitle might be used for multiple files
                var path = Path.ChangeExtension(sub.File, sub.Selection.FileFormat);
                var data = Convert.FromBase64String(file.Base64Data);
                File.WriteAllBytes(path, Gzip.Decompress(data));
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: stolorz/subtle
        private async Task <SubtitleFile> DownloadSubtitle(string subId)
        {
            try
            {
                var subs = await osdbClient.DownloadSubtitlesAsync(subId);

                return(subs.First());
            }
            catch (OSDbException e)
            {
                var result = MessageBox.Show(
                    $"Failed to download subtitle: {e.Message}",
                    "Error",
                    MessageBoxButtons.RetryCancel,
                    MessageBoxIcon.Error);

                if (result == DialogResult.Retry)
                {
                    return(await DownloadSubtitle(subId));
                }

                return(null);
            }
        }