Ejemplo n.º 1
0
        public static List <YouTubeVideoQuality> GetYouTubeVideoUrls(string VideoUrl)
        {
            var list = new List <YouTubeVideoQuality>();

            var id            = YouTubeDownloader.GetVideoIDFromUrl(VideoUrl);
            var infoUrl       = string.Format("http://www.youtube.com/get_video_info?&video_id={0}&el=detailpage&ps=default&eurl=&gl=US&hl=en", id);
            var infoText      = new WebClient().DownloadString(infoUrl);
            var infoValues    = HttpUtility.ParseQueryString(infoText);
            var title         = infoValues["title"];
            var videoDuration = infoValues["length_seconds"];
            var videos        = infoValues["url_encoded_fmt_stream_map"].Split(',');

            foreach (var item in videos)
            {
                try
                {
                    var data      = HttpUtility.ParseQueryString(item);
                    var server    = Uri.UnescapeDataString(data["fallback_host"]);
                    var signature = data["sig"] ?? data["signature"];
                    var url       = Uri.UnescapeDataString(data["url"]) + "&fallback_host=" + server;
                    if (!string.IsNullOrEmpty(signature))
                    {
                        url += "&signature=" + signature;
                    }
                    var size      = getSize(url);
                    var videoItem = new YouTubeVideoQuality();
                    videoItem.DownloadUrl = url;
                    videoItem.VideoSize   = size;
                    videoItem.VideoTitle  = title;
                    var tagInfo = new ITagInfo(Uri.UnescapeDataString(data["itag"]));
                    videoItem.Dimension = tagInfo.VideoDimensions;
                    videoItem.Extention = tagInfo.VideoExtentions;
                    videoItem.Length    = long.Parse(videoDuration);
                    list.Add(videoItem);
                }
                catch { }
            }

            return(list);
        }
Ejemplo n.º 2
0
 //
 void worker_DoWork(object o, DoWorkEventArgs e)
 {
     e.Result = YouTubeDownloader.GetYouTubeVideoUrls(e.Argument.ToString());
 }