• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

27 Mart 2015 Cuma

C# Youtube Video İndirme Programı | Açık Kaynak Kodu


C# Youtube Video İndirme Programı

Merhaba arkadaşlar uzun süredir araştırdığım bir programdı ve buldum sizlerle paylaşmak istedim codeproject lisanslı bu youtube video indirme programı C# 6.0 ile yazılmış olup tamamen ücretsiz olarak dağıtılmaktadır.... 







Kurulumu kod kısmına gelecek olursak

Video Tanımlama Kısmı


public class YouTubeVideoQuality
    {
        /// <summary>
        /// Gets or Sets the file name         /// </summary>
        public string VideoTitle { get; set; }
        /// <summary>
        /// Gets or Sets the file extention         /// </summary>
        public string Extention { get; set; }
        /// <summary>
        /// Gets or Sets the file url         /// </summary>
        public string DownloadUrl { get; set; }
        /// <summary>
        /// Gets or Sets the youtube video url         /// </summary>
        public string VideoUrl { get; set; }
        /// <summary>
        /// Gets or Sets the youtube video size         /// </summary>
        public long VideoSize { get; set; }
        /// <summary>
        /// Gets or Sets the youtube video dimension         /// </summary>
        public Size Dimension { get; set; }
        /// <summary>
        /// Gets the youtube video length         /// </summary>
        public long Length { get; set; }
        public override string ToString()
        {
            string videoExtention = this.Extention;
            string videoDimension = formatSize(this.Dimension);
            string videoSize = String.Format
            (new FileSizeFormatProvider(), "{0:fs}", this.VideoSize);

            return String.Format
            ("{0} ({1}) - {2}", videoExtention.ToUpper(), videoDimension, videoSize);
        }

        private string formatSize(Size value)
        {
            string s = value.Height >= 720 ? " HD" : "";
            return ((Size)value).Width + " x " + value.Height + s;
        }
    }

Video İndirme Kısmı

public static class YouTubeDownloader
    {
        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 url = Uri.UnescapeDataString(data["url"]) + 
                    "&fallback_host=" + server;
                    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;
        }

        private static long getSize(string videoUrl)
        {
            HttpWebRequest fileInfoRequest = (HttpWebRequest)HttpWebRequest.Create(videoUrl);
            fileInfoRequest.Proxy = Helper.InitialProxy();
            HttpWebResponse fileInfoResponse = (HttpWebResponse)fileInfoRequest.GetResponse();
            long bytesLength = fileInfoResponse.ContentLength;
            fileInfoRequest.Abort();
            return bytesLength;
        }

        /// <summary>
        /// Get the ID of a youtube video from its URL         /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetVideoIDFromUrl(string url)
        {
            url = url.Substring(url.IndexOf("?") + 1);
            char[] delimiters = { '&', '#' };
            string[] props = url.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            string videoid = "";
            foreach (string prop in props)
            {
                if (prop.StartsWith("v="))
                {
                    videoid = prop.Substring(prop.IndexOf("v=") + 2);
                }
            }

            return videoid;
        }
    }

Ve Video Bilgileri Yapı Biçimi Bu Kısım ıse

 public struct ITagInfo
    {
        const string itagExtentions = "5=flv,6=flv,17=3gp,18=mp4,22=mp4,34=flv, 35=flv,36=3gp,37=mp4,38=mp4,43=webm,44=webm,45=webm,46=webm,82=3D.mp4,83=3D.mp4, 84=3D.mp4,85=3D.mp4,100=3D.webm,101=3D.webm,102=3D.webm,120=live.flv";
        const string itagWideDimensions = "5=320x180,6=480x270,17=176x99,18=640x360, 22=1280x720,34=640x360,35=854x480,36=320x180,37=1920x1080,38=2048x1152,43=640x360, 44=854x480,45=1280x720,46=1920x1080,82=480x270,83=640x360,84=1280x720,85=1920x1080, 100=640x360,101=640x360,102=1280x720,120=1280x720";
        const string itagDimensions = "5=320x240,6=480x360,17=176x144,18=640x480, 22=1280x960,34=640x480,35=854x640,36=320x240,37=1920x1440,38=2048x1536,43=640x480, 44=854x640,45=1280x960,46=1920x1440,82=480x360,83=640x480,84=1280x960,85=1920x1440, 100=640x480,101=640x480,102=1280x960,120=1280x960";

        public ITagInfo(string iTag)
            : this()
        {
            iTag = (iTag + "").Trim();
            foreach (var item in itagExtentions.Split(','))
            {
                var nameValue = item.Split('=');
                if (nameValue[0] != iTag) continue;
                VideoExtentions = nameValue[1];
            }
            foreach (var item in itagWideDimensions.Split(','))
            {
                var nameValue = item.Split('=');
                if (nameValue[0] != iTag) continue;
                var widthAndHeight = nameValue[1].Split('x');
                VideoDimensions = new Size(int.Parse(widthAndHeight[0]), 
                int.Parse(widthAndHeight[1]));
            }
        }
        /// <summary>
        /// Gets the Video Extentions that belong to itag         /// </summary>
        public string VideoExtentions { get; private set; }
        /// <summary>
        /// Gets the Video Dimensions that belong to itag         /// </summary>
        public Size VideoDimensions { get; private set; }
    }






3 yorum:

  1. İndirme linki çalışmıyor. Rica etsem kaynak kodu bana mail yolu ile atabilir misiniz?

    mail : tqrl52@gmail.com

    teşekkürler.

    YanıtlaSil

İLetişim

Benimle İrtibata Geçin


Adres

Sultangazi/İstanbul , 34260 Türkiye

Telefon:

+(90) 536 936 5598

Website

http://kasimtok.blogspot.com.tr