Exemple #1
0
        public static List <YouTubeVideoQuality> GetYouTubeVideoUrls(params string[] VideoUrls)
        {
            List <YouTubeVideoQuality> urls = new List <YouTubeVideoQuality>();

            foreach (var VideoUrl in VideoUrls)
            {
                string html  = Helper.DownloadWebPage(VideoUrl);
                string title = GetTitle(html);
                foreach (var videoLink in ExtractUrls(html))
                {
                    YouTubeVideoQuality q = new YouTubeVideoQuality();
                    q.VideoUrl    = VideoUrl;
                    q.VideoTitle  = title;
                    q.DownloadUrl = videoLink + "&title=" + title;
                    if (!getSize(q))
                    {
                        continue;
                    }
                    q.Length = long.Parse(Regex.Match(html, "\"length_seconds\":(.+?),", RegexOptions.Singleline).Groups[1].ToString());
                    bool IsWide = IsWideScreen(html);
                    if (getQuality(q, IsWide))
                    {
                        urls.Add(q);
                    }
                }
            }
            return(urls);
        }
 public static List<YouTubeVideoQuality> GetYouTubeVideoUrls(params string[] VideoUrls)
 {
     List<YouTubeVideoQuality> urls = new List<YouTubeVideoQuality>();
     foreach ( var VideoUrl in VideoUrls )
     {
         string html = Helper.DownloadWebPage(VideoUrl);
         string title = GetTitle(html);
         foreach ( var videoLink in ExtractUrls(html) )
         {
             YouTubeVideoQuality q = new YouTubeVideoQuality();
             q.VideoUrl = VideoUrl;
             q.VideoTitle = title;
             q.DownloadUrl = videoLink + "&title=" + title;
             if ( !getSize(q) ) continue;
             q.Length = long.Parse(Regex.Match(html, "\"length_seconds\":(.+?),", RegexOptions.Singleline).Groups[1].ToString());
             bool IsWide = IsWideScreen(html);
             if ( getQuality(q, IsWide) )
                 urls.Add(q);
         }
     }
     return urls;
 }
Exemple #3
0
 private static bool getSize(YouTubeVideoQuality q)
 {
     try
     {
         HttpWebRequest  fileInfoRequest  = (HttpWebRequest)HttpWebRequest.Create(q.DownloadUrl);
         HttpWebResponse fileInfoResponse = (HttpWebResponse)fileInfoRequest.GetResponse();
         long            bytesLength      = fileInfoResponse.ContentLength;
         fileInfoRequest.Abort();
         if (bytesLength != -1)
         {
             q.SetSize(bytesLength);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #4
0
        private static bool getQuality(YouTubeVideoQuality q, Boolean _Wide)
        {
            int    iTagValue;
            string itag = Regex.Match(q.DownloadUrl, @"itag=([1-9]?[0-9]?[0-9])", RegexOptions.Singleline).Groups[1].ToString();

            if (itag != "")
            {
                if (int.TryParse(itag, out iTagValue) == false)
                {
                    iTagValue = 0;
                }

                switch (iTagValue)
                {
                case 5: q.SetQuality("flv", new Size(320, (_Wide ? 180 : 240))); break;

                case 6: q.SetQuality("flv", new Size(480, (_Wide ? 270 : 360))); break;

                case 17: q.SetQuality("3gp", new Size(176, (_Wide ? 99 : 144))); break;

                case 18: q.SetQuality("mp4", new Size(640, (_Wide ? 360 : 480))); break;

                case 22: q.SetQuality("mp4", new Size(1280, (_Wide ? 720 : 960))); break;

                case 34: q.SetQuality("flv", new Size(640, (_Wide ? 360 : 480))); break;

                case 35: q.SetQuality("flv", new Size(854, (_Wide ? 480 : 640))); break;

                case 36: q.SetQuality("3gp", new Size(320, (_Wide ? 180 : 240))); break;

                case 37: q.SetQuality("mp4", new Size(1920, (_Wide ? 1080 : 1440))); break;

                case 38: q.SetQuality("mp4", new Size(2048, (_Wide ? 1152 : 1536))); break;

                case 43: q.SetQuality("webm", new Size(640, (_Wide ? 360 : 480))); break;

                case 44: q.SetQuality("webm", new Size(854, (_Wide ? 480 : 640))); break;

                case 45: q.SetQuality("webm", new Size(1280, (_Wide ? 720 : 960))); break;

                case 46: q.SetQuality("webm", new Size(1920, (_Wide ? 1080 : 1440))); break;

                case 82: q.SetQuality("3D.mp4", new Size(480, (_Wide ? 270 : 360))); break;     // 3D

                case 83: q.SetQuality("3D.mp4", new Size(640, (_Wide ? 360 : 480))); break;     // 3D

                case 84: q.SetQuality("3D.mp4", new Size(1280, (_Wide ? 720 : 960))); break;    // 3D

                case 85: q.SetQuality("3D.mp4", new Size(1920, (_Wide ? 1080 : 1440))); break;  // 3D

                case 100: q.SetQuality("3D.webm", new Size(640, (_Wide ? 360 : 480))); break;   // 3D

                case 101: q.SetQuality("3D.webm", new Size(640, (_Wide ? 360 : 480))); break;   // 3D

                case 102: q.SetQuality("3D.webm", new Size(1280, (_Wide ? 720 : 960))); break;  // 3D

                case 120: q.SetQuality("live.flv", new Size(1280, (_Wide ? 720 : 960))); break; // Live-streaming - should be ignored?

                default: q.SetQuality("itag-" + itag, new Size(0, 0)); break;                   // unknown or parse error
                }
                return(true);
            }
            return(false);
        }
Exemple #5
0
        private static double GetVideoDistance(YouTubeVideoQuality video)
        {
            double f1 = 0.0;
            if ( videoWidth > 0 )
                f1 = Math.Pow(Math.Abs(video.Dimension.Width - videoWidth), 2);

            double f2 = 0.0;
            if ( videoSize > 0 )
                f2 = Math.Pow(Math.Abs(video.VideoSize - videoSize), 2);

            return Math.Sqrt(f1 + f2);
        }
        private static bool getQuality(YouTubeVideoQuality q, Boolean _Wide)
        {
            int iTagValue;
            string itag = Regex.Match(q.DownloadUrl, @"itag=([1-9]?[0-9]?[0-9])", RegexOptions.Singleline).Groups[1].ToString();
            if ( itag != "" )
            {
                if ( int.TryParse(itag, out iTagValue) == false )
                    iTagValue = 0;

                switch ( iTagValue )
                {
                    case 5: q.SetQuality("flv", new Size(320, (_Wide ? 180 : 240))); break;
                    case 6: q.SetQuality("flv", new Size(480, (_Wide ? 270 : 360))); break;
                    case 17: q.SetQuality("3gp", new Size(176, (_Wide ? 99 : 144))); break;
                    case 18: q.SetQuality("mp4", new Size(640, (_Wide ? 360 : 480))); break;
                    case 22: q.SetQuality("mp4", new Size(1280, (_Wide ? 720 : 960))); break;
                    case 34: q.SetQuality("flv", new Size(640, (_Wide ? 360 : 480))); break;
                    case 35: q.SetQuality("flv", new Size(854, (_Wide ? 480 : 640))); break;
                    case 36: q.SetQuality("3gp", new Size(320, (_Wide ? 180 : 240))); break;
                    case 37: q.SetQuality("mp4", new Size(1920, (_Wide ? 1080 : 1440))); break;
                    case 38: q.SetQuality("mp4", new Size(2048, (_Wide ? 1152 : 1536))); break;
                    case 43: q.SetQuality("webm", new Size(640, (_Wide ? 360 : 480))); break;
                    case 44: q.SetQuality("webm", new Size(854, (_Wide ? 480 : 640))); break;
                    case 45: q.SetQuality("webm", new Size(1280, (_Wide ? 720 : 960))); break;
                    case 46: q.SetQuality("webm", new Size(1920, (_Wide ? 1080 : 1440))); break;
                    case 82: q.SetQuality("3D.mp4", new Size(480, (_Wide ? 270 : 360))); break;        // 3D
                    case 83: q.SetQuality("3D.mp4", new Size(640, (_Wide ? 360 : 480))); break;        // 3D
                    case 84: q.SetQuality("3D.mp4", new Size(1280, (_Wide ? 720 : 960))); break;       // 3D
                    case 85: q.SetQuality("3D.mp4", new Size(1920, (_Wide ? 1080 : 1440))); break;     // 3D
                    case 100: q.SetQuality("3D.webm", new Size(640, (_Wide ? 360 : 480))); break;      // 3D
                    case 101: q.SetQuality("3D.webm", new Size(640, (_Wide ? 360 : 480))); break;      // 3D
                    case 102: q.SetQuality("3D.webm", new Size(1280, (_Wide ? 720 : 960))); break;     // 3D
                    case 120: q.SetQuality("live.flv", new Size(1280, (_Wide ? 720 : 960))); break;    // Live-streaming - should be ignored?
                    default: q.SetQuality("itag-" + itag, new Size(0, 0)); break;       // unknown or parse error
                }
                return true;
            } return false;
        }
 private static bool getSize(YouTubeVideoQuality q)
 {
     try
     {
         HttpWebRequest fileInfoRequest = (HttpWebRequest) HttpWebRequest.Create(q.DownloadUrl);
         HttpWebResponse fileInfoResponse = (HttpWebResponse) fileInfoRequest.GetResponse();
         long bytesLength = fileInfoResponse.ContentLength;
         fileInfoRequest.Abort();
         if ( bytesLength != -1 )
         {
             q.SetSize(bytesLength);
             return true;
         }
         else return false;
     }
     catch ( Exception )
     {
         return false;
     }
 }