示例#1
0
        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
        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);
            }
        }