Example #1
0
        private void HandleDownloadFeedback(
            string line,
            YtDownloadInfo downloadInfo
            )
        {
            var parsedData = _parser.Parse(line, downloadInfo.Id, downloadInfo.Url, downloadInfo.OutputFile);

            if (parsedData == null || parsedData.IsEmpty)
            {
                Logger.Debug("Download Non Parseable: " + line);
                return;
            }
            downloadInfo.DownloadChanged?.Invoke(null, new DownloadCompletedEventArgs(parsedData));
        }
Example #2
0
        private void HandleDownloadCompleted(int exitCode, YtDownloadInfo downloadInfo)
        {
            var di    = new DownloadInfo(downloadInfo.Id, downloadInfo.OutputFile, downloadInfo.Url);
            var finfo = new FileInfo(downloadInfo.OutputFile);

            if (finfo.Exists)
            {
                di.BytesTotal    = (int)finfo.Length;
                di.BytesReceived = di.BytesTotal;
            }
            else
            {
                di.BytesTotal    = 1;
                di.BytesReceived = 1;
            }
            Logger.Debug("Download exit code: " + exitCode);
            di.DownloadFaulted = (exitCode != 0);
            downloadInfo.DownloadCompleted?.Invoke(null, new DownloadCompletedEventArgs(di));
        }
Example #3
0
        public override void Download(
            string id,
            string filePath,
            Uri url,
            IEnumerable <KeyValuePair <string, string> > cookies,
            bool disableTracking,
            DownloadChangedEventHandler downloadChanged     = null,
            DownloadCompletedEventHandler downloadCompleted = null)
        {
            string outputFilePath = filePath.ToSafePath();
            var    downloadInfo   = new YtDownloadInfo(id, outputFilePath, url, cookies, disableTracking, downloadChanged, downloadCompleted);

            if (PrepareOutputDirectory(outputFilePath))
            {
                Sys.RunProcess(
                    _bin,
                    downloadInfo.GetCommadArguments(),
                    true,
                    (data) => HandleDownloadFeedback(data, downloadInfo),
                    (error) => HandleDownloadError(error),
                    (exitCode) => HandleDownloadCompleted(exitCode, downloadInfo));
            }
        }