Ejemplo n.º 1
0
        public IUrlInfo GetInfo(string url)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            url = url.Trim();

            if (!new Regex(YoutuberRegexp).Match(url).Success)
            {
                throw new Exception("Link is not valid for youtube video");
            }

            url = UrlFormatter.RemoveParametersFromUrl(url);

            IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url);
            VideoInfo videoInfo = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);

            Headers headers       = HttpRequester.GetHeaders(videoInfo.DownloadUrl);
            var     artistAndSong = GetArtistAndSongName(videoInfo.Title);

            return(new UrlInfo()
            {
                Artist = artistAndSong.Artist,
                Song = artistAndSong.Song,
                ContentLength = headers.ContentLenght,
                VideoId = UrlFormatter.GetYoutubeVideoIdentifier(url),
            });
        }