示例#1
0
        public DownloadDataAccess(string toolCachePath, string userAgent)
        {
            youTubeDLResolver = new ToolResolver(
                cacheDirectory: Path.Join(toolCachePath, "youtube-dl"),
                fileName: "youtube-dl.exe",
                DownloadResolvers.GitHubReleaseAsset(
                    owner: "ytdl-org",
                    repo: "youtube-dl",
                    assetName: "youtube-dl.exe",
                    userAgent));

            ffmpegResolver = new ToolResolver(
                cacheDirectory: Path.Join(toolCachePath, "ffmpeg"),
                fileName: "ffmpeg.exe",
                getLatestDownloadAsync: async cancellationToken =>
            {
                using var client = OwnershipTracker.Create(
                          new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All }));

                var version = await client.OwnedInstance.GetStringAsync("https://www.gyan.dev/ffmpeg/builds/release-version", cancellationToken).ConfigureAwait(false);

                return(new AvailableToolDownload(
                           version,
                           client.ReleaseOwnership(),
                           downloadUrl: "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip",
                           StreamTransforms.UnzipSingleFile($"ffmpeg-{version}-essentials_build/bin/ffmpeg.exe")));
            });
        }
示例#2
0
            public LeaseSource(string version, RefCountedFileLock fileLock)
            {
                using var lease = OwnershipTracker.Create(fileLock.Lease());

                Version  = version;
                FileLock = fileLock;
                Lease    = lease.ReleaseOwnership();
            }
        public static Func <CancellationToken, Task <AvailableToolDownload> > GitHubReleaseAsset(
            string owner,
            string repo,
            string assetName,
            string userAgent,
            Func <string, Func <Stream, Stream>?>?getStreamTransformForVersion = null)
        {
            if (string.IsNullOrWhiteSpace(owner))
            {
                throw new ArgumentException("Owner must be specified.", nameof(owner));
            }

            if (string.IsNullOrWhiteSpace(repo))
            {
                throw new ArgumentException("Repository must be specified.", nameof(repo));
            }

            if (string.IsNullOrWhiteSpace(assetName))
            {
                throw new ArgumentException("Asset name must be specified.", nameof(assetName));
            }

            if (string.IsNullOrWhiteSpace(userAgent))
            {
                throw new ArgumentException("User agent must be specified.", nameof(userAgent));
            }

            return(async cancellationToken =>
            {
                using var client = OwnershipTracker.Create(
                          new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.All })
                {
                    BaseAddress = new Uri("https://api.github.com"),
                    DefaultRequestHeaders = { { "User-Agent", userAgent } }
                });

                var(version, downloadUrl) = await GetLatestGitHubReleaseAssetAsync(client.OwnedInstance, owner, repo, assetName, cancellationToken);

                if (downloadUrl is null)
                {
                    throw new NotImplementedException($"Unable to find {assetName} in latest GitHub release.");
                }

                var streamTransform = getStreamTransformForVersion?.Invoke(version);

                return new AvailableToolDownload(version, client.ReleaseOwnership(), downloadUrl, streamTransform);
            });
        }