예제 #1
0
파일: Form1.cs 프로젝트: M4deM4n/SpotDown
        void YouTubeDownload(int num, int session)
        {
            PassArguments result = songArray[session][num];
//            while (true)
//            {
                try
                {
                    List<YouTubeVideoQuality> urls = result.YouTubeVideoQuality;
                    YouTubeVideoQuality highestQual = new YouTubeVideoQuality();

                    foreach (var url in urls)
                    {
                        if (url.Extention == "mp4")
                        {
                            highestQual = urls[0];
                            break;
                        }
                    }
                    string Url = "";
                    string saveTo = "";
                    try
                    {
                        YouTubeVideoQuality tempItem = highestQual;
                        Url = tempItem.DownloadUrl;
                        saveTo = escapeFilename(result.PassedFileName) + ".mp4";
                    }
                    catch (Exception ex)
                    {
                        Log("[Error x11] " + ex.InnerException, true);
                    }
                    if (result.PassedFileName == null || result.PassedNum == null)
                    {
                        MessageBox.Show("Somthing null");
                    }
                    EditList("Downloading...", result.PassedFileName, result.PassedNum, 2);
                    var folder = Path.GetDirectoryName(_tempDir + saveTo);
                    string file = Path.GetFileName(_tempDir + saveTo);

                    var client = new WebClient();
                    Uri address = new Uri(Url);
                    client.DownloadFile(address, folder + "\\" + file);
                    EditList("Converting...", result.PassedFileName, result.PassedNum, 3);
                    StartConvert(result.PassedFileName);
                    MusicTags(num, session);
                    _youtubeDownloadedNum++;
                    Done(result.PassedFileName, num);
                    _running--;
                    if (_running < 0)
                    {
                        _running = 0;
                    }
//                    break;
                }
                catch (Exception ex)
                {
                    Log("[Error x12] " + "|" + ex.Message + "| " + ex.InnerException + " | " + result.PassedFileName, true);
                }
//            }
        }
        public List<YouTubeVideoQuality> GetYouTubeVideoUrls(string VideoUrl)
        {
            var list = new List<YouTubeVideoQuality>();

            var id = 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);
            if (infoValues["errorcode"] == "150")
            {
                //Age restriction error, cant download
                return null;
            }
            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"] ?? data["s"];   // Hans: Added "s" for encrypted signatures
                    var url = Uri.UnescapeDataString(data["url"]) + "&fallback_host=" + server;

                    if (!string.IsNullOrEmpty(signature) && data["s"] == null)
                    {
                        url += "&signature=" + signature;
                    }

                    // If the download-URL contains encrypted signature
                    if (data["s"] != null)
                    {
                        string html = helper.DownloadWebPage(VideoUrl);
                        string Player_Version = Regex.Match(html, @"""\\/\\/s.ytimg.com\\/yts\\/jsbin\\/html5player-(.+?)\.js""").Groups[1].ToString();

                        // Decrypt the signature
                        string decryptedSignature = GetDecipheredSignature(Player_Version, signature.ToString());

                        // The new download-url with decrypted signature
                        url += "&signature=" + decryptedSignature;
                    }

                    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;
        }
예제 #3
0
        public List <YouTubeVideoQuality> GetYouTubeVideoUrls(string VideoUrl)
        {
            var list = new List <YouTubeVideoQuality>();

            var id         = 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);

            if (infoValues["errorcode"] == "150")
            {
                //Age restriction error, cant download
                return(null);
            }
            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"] ?? data["s"];   // Hans: Added "s" for encrypted signatures
                    var url       = Uri.UnescapeDataString(data["url"]) + "&fallback_host=" + server;

                    if (!string.IsNullOrEmpty(signature) && data["s"] == null)
                    {
                        url += "&signature=" + signature;
                    }

                    // If the download-URL contains encrypted signature
                    if (data["s"] != null)
                    {
                        string html           = helper.DownloadWebPage(VideoUrl);
                        string Player_Version = Regex.Match(html, @"""\\/\\/s.ytimg.com\\/yts\\/jsbin\\/html5player-(.+?)\.js""").Groups[1].ToString();

                        // Decrypt the signature
                        string decryptedSignature = GetDecipheredSignature(Player_Version, signature.ToString());

                        // The new download-url with decrypted signature
                        url += "&signature=" + decryptedSignature;
                    }

                    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);
        }