public async Task<Result<YoutubeDownloadResult, string>> DownloadYoutubeVideo(YTEVideoFormat video) { if(video == null) throw new Exception("null video passed to DownloadYoutubeVideo"); // We combine the VideoID with a DateTime hashcode just incase multiple copies // of the same video are being downloaded. That way there won't be any file clashes. string filepath = $"{Guid.NewGuid().ToString()}.temp"; try { if(video.YTEVideoInfo.RequiresDecryption) await Task.Run(() => DownloadUrlResolver.DecryptDownloadUrl(video.YTEVideoInfo)); var downloader = new VideoDownloader(video.YTEVideoInfo, filepath); await Task.Run(() => downloader.Execute()); return new YoutubeDownloadResult(filepath); } catch(WebException e) { return (e.Response as HttpWebResponse).StatusCode.ToString(); } catch(Exception) { return string.Empty; } }
public async Task <Result <YoutubeDownloadResult, string> > DownloadYoutubeVideo(YTEVideoFormat video) { if (video == null) { throw new Exception("null video passed to DownloadYoutubeVideo"); } // We combine the VideoID with a DateTime hashcode just incase multiple copies // of the same video are being downloaded. That way there won't be any file clashes. string filepath = $"{Guid.NewGuid().ToString()}.temp"; try { if (video.YTEVideoInfo.RequiresDecryption) { await Task.Run(() => DownloadUrlResolver.DecryptDownloadUrl(video.YTEVideoInfo)); } var downloader = new VideoDownloader(video.YTEVideoInfo, filepath); await Task.Run(() => downloader.Execute()); return(new YoutubeDownloadResult(filepath)); } catch (WebException e) { return((e.Response as HttpWebResponse).StatusCode.ToString()); } catch (Exception) { return(string.Empty); } }