From: <nor...@us...> - 2007-06-28 18:50:40
|
Revision: 649 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=649&view=rev Author: northern_sky Date: 2007-06-28 11:49:44 -0700 (Thu, 28 Jun 2007) Log Message: ----------- fixed strange char problem + small rating change Modified Paths: -------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItem.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItemInfo.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/AllGameScraper.cs Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItem.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItem.cs 2007-06-28 17:50:10 UTC (rev 648) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItem.cs 2007-06-28 18:49:44 UTC (rev 649) @@ -695,7 +695,7 @@ while ((!bSuccess) && (iRetries < 5)) { // brute force! Try five times.... sometimes I get - // a PostHTTP false result... don't know why! + // a ScrapeWebPage false result... don't know why! bSuccess = scraper.FindGameinfo(Title); if (!bSuccess) { @@ -722,7 +722,7 @@ while ((!bSuccess) && (iRetries < 5)) { // brute force! Try five times.... sometimes I get - // a PostHTTP false result... don't know why! + // a ScrapeWebPage false result... don't know why! bSuccess = scraper.FindGameinfoDetail(curApp, this, curInfo, saveType); if (!bSuccess) { @@ -746,7 +746,7 @@ FileInfoFavourite.Manufacturer = this.Manufacturer; FileInfoFavourite.Year = this.Year.ToString(); FileInfoFavourite.Overview = this.Overview; - FileInfoFavourite.RatingNorm = this.Rating; + FileInfoFavourite.Rating = this.Rating; FileInfoFavourite.Platform = this.System_; } @@ -760,7 +760,7 @@ this.Manufacturer = FileInfoFavourite.Manufacturer; this.Year = ProgramUtils.StringToInteger(FileInfoFavourite.Year, -1); this.Overview = FileInfoFavourite.Overview; - this.Rating = FileInfoFavourite.RatingNorm; + this.Rating = FileInfoFavourite.Rating; this.System_ = FileInfoFavourite.Platform; this.GameInfoURL = FileInfoFavourite.GameURL; this.Write(); Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItemInfo.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItemInfo.cs 2007-06-28 17:50:10 UTC (rev 648) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/FileItems/FileItemInfo.cs 2007-06-28 18:49:44 UTC (rev 649) @@ -50,8 +50,7 @@ string year; string style; string platform; - string rating; - int ratingNorm; + int rating; string manufacturer; string overview; @@ -74,8 +73,7 @@ subGenre = ""; style = ""; platform = ""; - rating = ""; - ratingNorm = 0; + rating = 0; imageURLs = ""; manufacturer = ""; overview = ""; @@ -193,7 +191,8 @@ platform = value; } } - public string RatingOrig + + public int Rating { get { @@ -204,17 +203,6 @@ rating = value; } } - public int RatingNorm - { - get - { - return ratingNorm; - } - set - { - ratingNorm = value; - } - } public string Manufacturer { get Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/AllGameScraper.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/AllGameScraper.cs 2007-06-28 17:50:10 UTC (rev 648) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Imports/AllGameScraper.cs 2007-06-28 18:49:44 UTC (rev 649) @@ -99,8 +99,10 @@ List<string> tableRowList = new List<string>(); List<string[]> tableCellList = new List<string[]>(); + string rating = string.Empty; + string httpPostLine = allGameUrlEnd + gameTitle; - string htmlText = PostHTTP(allGameUrlStart, httpPostLine); + string htmlText = ScrapeWebPage(allGameUrlStart, httpPostLine); if (htmlText.Length == 0) return false; @@ -148,7 +150,7 @@ // col 5: "Style // col 6: "Genre // col 7: "Platform - // col 8: "Rating" => use imagename to get rating: "st_gt1.gif" to "st_gt9.gif" + // col 8: "Rating" => in allgame we double it... cos it can be 0.5 etc foreach (string[] tableData in tableCellList) @@ -180,23 +182,22 @@ newGame.Platform = match.Groups["platform"].Value; match = Regex.Match(tableData[8], regexpRating, RegexOptions.IgnoreCase); - newGame.RatingOrig = match.Groups["rating"].Value; + rating = match.Groups["rating"].Value; //the rating can be 0-5 , but also in halfstepmodes... so to fit into old model //with 10 rating and no decimals, we just double the value. - if (newGame.RatingOrig != "") + if (rating != "") { - newGame.RatingOrig = (newGame.RatingOrig).Replace('.', ','); + rating = (rating).Replace('.', ','); } else { - newGame.RatingOrig = "0"; + rating = "0"; } - newGame.RatingNorm = (int)(Convert.ToDouble(newGame.RatingOrig) * 2); + newGame.Rating = (int)(Convert.ToDouble(rating) * 2); - newGame.RelevanceNorm = (ProgramUtils.StringToInteger(newGame.RelevanceOrig, -1) + 44); gameList.Add(newGame); @@ -230,12 +231,12 @@ // query string is as in the following example: //http://www.allgame.com/cg/agg.dll?p=agg&sql=1:9472 - // To use PostHTTP, we have to split the parameters from the full url + // To use ScrapeWebPage, we have to split the parameters from the full url string strPostData = curGame.GetGameURLPostParams(); if (strPostData == "") return false; - string page = PostHTTP(allGameUrlStart, strPostData); + string page = ScrapeWebPage(allGameUrlStart, strPostData); if (page.Length == 0) return false; @@ -261,9 +262,7 @@ while (match.Success) { - curGame.AddImageURL(match.Groups["link"].Value); - match = match.NextMatch(); } @@ -300,47 +299,42 @@ } - private string PostHTTP(string strURL, string strData) + private string ScrapeWebPage(string url, string strData) { string page = string.Empty; + byte[] bytes = null; + try { - - - WebRequest req = WebRequest.Create(strURL); + HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; - byte[] bytes = null; // Get the data that is being posted (or sent) to the server bytes = Encoding.ASCII.GetBytes(strData); req.ContentLength = bytes.Length; // 1. Get an output stream from the request object using (Stream outputStream = req.GetRequestStream()) { - // 2. Post the data out to the stream outputStream.Write(bytes, 0, bytes.Length); } - - using (WebResponse result = req.GetResponse()) + using (HttpWebResponse result =(HttpWebResponse) req.GetResponse()) { using (Stream ReceiveStream = result.GetResponseStream()) { - Encoding encode = Encoding.GetEncoding("utf-8"); + Encoding encode = Encoding.GetEncoding(result.CharacterSet); using (StreamReader sr = new StreamReader(ReceiveStream, encode)) { page = sr.ReadToEnd(); } - } } - } catch (Exception ex) { - Log.Info("AllGameScraper:PostHTTP: couldn't connect"); + Log.Info("AllGameScraper:ScrapeWebPage: couldn't connect"); Log.Info(ex.Message.ToString()); } return page; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |