Beispiel #1
0
        public IActionResult DownloadVideo(string url)
        {
            youtubeDl.CancelDownload();
            var process = new Process();

            process.StartInfo.FileName = "./del.bat";

            process.StartInfo.CreateNoWindow  = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.WaitForExit();

            youtubeDl.Options.FilesystemOptions.Output = "/video.mp4";

            youtubeDl.Options.VideoFormatOptions.Format          = NYoutubeDL.Helpers.Enums.VideoFormat.mp4;
            youtubeDl.Options.PostProcessingOptions.ExtractAudio = false;

            youtubeDl.VideoUrl = url;

            System.Diagnostics.Debug.WriteLine("ok");

            youtubeDl.Download();
            youtubeDl.CancelDownload();



            return(Ok(url));
        }
Beispiel #2
0
        public override async Task <VideoUrlParseResult> ParseByUrlAsync(string url, bool getTitle)
        {
            var youtubeDl = new YoutubeDL {
                RetrieveAllInfo = true,
                YoutubeDlPath   = GetPath(AppConfig.YoutubeDLPath),
                PythonPath      = GetPath(AppConfig.PythonPath)
            };

            youtubeDl.StandardOutputEvent += StandardOutputEvent;
            youtubeDl.StandardErrorEvent  += StandardErrorEvent;

            DownloadInfo result;

            try {
                var task = youtubeDl.GetDownloadInfoAsync(url);
                result = await TimeoutAfter(task, 10000);
            } catch (TaskCanceledException) {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Timeout. Error list: {0}", warnings);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout"));
            } catch (TimeoutException) {
                youtubeDl.CancelDownload();
                _log.Error("Timeout");
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Timeout"));
            }

            if (result == null)
            {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Result from parser is empty. Error list: {0}", warnings);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Result from parser is empty"));
            }

            if (!(result is VideoDownloadInfo info))
            {
                var warnings = GetErrorString(youtubeDl.Info);
                _log.Error("Unexpected result from parser. Error list: {0}. Result type is {1}. Title is {2}", warnings, result.GetType().Name, result.Title);
                return(VideoUrlParseResult.CreateError(url, VideoUrlParseResultType.LoadError, "Unexpected result from parser."));
            }

            DateTime?date = null;

            if (DateTime.TryParseExact(info.UploadDate, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsedDate))
            {
                date = parsedDate;
            }

            var bandcampMetadata = new PVExtendedMetadata(new BandcampMetadata {
                Url = info.WebpageUrl
            });

            var meta = VideoTitleParseResult.CreateSuccess(info.Title, info.Uploader, info.UploaderId, info.Thumbnail, (int?)info.Duration, uploadDate: date, extendedMetadata: bandcampMetadata);

            return(VideoUrlParseResult.CreateOk(url, PVService.Bandcamp, info.Id, meta));
        }