Exemple #1
0
 public YandexDiskClientWrapper(YandexDiskClient client, string key, object syncOutput = null)
 {
     _key        = key;
     _client     = client;
     _syncOutput = syncOutput ?? new object();
 }
Exemple #2
0
        private async Task downloadSignatures(QualityGroupConfig qualityGroup, CancellationToken token)
        {
            if (qualityGroup.FileListMegaId == null && qualityGroup.YandexName == null)
            {
                return;
            }

            (FsPath signaturesDir, FsPath signaturesFile) = getSignaturesFile(qualityGroup);
            FsPath signaturesFileBak = signaturesFile.Concat(".bak");

            if (signaturesFile.IsFile())
            {
                if (signaturesFileBak.IsFile())
                {
                    signaturesFileBak.DeleteFile();
                }

                signaturesFile.MoveFileTo(signaturesFileBak);
            }

            signaturesDir.CreateDirectory();

            if (qualityGroup.FileListMegaId != null)
            {
                string megaUrl = _config.MegaPrefix + qualityGroup.FileListMegaId;
                await _megatools.Download(megaUrl, signaturesDir,
                                          name : $"Signatures for {qualityGroup.Quality} images", silent : true, token : token);
            }
            else if (qualityGroup.YandexName != null)
            {
                FsPath fileListArchive = signaturesDir.Join("filelist.7z");
                var    client          = new YandexDiskClient();
                Console.Write("{0} filelist.7z: get YandexDisk download url ... ", qualityGroup.Name);
                var url = await client.GetFilelistDownloadUrl(_config, qualityGroup, token);

                Console.Write("downloading ... ");

                bool success;
                try
                {
                    await client.DownloadFile(url, fileListArchive, token);

                    Console.WriteLine($"done");
                    success = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"failed: {ex.Message}");
                    _log.Warn(ex, $"Failed download {fileListArchive} from {url}");
                    success = false;
                }

                if (success)
                {
                    if (fileListArchive.IsFile())
                    {
                        new SevenZip(silent: true).Extract(fileListArchive, signaturesDir);
                    }
                }
            }
            else
            {
                throw new ArgumentException($"No downloader can get filelist for quality {qualityGroup.Quality}");
            }


            if (!signaturesFile.IsFile())
            {
                if (signaturesFileBak.IsFile())
                {
                    Console.WriteLine("Failed to unzip signatures");

                    Console.WriteLine("Move {0} {1}", signaturesFileBak, signaturesFile);
                    signaturesFileBak.MoveFileTo(signaturesFile);
                }
            }
            else
            {
                signaturesFileBak.DeleteFile();
            }
        }
Exemple #3
0
 public YandexDownloader(object syncOutput, YandexDiskClient client)
 {
     _syncOutput = syncOutput;
     _client     = client;
 }