private void GetTrailers()
        {
            // try to log in
            uri = new System.Uri("http://movies.yahoo.com/feature/hdtrailers.html");
            SnapStream.Logging.WriteLog("YahooTrailers: Scraping http://movies.yahoo.com/feature/hdtrailers.html");
            // Create a webclient
            webreq = (HttpWebRequest)WebRequest.Create(uri);
            cookies = new CookieContainer();
            webreq.CookieContainer = cookies;
            // Get the response
            try
            {
                webres = (HttpWebResponse)webreq.GetResponse();
                resStream = webres.GetResponseStream();
                response = new StreamReader( resStream ).ReadToEnd();
                response = response.Substring(response.IndexOf("<!-- Menu Links -->"));
                // Create a new List item
                YahooTrailersListItem trailerlistitem;
                while (response.IndexOf("\"a-m-t\">") != -1)
                {
                    // Get the Title
                    int startindex = response.IndexOf("\"a-m-t\">")+19;
                    int endindex = response.IndexOf("</dt>",startindex);
                    string title = response.Substring(startindex,endindex-startindex).Trim();
                    trailerlistitem = new YahooTrailersListItem(title);
                    //SnapStream.Logging.WriteLog("YahooTrailers: " + title);
                    response = response.Substring(startindex+title.Length);
                    // Get the Poster URL
                    startindex = response.IndexOf("img src=\"")+9;
                    endindex = response.IndexOf("\" border",startindex);
                    trailerlistitem._jpegURL = response.Substring(startindex,endindex-startindex).Trim();
                    ////SnapStream.Logging.WriteLog(trailerlistitem._jpegURL);
                    response = response.Substring(startindex+trailerlistitem._jpegURL.Length);
                    // Get the Details
                    startindex = response.IndexOf("<div>")+6;
                    endindex = response.IndexOf("<br />",startindex)-1;
                    trailerlistitem._details = response.Substring(startindex,endindex-startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._details);
                    response = response.Substring(startindex+trailerlistitem._details.Length);
                    // Get the Starring actors
                    startindex = response.IndexOf("Starring: ")+10;
                    endindex = response.IndexOf("<br />",startindex);
                    trailerlistitem._starring = response.Substring(startindex,endindex-startindex).Trim();
                    trailerlistitem.addStarring( trailerlistitem._starring );
                    //SnapStream.Logging.WriteLog(trailerlistitem._starring);
                    response = response.Substring(startindex+trailerlistitem._starring.Length);
                    // Get the Genre
                    startindex = response.IndexOf("<br />")+7;
                    endindex = response.IndexOf("<br />",startindex);
                    trailerlistitem._genre = response.Substring(startindex,endindex-startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._genre);
                    response = response.Substring(startindex+trailerlistitem._genre.Length);
                    // Get the release date
                    startindex = response.IndexOf("<br />")+7;
                    endindex = response.IndexOf("<br />",startindex);
                    trailerlistitem._releasedate = response.Substring(startindex,endindex-startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._releasedate);
                    response = response.Substring(startindex+trailerlistitem._releasedate.Length);
                    // Get the Rating
                    startindex = response.IndexOf("<br />")+7;
                    endindex = response.IndexOf("<br />",startindex);
                    trailerlistitem._rating = response.Substring(startindex,endindex-startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._rating);
                    response = response.Substring(startindex+trailerlistitem._rating.Length);
                    // Find Trailers
                    int foundTrailer2 = response.IndexOf("Trailer 2:",0,response.IndexOf("</dd>"));
                    int foundTrailer = response.IndexOf("Trailer:",0,response.IndexOf("</dd>"));
                    int foundTeaser2 = response.IndexOf("Teaser 2:",0,response.IndexOf("</dd>"));
                    int foundTeaser = response.IndexOf("Teaser:",0,response.IndexOf("</dd>"));
                    string subresponse;
                    // Get Trailer 2
                    if (foundTrailer2 != -1)
                    {
                        //SnapStream.Logging.WriteLog("YahooTrailers: Found Trailer 2");

                        // Declare the trailer array
                        trailerlistitem._trailer2URL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTrailer2);
                        //SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"")+6;
                        endindex = subresponse.IndexOf("\"",startindex);
                        trailerlistitem._trailer2URL[0] = subresponse.Substring(startindex,endindex-startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[0]);
                        //response = response.Substring(startindex+trailerlistitem._trailer2URL[i].Length);
                        trailerlistitem._trailer2URL[1] = trailerlistitem._trailer2URL[0].Replace("480","720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[1]);
                        trailerlistitem._trailer2URL[2] = trailerlistitem._trailer2URL[0].Replace("480","1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[2]);
                    }
                    // Get Trailer
                    if (foundTrailer != -1)
                    {
                        ////SnapStream.Logging.WriteLog("YahooTrailers: Found Trailer");

                        // Declare the trailer array
                        trailerlistitem._trailerURL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTrailer);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"")+6;
                        endindex = subresponse.IndexOf("\"",startindex);
                        trailerlistitem._trailerURL[0] = subresponse.Substring(startindex,endindex-startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[0]);
                        //response = response.Substring(startindex+trailerlistitem._trailerURL[i].Length);
                        trailerlistitem._trailerURL[1] = trailerlistitem._trailerURL[0].Replace("480","720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[1]);
                        trailerlistitem._trailerURL[2] = trailerlistitem._trailerURL[0].Replace("480","1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[2]);
                    }
                    // Get Teaser 2
                    if (foundTeaser2 != -1)
                    {
                        ////SnapStream.Logging.WriteLog("YahooTrailers: Found Teaser 2");

                        // Declare the trailer array
                        trailerlistitem._teaser2URL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTeaser2);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"")+6;
                        endindex = subresponse.IndexOf("\"",startindex);
                        trailerlistitem._teaser2URL[0] = subresponse.Substring(startindex,endindex-startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[0]);
                        //response = response.Substring(startindex+trailerlistitem._teaser2URL[i].Length);
                        trailerlistitem._teaser2URL[1] = trailerlistitem._teaser2URL[0].Replace("480","720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[1]);
                        trailerlistitem._teaser2URL[2] = trailerlistitem._teaser2URL[0].Replace("480","1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[2]);
                    }
                    // Get Teaser
                    if (foundTeaser != -1)
                    {
                        //SnapStream.Logging.WriteLog("YahooTrailers: Found Teaser");

                        // Declare the trailer array
                        trailerlistitem._teaserURL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTeaser);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"")+6;
                        endindex = subresponse.IndexOf("\"",startindex);
                        trailerlistitem._teaserURL[0] = subresponse.Substring(startindex,endindex-startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[0]);
                        //response = response.Substring(startindex+trailerlistitem._teaserURL[i].Length);
                        trailerlistitem._teaserURL[1] = trailerlistitem._teaserURL[0].Replace("480","720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[1]);
                        trailerlistitem._teaserURL[2] = trailerlistitem._teaserURL[0].Replace("480","1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[2]);
                    }

                    // Get Posters
                    string jpgpath = homedir + "\\Posters\\" + title.Replace(":","").Replace("?","") + ".jpg";
                    try
                    {
                        System.Net.WebClient webClient = new System.Net.WebClient();
                        webClient.DownloadFile( trailerlistitem._jpegURL, jpgpath);
                        trailerlistitem.addPoster(title);
                    }
                    catch (System.Net.WebException e)
                    {
                        SnapStream.Logging.WriteLog(e.Message);
                    }

                    // Add to trailer list
                    trailerlistitem.Height = 75;
                    _trailerlist.AddItem(trailerlistitem);
                }
                SnapStream.Logging.WriteLog("YahooTrailers: Done fetching trailer information");
            }
            catch (System.Net.WebException e)
            {
                SnapStream.Logging.WriteLog("YahooTrailers: " + e.ToString());
                _header.Text = "Yahoo Trailers: Connection Error";
            }
        }
示例#2
0
        private void GetTrailers()
        {
            // try to log in
            uri = new System.Uri("http://movies.yahoo.com/feature/hdtrailers.html");
            SnapStream.Logging.WriteLog("YahooTrailers: Scraping http://movies.yahoo.com/feature/hdtrailers.html");
            // Create a webclient
            webreq  = (HttpWebRequest)WebRequest.Create(uri);
            cookies = new CookieContainer();
            webreq.CookieContainer = cookies;
            // Get the response
            try
            {
                webres    = (HttpWebResponse)webreq.GetResponse();
                resStream = webres.GetResponseStream();
                response  = new StreamReader(resStream).ReadToEnd();
                response  = response.Substring(response.IndexOf("<!-- Menu Links -->"));
                // Create a new List item
                YahooTrailersListItem trailerlistitem;
                while (response.IndexOf("\"a-m-t\">") != -1)
                {
                    // Get the Title
                    int    startindex = response.IndexOf("\"a-m-t\">") + 19;
                    int    endindex   = response.IndexOf("</dt>", startindex);
                    string title      = response.Substring(startindex, endindex - startindex).Trim();
                    trailerlistitem = new YahooTrailersListItem(title);
                    //SnapStream.Logging.WriteLog("YahooTrailers: " + title);
                    response = response.Substring(startindex + title.Length);
                    // Get the Poster URL
                    startindex = response.IndexOf("img src=\"") + 9;
                    endindex   = response.IndexOf("\" border", startindex);
                    trailerlistitem._jpegURL = response.Substring(startindex, endindex - startindex).Trim();
                    ////SnapStream.Logging.WriteLog(trailerlistitem._jpegURL);
                    response = response.Substring(startindex + trailerlistitem._jpegURL.Length);
                    // Get the Details
                    startindex = response.IndexOf("<div>") + 6;
                    endindex   = response.IndexOf("<br />", startindex) - 1;
                    trailerlistitem._details = response.Substring(startindex, endindex - startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._details);
                    response = response.Substring(startindex + trailerlistitem._details.Length);
                    // Get the Starring actors
                    startindex = response.IndexOf("Starring: ") + 10;
                    endindex   = response.IndexOf("<br />", startindex);
                    trailerlistitem._starring = response.Substring(startindex, endindex - startindex).Trim();
                    trailerlistitem.addStarring(trailerlistitem._starring);
                    //SnapStream.Logging.WriteLog(trailerlistitem._starring);
                    response = response.Substring(startindex + trailerlistitem._starring.Length);
                    // Get the Genre
                    startindex             = response.IndexOf("<br />") + 7;
                    endindex               = response.IndexOf("<br />", startindex);
                    trailerlistitem._genre = response.Substring(startindex, endindex - startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._genre);
                    response = response.Substring(startindex + trailerlistitem._genre.Length);
                    // Get the release date
                    startindex = response.IndexOf("<br />") + 7;
                    endindex   = response.IndexOf("<br />", startindex);
                    trailerlistitem._releasedate = response.Substring(startindex, endindex - startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._releasedate);
                    response = response.Substring(startindex + trailerlistitem._releasedate.Length);
                    // Get the Rating
                    startindex = response.IndexOf("<br />") + 7;
                    endindex   = response.IndexOf("<br />", startindex);
                    trailerlistitem._rating = response.Substring(startindex, endindex - startindex).Trim();
                    //SnapStream.Logging.WriteLog(trailerlistitem._rating);
                    response = response.Substring(startindex + trailerlistitem._rating.Length);
                    // Find Trailers
                    int    foundTrailer2 = response.IndexOf("Trailer 2:", 0, response.IndexOf("</dd>"));
                    int    foundTrailer  = response.IndexOf("Trailer:", 0, response.IndexOf("</dd>"));
                    int    foundTeaser2  = response.IndexOf("Teaser 2:", 0, response.IndexOf("</dd>"));
                    int    foundTeaser   = response.IndexOf("Teaser:", 0, response.IndexOf("</dd>"));
                    string subresponse;
                    // Get Trailer 2
                    if (foundTrailer2 != -1)
                    {
                        //SnapStream.Logging.WriteLog("YahooTrailers: Found Trailer 2");

                        // Declare the trailer array
                        trailerlistitem._trailer2URL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTrailer2);
                        //SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"") + 6;
                        endindex   = subresponse.IndexOf("\"", startindex);
                        trailerlistitem._trailer2URL[0] = subresponse.Substring(startindex, endindex - startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[0]);
                        //response = response.Substring(startindex+trailerlistitem._trailer2URL[i].Length);
                        trailerlistitem._trailer2URL[1] = trailerlistitem._trailer2URL[0].Replace("480", "720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[1]);
                        trailerlistitem._trailer2URL[2] = trailerlistitem._trailer2URL[0].Replace("480", "1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailer2URL[2]);
                    }
                    // Get Trailer
                    if (foundTrailer != -1)
                    {
                        ////SnapStream.Logging.WriteLog("YahooTrailers: Found Trailer");

                        // Declare the trailer array
                        trailerlistitem._trailerURL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTrailer);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"") + 6;
                        endindex   = subresponse.IndexOf("\"", startindex);
                        trailerlistitem._trailerURL[0] = subresponse.Substring(startindex, endindex - startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[0]);
                        //response = response.Substring(startindex+trailerlistitem._trailerURL[i].Length);
                        trailerlistitem._trailerURL[1] = trailerlistitem._trailerURL[0].Replace("480", "720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[1]);
                        trailerlistitem._trailerURL[2] = trailerlistitem._trailerURL[0].Replace("480", "1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._trailerURL[2]);
                    }
                    // Get Teaser 2
                    if (foundTeaser2 != -1)
                    {
                        ////SnapStream.Logging.WriteLog("YahooTrailers: Found Teaser 2");

                        // Declare the trailer array
                        trailerlistitem._teaser2URL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTeaser2);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"") + 6;
                        endindex   = subresponse.IndexOf("\"", startindex);
                        trailerlistitem._teaser2URL[0] = subresponse.Substring(startindex, endindex - startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[0]);
                        //response = response.Substring(startindex+trailerlistitem._teaser2URL[i].Length);
                        trailerlistitem._teaser2URL[1] = trailerlistitem._teaser2URL[0].Replace("480", "720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[1]);
                        trailerlistitem._teaser2URL[2] = trailerlistitem._teaser2URL[0].Replace("480", "1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaser2URL[2]);
                    }
                    // Get Teaser
                    if (foundTeaser != -1)
                    {
                        //SnapStream.Logging.WriteLog("YahooTrailers: Found Teaser");

                        // Declare the trailer array
                        trailerlistitem._teaserURL = new string[3];

                        // Get to the HTML
                        subresponse = response.Substring(foundTeaser);
                        ////SnapStream.Logging.WriteLog(subresponse);

                        // Get all three resolutions
                        startindex = subresponse.IndexOf("href=\"") + 6;
                        endindex   = subresponse.IndexOf("\"", startindex);
                        trailerlistitem._teaserURL[0] = subresponse.Substring(startindex, endindex - startindex).Trim();
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[0]);
                        //response = response.Substring(startindex+trailerlistitem._teaserURL[i].Length);
                        trailerlistitem._teaserURL[1] = trailerlistitem._teaserURL[0].Replace("480", "720");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[1]);
                        trailerlistitem._teaserURL[2] = trailerlistitem._teaserURL[0].Replace("480", "1080");
                        //SnapStream.Logging.WriteLog(trailerlistitem._teaserURL[2]);
                    }

                    // Get Posters
                    string jpgpath = homedir + "\\Posters\\" + title.Replace(":", "").Replace("?", "") + ".jpg";
                    try
                    {
                        System.Net.WebClient webClient = new System.Net.WebClient();
                        webClient.DownloadFile(trailerlistitem._jpegURL, jpgpath);
                        trailerlistitem.addPoster(title);
                    }
                    catch (System.Net.WebException e)
                    {
                        SnapStream.Logging.WriteLog(e.Message);
                    }

                    // Add to trailer list
                    trailerlistitem.Height = 75;
                    _trailerlist.AddItem(trailerlistitem);
                }
                SnapStream.Logging.WriteLog("YahooTrailers: Done fetching trailer information");
            }
            catch (System.Net.WebException e)
            {
                SnapStream.Logging.WriteLog("YahooTrailers: " + e.ToString());
                _header.Text = "Yahoo Trailers: Connection Error";
            }
        }