Getting video title

Dec 19, 2012 at 4:41 PM

Hi, 

Is it possible to retrieve the video title in WinRT using your toolkit?
If not, you have any suggestions on how I can retrieve it, just by the youtube link?

Thanks
- Billy 

Coordinator
Dec 19, 2012 at 9:50 PM

Try:

 

       public static async Task<string> GetVideoTitleAsync(string youTubeId)
        {
            var response = await Http.GetAsync("http://www.youtube.com/watch?v=" + youTubeId + "&nomobile=1");
            if (response != null)
            {
                var html = response.Response;
                var startIndex = html.IndexOf(" title=\"");
                if (startIndex != -1)
                {
                    startIndex = html.IndexOf(" title=\"", startIndex + 1);
                    if (startIndex != -1)
                    {
                        startIndex += 8;
                        var endIndex = html.IndexOf("\">", startIndex);
                        if (endIndex != -1)
                            return html.Substring(startIndex, endIndex - startIndex);
                    }
                }
            }
            return null;
        }

Dec 19, 2012 at 11:35 PM

Wow, that worked! Thank you. Great toolkit! :)

 

- Billy