public static async Task <string> GetEmbededVideo(string url) { try { if (url.Contains("youtube") || url.Contains("youtu")) { VideoInfos = await DownloadUrlResolver.GetDownloadUrlsAsync(url); var videoInfos = VideoInfos.ToList(); if (videoInfos.Count() > 1) { YoutubeExtractor.VideoInfo video = videoInfos.FirstOrDefault(info => info.VideoType == VideoType.Mp4 && info.Resolution == 720); if (video == null) { video = videoInfos.FirstOrDefault( info => info.VideoType == VideoType.Mp4 && info.Resolution == 480); } if (video == null) { video = videoInfos.FirstOrDefault( info => info.VideoType == VideoType.Mp4 && info.Resolution == 360); } if (video == null) { video = videoInfos.FirstOrDefault( info => info.VideoType == VideoType.Mp4 && info.Resolution == 240); } if (video == null) { video = videoInfos.FirstOrDefault( info => info.VideoType == VideoType.Mp4 && info.Resolution == 144); } if (video != null) { if (video.RequiresDecryption) { DownloadUrlResolver.DecryptDownloadUrl(video); } VideoSelected = video; VideoDownloadstring = video.DownloadUrl; return(VideoDownloadstring); } else { return(null); } } else { var result = await Get_Youtube_Video(url); if (result != null) { VideoDownloadstring = result[0].Videourl; return(VideoDownloadstring); } else { return(null); } } } else { return(null); } } catch (IOException exception) { Console.WriteLine(exception); return("Invalid"); } }
/// <summary> /// Initializes a new instance of the <see cref="VideoDownloader"/> class. /// </summary> /// <param name="video">The video to download.</param> /// <param name="savePath">The path to save the video.</param> /// <param name="bytesToDownload">An optional value to limit the number of bytes to download.</param> /// <exception cref="ArgumentNullException"><paramref name="video"/> or <paramref name="savePath"/> is <c>null</c>.</exception> public VideoDownloader(VideoInfo video, string savePath, String folder, int?bytesToDownload = null) : base(video, savePath, folder, bytesToDownload) { }
internal VideoInfo(VideoInfo info) : this(info.FormatCode, info.VideoType, info.Resolution, info.Is3D, info.AudioType, info.AudioBitrate, info.AdaptiveType) { }
/// <summary> /// Initializes a new instance of the <see cref="AudioDownloader"/> class. /// </summary> /// <param name="video">The video to convert.</param> /// <param name="savePath">The path to save the audio.</param> /// /// <param name="bytesToDownload">An optional value to limit the number of bytes to download.</param> /// <exception cref="ArgumentNullException"><paramref name="video"/> or <paramref name="savePath"/> is <c>null</c>.</exception> public AudioDownloader(VideoInfo video, string savePath, int?bytesToDownload = null) : base(video, savePath, bytesToDownload) { }
internal VideoInfo(VideoInfo info) : this(info.FormatCode, info.VideoType, info.Resolution, info.IsHDR, info.Is3D, info.AudioType, info.AudioBitrate, info.AdaptiveType) { }
/// <summary> /// Initializes a new instance of the <see cref="AudioDownloader"/> class. /// </summary> /// <param name="video">The video to convert.</param> /// <param name="savePath">The path to save the audio.</param> public AudioDownloader(VideoInfo video, string savePath) : base(video, savePath) { }
private static IEnumerable <VideoInfo> GetVideoInfos(YoutubeModel model) { var streamingFormats = GetStreamMap(model); streamingFormats.AddRange(GetAdaptiveStreamMap(model)); foreach (var fmt in streamingFormats) { if (!fmt.Itag.HasValue) { continue; } var itag = (int)fmt.Itag.Value; VideoInfo videoInfo = VideoInfo.Defaults.SingleOrDefault(info => info.FormatCode == itag); videoInfo = videoInfo ?? new VideoInfo(itag); if (!string.IsNullOrEmpty(fmt.Url)) { videoInfo.DownloadUrl = HttpHelper.UrlDecode(HttpHelper.UrlDecode(fmt.Url)); } else if (!string.IsNullOrEmpty(fmt.Cipher) || !string.IsNullOrEmpty(fmt.SignatureCipher)) { IDictionary <string, string> cipher = null; if (!string.IsNullOrEmpty(fmt.Cipher)) { cipher = HttpHelper.ParseQueryString(fmt.Cipher); } if (!string.IsNullOrEmpty(fmt.SignatureCipher)) { cipher = HttpHelper.ParseQueryString(fmt.SignatureCipher); } if (!cipher.ContainsKey("url")) { continue; } if (!cipher.ContainsKey("s")) { continue; } var url = cipher["url"]; var sig = cipher["s"]; url = HttpHelper.UrlDecode(url); url = HttpHelper.UrlDecode(url); sig = HttpHelper.UrlDecode(sig); sig = HttpHelper.UrlDecode(sig); url = url.Replace("&s=", "&sig="); videoInfo.DownloadUrl = HttpHelper.ReplaceQueryStringParameter(url, SignatureQuery, sig); videoInfo.RequiresDecryption = true; } else { continue; } if (!HttpHelper.ParseQueryString(videoInfo.DownloadUrl).ContainsKey(RateBypassFlag)) { videoInfo.DownloadUrl = string.Concat(videoInfo.DownloadUrl, string.Format("&{0}={1}", "ratebypass", "yes")); } if (fmt.AudioSampleRate.HasValue) { videoInfo.AudioBitrate = (int)fmt.AudioSampleRate.Value; } if (fmt.ContentLength.HasValue) { videoInfo.FileSize = (int)fmt.ContentLength.Value; } if (!string.IsNullOrEmpty(fmt.QualityLabel)) { videoInfo.FormatNote = fmt.QualityLabel; } else { videoInfo.FormatNote = fmt.Quality; } if (fmt.Fps.HasValue) { videoInfo.FPS = (int)fmt.Fps.Value; } if (fmt.Height.HasValue) { videoInfo.Height = (int)fmt.Height.Value; } if (fmt.Width.HasValue) { videoInfo.Width = (int)fmt.Width.Value; } // bitrate for itag 43 is always 2147483647 if (itag != 43) { if (fmt.AverageBitrate.HasValue) { videoInfo.AverageBitrate = fmt.AverageBitrate.Value / 1000f; } else if (fmt.Bitrate.HasValue) { videoInfo.AverageBitrate = fmt.Bitrate.Value / 1000f; } } if (fmt.Height.HasValue) { videoInfo.Height = (int)fmt.Height.Value; } if (fmt.Width.HasValue) { videoInfo.Width = (int)fmt.Width.Value; } yield return(videoInfo); } }
/// <summary> /// Initializes a new instance of the <see cref="Downloader"/> class. /// </summary> /// <param name="video">The video to download/convert.</param> /// <param name="savePath">The path to save the video/audio.</param> /// /// <param name="bytesToDownload">An optional value to limit the number of bytes to download.</param> /// <exception cref="ArgumentNullException"><paramref name="video"/> or <paramref name="savePath"/> is <c>null</c>.</exception> protected Downloader(VideoInfo video, string savePath, int?bytesToDownload = null) { Init(video, savePath, bytesToDownload); }
public static void DecryptDownloadUrl(VideoInfo info) { // Nothing to do here, URL is decrypted automatically // upon calling YouTubeVideo.Uri. }
/// <summary> /// Initializes a new instance of the <see cref="Downloader"/> class. /// </summary> /// <param name="video">The video to download/convert.</param> /// <param name="savePath">The path to save the video/audio.</param> protected Downloader(VideoInfo video, string savePath) { this.Video = video; this.SavePath = savePath; }